File: formats_helper_tests.rb

package info (click to toggle)
ruby-fog-aws 3.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,140 kB
  • sloc: ruby: 73,328; javascript: 14; makefile: 9; sh: 4
file content (107 lines) | stat: -rw-r--r-- 3,589 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Shindo.tests('test_helper', 'meta') do

  tests('comparing welcome data against schema') do
    data = { welcome: 'Hello' }
    data_matches_schema(welcome: String) { data }
  end

  tests('#data_matches_schema') do
    tests('when value matches schema expectation') do
      data_matches_schema('key' => String) { { 'key' => 'Value' } }
    end

    tests('when values within an array all match schema expectation') do
      data_matches_schema('key' => [Integer]) { { 'key' => [1, 2] } }
    end

    tests('when nested values match schema expectation') do
      data_matches_schema('key' => { nested_key: String }) { { 'key' => { nested_key: 'Value' } } }
    end

    tests('when collection of values all match schema expectation') do
      data_matches_schema([{ 'key' => String }]) { [{ 'key' => 'Value' }, { 'key' => 'Value' }] }
    end

    tests('when collection is empty although schema covers optional members') do
      data_matches_schema([{ 'key' => String }], allow_optional_rules: true) { [] }
    end

    tests('when additional keys are passed and not strict') do
      data_matches_schema({ 'key' => String }, allow_extra_keys: true) { { 'key' => 'Value', extra: 'Bonus' } }
    end

    tests('when value is nil and schema expects NilClass') do
      data_matches_schema('key' => NilClass) { { 'key' => nil } }
    end

    tests('when value and schema match as hashes') do
      data_matches_schema({}) { {} }
    end

    tests('when value and schema match as arrays') do
      data_matches_schema([]) { [] }
    end

    tests('when value is a Time') do
      data_matches_schema('time' => Time) { { 'time' => Time.now } }
    end

    tests('when key is missing but value should be NilClass (#1477)') do
      data_matches_schema({ 'key' => NilClass }, allow_optional_rules: true) { {} }
    end

    tests('when key is missing but value is nullable (#1477)') do
      data_matches_schema({ 'key' => Fog::Nullable::String }, allow_optional_rules: true) { {} }
    end
  end

  tests('#formats backwards compatible changes') do
    tests('when value matches schema expectation') do
      formats('key' => String) { { 'key' => 'Value' } }
    end

    tests('when values within an array all match schema expectation') do
      formats('key' => [Integer]) { { 'key' => [1, 2] } }
    end

    tests('when nested values match schema expectation') do
      formats('key' => { nested_key: String }) { { 'key' => { nested_key: 'Value' } } }
    end

    tests('when collection of values all match schema expectation') do
      formats([{ 'key' => String }]) { [{ 'key' => 'Value' }, { 'key' => 'Value' }] }
    end

    tests('when collection is empty although schema covers optional members') do
      formats([{ 'key' => String }]) { [] }
    end

    tests('when additional keys are passed and not strict') do
      formats({ 'key' => String }, false) { { 'key' => 'Value', :extra => 'Bonus' } }
    end

    tests('when value is nil and schema expects NilClass') do
      formats('key' => NilClass) { { 'key' => nil } }
    end

    tests('when value and schema match as hashes') do
      formats({}) { {} }
    end

    tests('when value and schema match as arrays') do
      formats([]) { [] }
    end

    tests('when value is a Time') do
      formats('time' => Time) { { 'time' => Time.now } }
    end

    tests('when key is missing but value should be NilClass (#1477)') do
      formats('key' => NilClass) { {} }
    end

    tests('when key is missing but value is nullable (#1477)') do
      formats('key' => Fog::Nullable::String) { {} }
    end
  end
end