Class: CabezaDeTermo::JsonSpec::ExpectationsLibrary

Inherits:
Object
  • Object
show all
Defined in:
lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExpectationsLibrary

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 = {}
  @expectation_messages_mapping = new_expectations_messages_mapping
  @default_expectations_mapping = new_default_expectations_mapping
end

Class Method Details

.currentObject

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_defaultObject

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

.resetObject



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_expectationsObject

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 define_message_formatter_for(expectation_method, message_block)
  @expectation_messages_mapping.define_message_formatter_for(expectation_method, message_block)

  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

Returns:

  • (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

Returns:

  • (Boolean)


66
67
68
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 66

def has_message_formatter_for?(expectation_method)
  @expectation_messages_mapping.has_message_formatter_for?(expectation_method)
end

#has_modifier_for?(expectation_method) ⇒ Boolean

Returns:

  • (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 message_formatter_for(expectation_method)
  @expectation_messages_mapping.message_formatter_for(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_mappingObject



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 new_expectation_from_message(message)
  expectation_instantiator_for( message.method_name ).new( *message.args )
end

#new_expectations_messages_mappingObject

Helpers



123
124
125
# File 'lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb', line 123

def new_expectations_messages_mapping()
  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 new_modifier_from_message(message)
  modifier_instantiator_for(message.method_name).new( *message.args )
end