Class: CabezaDeTermo::JsonSpec::JsonAnyOf

Inherits:
JsonExpression show all
Defined in:
lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb

Overview

A JsonExpression that represents the expectations of several possible expressions to expect.

Instance Method Summary collapse

Methods inherited from JsonExpression

#add_default_expectations, #add_expectation, #add_expectation_from_library, #default_expectations, #default_expectations_for, #expectations_library, #expectations_runner, #is_a_modifier_library_method?, #is_an_expectations_library_method?, #json_spec, #method_missing, #new_any_of_expression, #new_anything_expression, #new_each_field, #new_expectations_runner, #new_expression_for, #new_json_each_expression, #new_json_field_name_expression, #new_list_expression, #new_named_field_expression, #new_object_expression, #new_scalar_expression, #parent_expression, #perform_modifier_from_library, #run_modifier, #set_expectations_runner, #set_parent_expression, #to_be_as_defined_by, #to_be_as_defined_in

Constructor Details

#initialize(parent_expression) ⇒ JsonAnyOf

The expression that holds the expectations of each item in a json list.

Parameters:

  • JsonExpression

    parent_expression The parent expression in the parse tree.



14
15
16
17
18
# File 'lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb', line 14

def initialize(parent_expression)
	super(parent_expression)

	@possible_expressions = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CabezaDeTermo::JsonSpec::JsonExpression

Instance Method Details

#accept_walker(expression_walker) ⇒ Object

Walking expressions



57
58
59
# File 'lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb', line 57

def accept_walker(expression_walker)
	expression_walker.walk_json_any_of(self)
end

#add_posibble_expression(expression) ⇒ Object



42
43
44
45
46
# File 'lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb', line 42

def add_posibble_expression(expression)
	possible_expressions << expression

	expression
end

#expect(type, &block) ⇒ Object

Expectations



26
27
28
# File 'lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb', line 26

def expect(type, &block)
	expect_a(type, &block)
end

#expect_a(type, &block) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb', line 34

def expect_a(type, &block)
	expression = add_posibble_expression( new_expression_for(type) )

	CdT.bind_block_evaluation_to self, &block unless block.nil?

	expression
end

#expect_an(type, &block) ⇒ Object



30
31
32
# File 'lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb', line 30

def expect_an(type, &block)
	expect_a(type, &block)
end

#or_alsoObject

Some intention revealing sugar to make the spec building clearer.



51
52
53
# File 'lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb', line 51

def or_also()
	self
end

#possible_expressionsObject



20
21
22
# File 'lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb', line 20

def possible_expressions()
	@possible_expressions
end