Class: CabezaDeTermo::JsonSpec::ExpectationsLibrary
- Inherits:
-
Object
- Object
- CabezaDeTermo::JsonSpec::ExpectationsLibrary
- Defined in:
- lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb
Class Method Summary collapse
-
.current ⇒ Object
Instance accessing.
- .define(&block) ⇒ Object
-
.new_default ⇒ Object
Initializing.
- .reset ⇒ Object
- .set_current(expectations_library) ⇒ Object
Instance Method Summary collapse
-
#default_expectations ⇒ Object
Accessing.
-
#define(&block) ⇒ Object
Defining.
-
#define_expectation(expectation_method, expectation_instantiator) ⇒ Object
Expectations.
- #define_message_formatter_for(expectation_method, message_block) ⇒ Object
-
#define_modifier(expectation_method, modifier_instantiator) ⇒ Object
Modifiers.
- #expectation_instantiator_for(expectation_method) ⇒ Object
- #has_expectation_for?(expectation_method) ⇒ Boolean
-
#has_message_formatter_for?(expectation_method) ⇒ Boolean
Expectation messages.
- #has_modifier_for?(expectation_method) ⇒ Boolean
-
#initialize ⇒ ExpectationsLibrary
constructor
Instance methods.
- #message_formatter_for(expectation_method) ⇒ Object
- #modifier_instantiator_for(method_name) ⇒ Object
- #new_default_expectations_mapping ⇒ Object
- #new_expectation_from_message(message) ⇒ Object
-
#new_expectations_messages_mapping ⇒ Object
Helpers.
- #new_modifier_from_message(message) ⇒ Object
Constructor Details
#initialize ⇒ ExpectationsLibrary
Instance methods
45 46 47 48 49 50 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 45 def initialize() @expectations = {} @modifiers = {} = @default_expectations_mapping = new_default_expectations_mapping end |
Class Method Details
.current ⇒ Object
Instance accessing
17 18 19 20 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 17 def self.current() @current = new_default if @current.nil? @current end |
.define(&block) ⇒ Object
29 30 31 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 29 def self.define(&block) current.define(&block) end |
.new_default ⇒ Object
Initializing
39 40 41 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 39 def self.new_default() DefaultLibraryInitializer.new_library end |
.reset ⇒ Object
33 34 35 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 33 def self.reset() @current = nil end |
.set_current(expectations_library) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 22 def self.set_current(expectations_library) to_be_replaced = current @current = expectations_library to_be_replaced end |
Instance Method Details
#default_expectations ⇒ Object
Accessing
54 55 56 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 54 def default_expectations() @default_expectations_mapping end |
#define(&block) ⇒ Object
Defining
60 61 62 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 60 def define(&block) CdT.bind_block_evaluation_to ExpectationLibraryDefinitionBuilder.new(self), &block end |
#define_expectation(expectation_method, expectation_instantiator) ⇒ Object
Expectations
82 83 84 85 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 82 def define_expectation(expectation_method, expectation_instantiator) @expectations[expectation_method.to_sym] = expectation_instantiator self end |
#define_message_formatter_for(expectation_method, message_block) ⇒ Object
74 75 76 77 78 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 74 def (expectation_method, ) .(expectation_method, ) self end |
#define_modifier(expectation_method, modifier_instantiator) ⇒ Object
Modifiers
102 103 104 105 106 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 102 def define_modifier(expectation_method, modifier_instantiator) @modifiers[expectation_method.to_sym] = modifier_instantiator self end |
#expectation_instantiator_for(expectation_method) ⇒ Object
91 92 93 94 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 91 def expectation_instantiator_for(expectation_method) return @expectations[expectation_method.to_sym] if has_expectation_for?(expectation_method) raise ExpectationNotFoundError.new("The Expectation method '#{expectation_method}' was not found.") end |
#has_expectation_for?(expectation_method) ⇒ Boolean
87 88 89 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 87 def has_expectation_for?(expectation_method) @expectations.key?(expectation_method.to_sym) end |
#has_message_formatter_for?(expectation_method) ⇒ Boolean
Expectation messages
66 67 68 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 66 def (expectation_method) .(expectation_method) end |
#has_modifier_for?(expectation_method) ⇒ Boolean
108 109 110 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 108 def has_modifier_for?(expectation_method) @modifiers.key?(expectation_method.to_sym) end |
#message_formatter_for(expectation_method) ⇒ Object
70 71 72 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 70 def (expectation_method) .(expectation_method) end |
#modifier_instantiator_for(method_name) ⇒ Object
112 113 114 115 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 112 def modifier_instantiator_for(method_name) return @modifiers[method_name.to_sym] if has_modifier_for?(method_name) raise ModifierNotFoundError.new("The modifier method '#{method_name}' was not found.") end |
#new_default_expectations_mapping ⇒ Object
127 128 129 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 127 def new_default_expectations_mapping() DefaultExpectationsMapping.new end |
#new_expectation_from_message(message) ⇒ Object
96 97 98 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 96 def () expectation_instantiator_for( .method_name ).new( *.args ) end |
#new_expectations_messages_mapping ⇒ Object
Helpers
123 124 125 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 123 def () ExpectationMessagesMapping.new end |
#new_modifier_from_message(message) ⇒ Object
117 118 119 |
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 117 def () modifier_instantiator_for(.method_name).new( *.args ) end |