json-spec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.gitmodules +3 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +960 -0
  7. data/Rakefile +10 -0
  8. data/api_documentation.md +611 -0
  9. data/cachivache/.gitignore +1 -0
  10. data/cachivache/Gemfile +4 -0
  11. data/cachivache/README.md +247 -0
  12. data/cachivache/Rakefile +19 -0
  13. data/cachivache/Vagrantfile +70 -0
  14. data/cachivache/cachivache.rb +59 -0
  15. data/cachivache/lib/let-behaviour.rb +27 -0
  16. data/cachivache/lib/rake-helper.rb +131 -0
  17. data/cachivache/lib/sh-file-context.rb +39 -0
  18. data/cachivache/lib/sh-if-context.rb +31 -0
  19. data/cachivache/stuff/.gitkeep +0 -0
  20. data/cachivache/stuff/ruby-json-spec.rb +22 -0
  21. data/examples/example-1-simple.rb +66 -0
  22. data/examples/example-2-default-expectations.rb +63 -0
  23. data/examples/example-3-each-field.rb +104 -0
  24. data/examples/example-4-to-be-as-defined-in.rb +117 -0
  25. data/examples/example-5-custom-expectations.rb +153 -0
  26. data/examples/example-6-custom-messages.rb +36 -0
  27. data/examples/example-7-full-example.rb +231 -0
  28. data/examples/fixtures.rb +77 -0
  29. data/examples/validation-printer.rb +47 -0
  30. data/json-spec.gemspec +29 -0
  31. data/lib/cabeza-de-termo/json-spec/errors/error.rb +6 -0
  32. data/lib/cabeza-de-termo/json-spec/errors/expectation-not-found-error.rb +8 -0
  33. data/lib/cabeza-de-termo/json-spec/errors/modifier-not-found-error.rb +8 -0
  34. data/lib/cabeza-de-termo/json-spec/errors/unkown-json-type-error.rb +8 -0
  35. data/lib/cabeza-de-termo/json-spec/errors/validation-error.rb +8 -0
  36. data/lib/cabeza-de-termo/json-spec/expectations-library/default-expectations/default-expectation-builder.rb +29 -0
  37. data/lib/cabeza-de-termo/json-spec/expectations-library/default-expectations/default-expectations-mapping.rb +54 -0
  38. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/block-expectation-definition.rb +16 -0
  39. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/class-expectation-definition.rb +15 -0
  40. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectation-definition.rb +19 -0
  41. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb +136 -0
  42. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expecting-all-of-expectation-definition.rb +23 -0
  43. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expecting-any-of-expectation-definition.rb +23 -0
  44. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expecting-expectation-definition.rb +17 -0
  45. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/negating-expectation-definition.rb +16 -0
  46. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-library-definition-builder.rb +35 -0
  47. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/class-modifier-definition.rb +15 -0
  48. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/composing-modifiers-definition.rb +28 -0
  49. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/modifier-definition.rb +13 -0
  50. data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/modifiers-definition-builder.rb +73 -0
  51. data/lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb +150 -0
  52. data/lib/cabeza-de-termo/json-spec/expectations-library/initializers/default-library-initializer.rb +265 -0
  53. data/lib/cabeza-de-termo/json-spec/expectations-library/initializers/library-initializer.rb +9 -0
  54. data/lib/cabeza-de-termo/json-spec/expectations-library/messages/expectation-messages-mapping.rb +27 -0
  55. data/lib/cabeza-de-termo/json-spec/expectations/abstract-expectation.rb +39 -0
  56. data/lib/cabeza-de-termo/json-spec/expectations/all-expectations-composite.rb +33 -0
  57. data/lib/cabeza-de-termo/json-spec/expectations/any-expectation-composite.rb +33 -0
  58. data/lib/cabeza-de-termo/json-spec/expectations/block-expectation.rb +28 -0
  59. data/lib/cabeza-de-termo/json-spec/expectations/expectation.rb +51 -0
  60. data/lib/cabeza-de-termo/json-spec/expectations/is-email-expectation.rb +16 -0
  61. data/lib/cabeza-de-termo/json-spec/expectations/is-scalar-expectation.rb +17 -0
  62. data/lib/cabeza-de-termo/json-spec/expectations/is-url-expectation.rb +21 -0
  63. data/lib/cabeza-de-termo/json-spec/expectations/negated-expectation.rb +31 -0
  64. data/lib/cabeza-de-termo/json-spec/expectations/runner/abstract-expectations-runner.rb +27 -0
  65. data/lib/cabeza-de-termo/json-spec/expectations/runner/can-be-absent-expectations-runner.rb +50 -0
  66. data/lib/cabeza-de-termo/json-spec/expectations/runner/can-be-null-expectations-runner.rb +48 -0
  67. data/lib/cabeza-de-termo/json-spec/expectations/runner/expectations-runner.rb +43 -0
  68. data/lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb +62 -0
  69. data/lib/cabeza-de-termo/json-spec/expressions/json-anything.rb +16 -0
  70. data/lib/cabeza-de-termo/json-spec/expressions/json-each-field.rb +58 -0
  71. data/lib/cabeza-de-termo/json-spec/expressions/json-each.rb +58 -0
  72. data/lib/cabeza-de-termo/json-spec/expressions/json-expression.rb +314 -0
  73. data/lib/cabeza-de-termo/json-spec/expressions/json-field-name.rb +16 -0
  74. data/lib/cabeza-de-termo/json-spec/expressions/json-field.rb +76 -0
  75. data/lib/cabeza-de-termo/json-spec/expressions/json-list.rb +40 -0
  76. data/lib/cabeza-de-termo/json-spec/expressions/json-object.rb +82 -0
  77. data/lib/cabeza-de-termo/json-spec/expressions/json-scalar.rb +20 -0
  78. data/lib/cabeza-de-termo/json-spec/expressions/json-spec.rb +174 -0
  79. data/lib/cabeza-de-termo/json-spec/instantiators/abstract-instantiator.rb +9 -0
  80. data/lib/cabeza-de-termo/json-spec/instantiators/all-expectations-composite-instantiator.rb +12 -0
  81. data/lib/cabeza-de-termo/json-spec/instantiators/any-expectation-composite-instantiator.rb +12 -0
  82. data/lib/cabeza-de-termo/json-spec/instantiators/block-expectation-instantiator.rb +16 -0
  83. data/lib/cabeza-de-termo/json-spec/instantiators/composite-instantiator.rb +45 -0
  84. data/lib/cabeza-de-termo/json-spec/instantiators/modifier-composite-instantiator.rb +12 -0
  85. data/lib/cabeza-de-termo/json-spec/instantiators/negated-expectation-instantiator.rb +20 -0
  86. data/lib/cabeza-de-termo/json-spec/instantiators/patial-application-instantiator.rb +26 -0
  87. data/lib/cabeza-de-termo/json-spec/json-spec.rb +2 -0
  88. data/lib/cabeza-de-termo/json-spec/message-formatters/block-message-formatter.rb +15 -0
  89. data/lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb +60 -0
  90. data/lib/cabeza-de-termo/json-spec/message-formatters/message-formatter.rb +9 -0
  91. data/lib/cabeza-de-termo/json-spec/metaprogramming/message-send.rb +37 -0
  92. data/lib/cabeza-de-termo/json-spec/metaprogramming/message.rb +37 -0
  93. data/lib/cabeza-de-termo/json-spec/metaprogramming/object-method.rb +14 -0
  94. data/lib/cabeza-de-termo/json-spec/modifiers/can-be-absent-modifier.rb +13 -0
  95. data/lib/cabeza-de-termo/json-spec/modifiers/can-be-null-modifier.rb +13 -0
  96. data/lib/cabeza-de-termo/json-spec/modifiers/expression-modifier.rb +9 -0
  97. data/lib/cabeza-de-termo/json-spec/modifiers/modifier-composite.rb +27 -0
  98. data/lib/cabeza-de-termo/json-spec/signals/signal.rb +6 -0
  99. data/lib/cabeza-de-termo/json-spec/signals/skip-branch-signal.rb +8 -0
  100. data/lib/cabeza-de-termo/json-spec/utilities/bind.rb +20 -0
  101. data/lib/cabeza-de-termo/json-spec/utilities/range.rb +70 -0
  102. data/lib/cabeza-de-termo/json-spec/value-holders/accessors-chain.rb +27 -0
  103. data/lib/cabeza-de-termo/json-spec/value-holders/missing-value.rb +21 -0
  104. data/lib/cabeza-de-termo/json-spec/value-holders/value-holder.rb +135 -0
  105. data/lib/cabeza-de-termo/json-spec/version.rb +5 -0
  106. data/lib/cabeza-de-termo/json-spec/walkers/expression-walker.rb +66 -0
  107. data/lib/cabeza-de-termo/json-spec/walkers/json-expectations-runner.rb +214 -0
  108. data/lib/cabeza-de-termo/json-spec/walkers/json-expression-explainer.rb +183 -0
  109. data/lib/cabeza-de-termo/json-spec/walkers/reporter/expectation-report.rb +63 -0
  110. data/lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb +111 -0
  111. data/lib/cabeza-de-termo/json-spec/walkers/validator/json-validator-error.rb +29 -0
  112. data/lib/cabeza-de-termo/json-spec/walkers/validator/json-validator.rb +133 -0
  113. data/lib/cabeza-de-termo/json-spec/walkers/value-holders-stack-behaviour.rb +57 -0
  114. metadata +242 -0
@@ -0,0 +1,43 @@
1
+ require_relative 'abstract-expectations-runner'
2
+
3
+ module CabezaDeTermo
4
+ module JsonSpec
5
+ class ExpectationsRunner < AbstractExpectationsRunner
6
+ def initialize()
7
+ @expectations = []
8
+ end
9
+
10
+ # Adding
11
+
12
+ def add(expectation)
13
+ @expectations << expectation
14
+ end
15
+
16
+ # Accessing
17
+
18
+ def expectations
19
+ @expectations
20
+ end
21
+
22
+ # Walking
23
+
24
+ def accept_walker(expression_walker)
25
+ expression_walker.walk_expectation_runner(self)
26
+ end
27
+
28
+ def accept_walker_with_value_holder(expression_walker, value_holder)
29
+ expectations.each do |each_expectation|
30
+ each_expectation.accept_walker(expression_walker)
31
+ end
32
+ end
33
+
34
+ # Explaining
35
+
36
+ def explain_with(expression_walker)
37
+ expectations.each do |each_expectation|
38
+ expression_walker.walk_expectation(each_expectation)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,62 @@
1
+ require_relative "json-expression"
2
+
3
+ module CabezaDeTermo
4
+ module JsonSpec
5
+ #
6
+ # A JsonExpression that represents the expectations of several possible expressions to expect.
7
+ #
8
+ class JsonAnyOf < JsonExpression
9
+ #
10
+ # The expression that holds the expectations of each item in a json list.
11
+ #
12
+ # @param JsonExpression parent_expression The parent expression in the parse tree.
13
+ #
14
+ def initialize(parent_expression)
15
+ super(parent_expression)
16
+
17
+ @possible_expressions = []
18
+ end
19
+
20
+ def possible_expressions()
21
+ @possible_expressions
22
+ end
23
+
24
+ # Expectations
25
+
26
+ def expect(type, &block)
27
+ expect_a(type, &block)
28
+ end
29
+
30
+ def expect_an(type, &block)
31
+ expect_a(type, &block)
32
+ end
33
+
34
+ def expect_a(type, &block)
35
+ expression = add_posibble_expression( new_expression_for(type) )
36
+
37
+ Bind.evaluation of: block, to: self unless block.nil?
38
+
39
+ expression
40
+ end
41
+
42
+ def add_posibble_expression(expression)
43
+ possible_expressions << expression
44
+
45
+ expression
46
+ end
47
+
48
+ #
49
+ # Some intention revealing sugar to make the spec building clearer.
50
+ #
51
+ def or_also()
52
+ self
53
+ end
54
+
55
+ # Walking expressions
56
+
57
+ def accept_walker(expression_walker)
58
+ expression_walker.walk_json_any_of(self)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,16 @@
1
+ require_relative "json-expression"
2
+
3
+ module CabezaDeTermo
4
+ module JsonSpec
5
+ #
6
+ # A JsonExpression that represents any expression
7
+ #
8
+ class JsonAnything < JsonExpression
9
+ # Walking expressions
10
+
11
+ def accept_walker(expression_walker)
12
+ expression_walker.walk_json_anything(self)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,58 @@
1
+ require_relative "json-expression"
2
+
3
+ module CabezaDeTermo
4
+ module JsonSpec
5
+ #
6
+ # A JsonExpression that represents what each item in a JsonList must expect.
7
+ #
8
+ class JsonEachField < JsonExpression
9
+ def initialize(parent_expression)
10
+ super(parent_expression)
11
+
12
+ @name_expression = new_json_field_name_expression
13
+ @value_expression = nil
14
+ end
15
+
16
+ # Accessing
17
+
18
+ def name_expression()
19
+ @name_expression
20
+ end
21
+
22
+ def value_expression()
23
+ @value_expression
24
+ end
25
+
26
+ # Expectations
27
+
28
+ #
29
+ # Answer the [JsonFieldName] so it can receive expectations.
30
+ #
31
+ def expect_name()
32
+ @name_expression
33
+ end
34
+
35
+ def expect(type, &block)
36
+ expect_a(type, &block)
37
+ end
38
+
39
+ def expect_an(type, &block)
40
+ expect_a(type, &block)
41
+ end
42
+
43
+ def expect_a(type, &block)
44
+ @value_expression = new_expression_for(type)
45
+
46
+ Bind.evaluation of: block, to: @value_expression unless block.nil?
47
+
48
+ @value_expression
49
+ end
50
+
51
+ # Walking expressions
52
+
53
+ def accept_walker(expression_walker)
54
+ expression_walker.walk_json_each_field(self)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ require_relative "json-expression"
2
+
3
+ module CabezaDeTermo
4
+ module JsonSpec
5
+ #
6
+ # A JsonExpression that represents what each item in a JsonList must expect.
7
+ #
8
+ class JsonEach < JsonExpression
9
+ #
10
+ # The expression that holds the expectations of each item in a json list.
11
+ # @var JsonExpression
12
+ #
13
+ def initialize(parent_expression)
14
+ super(parent_expression)
15
+
16
+ @each_item_expression = nil
17
+ end
18
+
19
+ def each_item_expression()
20
+ @each_item_expression
21
+ end
22
+
23
+ # Asking
24
+
25
+ def has_each_item_expression?()
26
+ !no_each_item_expression?
27
+ end
28
+
29
+ def no_each_item_expression?()
30
+ @each_item_expression.nil?
31
+ end
32
+
33
+ # Expecting expressions
34
+
35
+ def expect(type, &block)
36
+ expect_a(type, &block)
37
+ end
38
+
39
+ def expect_an(type, &block)
40
+ expect_a(type, &block)
41
+ end
42
+
43
+ def expect_a(type, &block)
44
+ @each_item_expression = new_expression_for(type)
45
+
46
+ Bind.evaluation of: block, to: @each_item_expression unless block.nil?
47
+
48
+ @each_item_expression
49
+ end
50
+
51
+ # Walking expressions
52
+
53
+ def accept_walker(expression_walker)
54
+ expression_walker.walk_json_each(self)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,314 @@
1
+ require "cabeza-de-termo/json-spec/expectations/runner/expectations-runner"
2
+ require "cabeza-de-termo/json-spec/walkers/json-expression-explainer"
3
+ require "cabeza-de-termo/json-spec/metaprogramming/object-method"
4
+
5
+ module CabezaDeTermo
6
+ module JsonSpec
7
+ #
8
+ # Base class for JsonExpression representing nodes in a json parse tree.
9
+ #
10
+ class JsonExpression
11
+ #
12
+ # @param JsonExpression parent_expression The parent expression in the parse tree.
13
+ #
14
+ def initialize(parent_expression)
15
+ @parent_expression = parent_expression
16
+ @expectations_runner = new_expectations_runner
17
+
18
+ add_default_expectations
19
+ end
20
+
21
+ # Accessing
22
+
23
+ #
24
+ # Get the parent expression in the parse tree.
25
+ #
26
+ # @return JsonExpression
27
+ #
28
+ def parent_expression()
29
+ @parent_expression
30
+ end
31
+
32
+ #
33
+ # Set the parent expression in the parse tree.
34
+ #
35
+ def set_parent_expression(parent_expression)
36
+ @parent_expression = parent_expression
37
+ end
38
+
39
+ #
40
+ # Get the expectations_runner with the Expectations to run on the value
41
+ # coresponding to self expression of a json object.
42
+ #
43
+ # @return expectations_runnerInterface
44
+ #
45
+ def expectations_runner()
46
+ @expectations_runner
47
+ end
48
+
49
+ #
50
+ # Set the expectations_runner with Expectations to run on the value coresponding to self
51
+ # expression of a json object.
52
+ #
53
+ # @param expectations_runnerInterface expectations_runner
54
+ #
55
+ def set_expectations_runner(expectations_runner)
56
+ @expectations_runner = expectations_runner
57
+ end
58
+
59
+ #
60
+ # Answer the top most JsonSpec expression.
61
+ # Implemented by bubbling self message up to the JsonSpec object.
62
+ #
63
+ # @return JsonSpec
64
+ #
65
+ def json_spec()
66
+ parent_expression.json_spec
67
+ end
68
+
69
+ #
70
+ # Answer the global ExpectationsLibrary.
71
+ #
72
+ # @return JsonSpec
73
+ #
74
+ def global_expectations_library()
75
+ json_spec.global_expectations_library
76
+ end
77
+
78
+ # Error handling
79
+
80
+ #
81
+ # When we receive a message that we don't understand, check if
82
+ #
83
+ # - it is an expectation message, then add the expected Expectation to self expression
84
+ # - it is a modifier message, then run the modifier on self expression
85
+ # - if none of the above, bubble the message up to the parent expression, so it can handle
86
+ # it.
87
+ #
88
+ # @param Message message The message that self object does not understand.
89
+ #
90
+ # @return mixed Answer whatever the actual handler of the message answered
91
+ #
92
+ def method_missing(method_name, *args, &block)
93
+ message = Message.new(method_name.to_sym, *args, &block)
94
+
95
+ return add_expectation_from_library(message) if is_an_expectations_library_method?(message)
96
+ return perform_modifier_from_library(message) if is_a_modifier_library_method?(message)
97
+
98
+ super(method_name, *args, &block)
99
+ end
100
+
101
+ # Asking
102
+
103
+ #
104
+ # Answer true if the Message is an expectation message.
105
+ #
106
+ # @param Message message The message that self object does not understood.
107
+ #
108
+ # @return boolean
109
+ #
110
+ def is_an_expectations_library_method?(message)
111
+ global_expectations_library.has_expectation_for?(message.method_name)
112
+ end
113
+
114
+ #
115
+ # Answer true if the Message is a modifier message.
116
+ #
117
+ # @param Message message The message that self object does not understood.
118
+ #
119
+ # @return boolean
120
+ #
121
+ def is_a_modifier_library_method?(message)
122
+ global_expectations_library.has_modifier_for?(message.method_name)
123
+ end
124
+
125
+ # Defining Expectations
126
+
127
+ #
128
+ # Add the default expectations for this expression.
129
+ #
130
+ def add_default_expectations()
131
+ default_expectations.each do |message|
132
+ message.send_to(self)
133
+ end
134
+ end
135
+
136
+ #
137
+ # Answer the default expectations for this expression.
138
+ # Subclasses should override self methos accondingly.
139
+ #
140
+ def default_expectations()
141
+ []
142
+ end
143
+
144
+ #
145
+ # Create a new Expectation from the ExpectationsLibrary corresponding to the Message
146
+ # and add it to self expression Expectations.
147
+ # Answer self expression.
148
+ #
149
+ # @param Message message The message that self object does not understood.
150
+ #
151
+ # @return JsonExpression
152
+ #
153
+ def add_expectation_from_library(message)
154
+ expectation = global_expectations_library.new_expectation_from_message(message)
155
+
156
+ expectation.set_expectation_method(message.method_name)
157
+ expectation.set_json_spec(json_spec)
158
+
159
+ add_expectation(expectation)
160
+
161
+ Bind.evaluation of: message.block, to: self unless message.block.nil?
162
+
163
+ self
164
+ end
165
+
166
+ #
167
+ # Create a new modifier from the ExpectationsLibrary corresponding to the Message
168
+ # and allow it to modify self expression.
169
+ # Answer self expression.
170
+ #
171
+ # @param Message message The message that self object does not understood.
172
+ #
173
+ # @return JsonExpression
174
+ #
175
+ def perform_modifier_from_library(message)
176
+ modifier = global_expectations_library
177
+ .new_modifier_from_message(message)
178
+
179
+ run_modifier(modifier)
180
+
181
+ Bind.evaluation of: message.block, to: self unless message.block.nil?
182
+
183
+ self
184
+ end
185
+
186
+ def run_modifier(modifier)
187
+ modifier.run_on(self)
188
+ end
189
+
190
+ #
191
+ # Add an Expectation it to self expression Expectations.
192
+ # Answer self expression.
193
+ #
194
+ # @param Message message The message that self object does not understood.
195
+ #
196
+ # @return JsonExpression
197
+ #
198
+ def add_expectation(expectation)
199
+ expectations_runner.add(expectation)
200
+ end
201
+
202
+ #
203
+ # Send to object a message named method_name with self expression as its parameter
204
+ # to allow it to add more expectations to self expression.
205
+ # Answer the same that answers the message sent.
206
+ #
207
+ # @param mixed object The object receiving the message.
208
+ #
209
+ # @param string method_name The name of the method to invoke on the object.
210
+ #
211
+ # @return mixed
212
+ #
213
+ def to_be_as_defined_in(object, method_name)
214
+ to_be_as_defined_by( ObjectMethod.new(object, method_name) )
215
+ end
216
+
217
+ #
218
+ # Evaluate the Valuable with self expression as its parameter to allow it to add more
219
+ # expectations to self expression.
220
+ # Answer the same that answers the Valuable.
221
+ #
222
+ # @param Valuable valuable The object to evaluate with self expression as its parameter.
223
+ #
224
+ # @return mixed
225
+ #
226
+ def to_be_as_defined_by(callable)
227
+ callable.call(self)
228
+ end
229
+
230
+ # Default Expectations
231
+
232
+ #
233
+ # Answer a collection of default Expectations to add to a new expression of type
234
+ # json_expression_type.
235
+ #
236
+ # @param string json_expression_type The type of the expression.
237
+ #
238
+ # @return Expectation[]
239
+ #
240
+ def default_expectations_for(json_expression_type)
241
+ json_spec.default_expectations_for(json_expression_type)
242
+ end
243
+
244
+ # Instance creation
245
+
246
+ def new_expression_for(type)
247
+ return new_scalar_expression if type == :scalar
248
+ return new_object_expression if type == :object
249
+ return new_list_expression if type == :list
250
+ return new_any_of_expression if type == :any_of
251
+ return new_anything_expression if type == :anything
252
+
253
+ raise "Invalid expected type: #{type.inspect}"
254
+ end
255
+
256
+ #
257
+ # Answer an ExpectationInterface to hold the Expectations on this expression.
258
+ #
259
+ # @return ExpectationInterface
260
+ #
261
+ def new_expectations_runner()
262
+ ExpectationsRunner.new
263
+ end
264
+
265
+ def new_object_expression()
266
+ JsonObject.new(self)
267
+ end
268
+
269
+ def new_list_expression()
270
+ JsonList.new(self)
271
+ end
272
+
273
+ def new_scalar_expression()
274
+ JsonScalar.new(self)
275
+ end
276
+
277
+ def new_any_of_expression()
278
+ JsonAnyOf.new(self)
279
+ end
280
+
281
+ def new_json_field_name_expression()
282
+ JsonFieldName.new(self)
283
+ end
284
+
285
+ def new_json_each_expression()
286
+ JsonEach.new(self)
287
+ end
288
+
289
+ def new_anything_expression()
290
+ JsonAnything.new(self)
291
+ end
292
+
293
+ #
294
+ # Create a new JsonField named field_name.
295
+ #
296
+ # @param string field_name The name of the field to create on self JsonObject.
297
+ #
298
+ # @return JsonField
299
+ #
300
+ def new_named_field_expression(field_name)
301
+ JsonField.new(self, field_name)
302
+ end
303
+
304
+ #
305
+ # Create a new JsonEachField.
306
+ #
307
+ # @return JsonEachField
308
+ #
309
+ def new_each_field()
310
+ JsonEachField.new(self)
311
+ end
312
+ end
313
+ end
314
+ end