Class: CabezaDeTermo::JsonSpec::ExpectationsDefinitionBuilder
- Inherits:
-
Object
- Object
- CabezaDeTermo::JsonSpec::ExpectationsDefinitionBuilder
show all
- Defined in:
- lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ExpectationsDefinitionBuilder.
18
19
20
21
22
23
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 18
def initialize(expectations_library, &block)
@expectations_library = expectations_library
reset_current_definition
CdT.bind_block_evaluation_to self, &block
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Delegate every method to the current definition builder
131
132
133
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 131
def method_missing(method_name, *args, &block)
@definition.send(method_name, *args, &block)
end
|
Class Method Details
.for(expectations_library, &block) ⇒ Object
14
15
16
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 14
def self.for(expectations_library, &block)
new(expectations_library, &block)
end
|
Instance Method Details
#define(method_name, &block) ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 57
def define(method_name, &block)
@method_name = method_name.to_sym
CdT.bind_block_evaluation_to self, &block
define_expectation_in_library
define_expectation_message_in_library
reset_current_definition
end
|
#define_expectation_in_library ⇒ Object
112
113
114
115
116
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 112
def define_expectation_in_library
return unless has_expectation_definition?
expectations_library.define_expectation(method_name, expectation_instantiator)
end
|
#define_expectation_message_in_library ⇒ Object
118
119
120
121
122
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 118
def define_expectation_message_in_library
return unless has_message_definition?
expectations_library.define_message_formatter_for(method_name, @message_formatter)
end
|
#definition ⇒ Object
35
36
37
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 35
def definition
@definition
end
|
#expectation_instantiator ⇒ Object
124
125
126
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 124
def expectation_instantiator
definition.expectation_instantiator
end
|
#expectations_library ⇒ Object
27
28
29
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 27
def expectations_library
@expectations_library
end
|
#expecting(expectation_method, *args) ⇒ Object
83
84
85
86
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 83
def expecting(expectation_method, *args)
@definition = ExpectingExpectationDefinition.new(expectations_library)
@definition.expect(expectation_method, *args)
end
|
#expecting_all_of(expectation_method, *args) ⇒ Object
93
94
95
96
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 93
def expecting_all_of(expectation_method, *args)
@definition = ExpectingAllOfExpectationDefinition.new(expectations_library)
@definition.and_also(expectation_method, *args)
end
|
#expecting_any_of(expectation_method, *args) ⇒ Object
88
89
90
91
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 88
def expecting_any_of(expectation_method, *args)
@definition = ExpectingAnyOfExpectationDefinition.new(expectations_library)
@definition.or_also(expectation_method, *args)
end
|
#has_expectation_definition? ⇒ Boolean
41
42
43
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 41
def has_expectation_definition?
!@definition.nil?
end
|
#has_message_definition? ⇒ Boolean
45
46
47
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 45
def has_message_definition?
!@message_formatter.nil?
end
|
#message(message) ⇒ Object
104
105
106
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 104
def message(message)
message_formatter ErbMessageFormatter.new(message)
end
|
#message_block(&block) ⇒ Object
108
109
110
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 108
def message_block(&block)
message_formatter BlockMessageFormatter.new(block)
end
|
100
101
102
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 100
def message_formatter(message_formatter)
@message_formatter = message_formatter
end
|
#method_name ⇒ Object
31
32
33
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 31
def method_name
@method_name
end
|
#negating(expectation_method) ⇒ Object
78
79
80
81
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 78
def negating(expectation_method)
@definition = NegatingExpectationDefinition.new(expectations_library)
@definition.negate expectation_method
end
|
#reset_current_definition ⇒ Object
51
52
53
54
55
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 51
def reset_current_definition
@method_name = nil
@definition = nil
@message_formatter = nil
end
|
#with_block(&block) ⇒ Object
73
74
75
76
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 73
def with_block(&block)
@definition = BlockExpectationDefinition.new(expectations_library)
@definition.block block
end
|
#with_class(klass) ⇒ Object
68
69
70
71
|
# File 'lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb', line 68
def with_class(klass)
@definition = ClassExpectationDefinition.new(expectations_library)
@definition.klass klass
end
|