Class: Neo4j::RSpec::Matchers::HasN::AssociationMatcher
- Inherits:
-
Object
- Object
- Neo4j::RSpec::Matchers::HasN::AssociationMatcher
- Defined in:
- lib/neo4j/rspec/matchers/has_n.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
Returns the value of attribute association.
-
#expectation_message ⇒ Object
Returns the value of attribute expectation_message.
-
#negative_result_message ⇒ Object
Returns the value of attribute negative_result_message.
-
#positive_result_message ⇒ Object
Returns the value of attribute positive_result_message.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(name, macro) ⇒ AssociationMatcher
constructor
A new instance of AssociationMatcher.
- #macro_description ⇒ Object
- #matchers ⇒ Object
- #matches?(actual) ⇒ Boolean
- #with_direction(direction) ⇒ Object
- #with_model_class(model_class) ⇒ Object
- #with_origin(origin) ⇒ Object
- #with_type(type) ⇒ Object
- #without_type ⇒ Object
Constructor Details
#initialize(name, macro) ⇒ AssociationMatcher
144 145 146 147 148 149 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 144 def initialize(name, macro) @association = {} @association[:name] = name.to_sym @association[:macro] = macro = "#{macro_description} #{@association[:name]}" end |
Instance Attribute Details
#association ⇒ Object
Returns the value of attribute association.
141 142 143 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 141 def association @association end |
#expectation_message ⇒ Object
Returns the value of attribute expectation_message.
141 142 143 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 141 def end |
#negative_result_message ⇒ Object
Returns the value of attribute negative_result_message.
141 142 143 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 141 def end |
#positive_result_message ⇒ Object
Returns the value of attribute positive_result_message.
141 142 143 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 141 def end |
Instance Method Details
#description ⇒ Object
208 209 210 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 208 def description end |
#failure_message ⇒ Object
200 201 202 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 200 def "Expected #{@actual.class} to #{expectation_message}, got #{negative_result_message}" end |
#failure_message_when_negated ⇒ Object
204 205 206 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 204 def "Expected #{@actual.class} to not #{expectation_message}, got #{positive_result_message}" end |
#macro_description ⇒ Object
151 152 153 154 155 156 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 151 def macro_description case association[:macro] when :has_many then "have many" when :has_one then "have one" end end |
#matchers ⇒ Object
158 159 160 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 158 def matchers association.select { |_, v| v.is_a? BaseMatcher } end |
#matches?(actual) ⇒ Boolean
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 182 def matches?(actual) @actual = actual actual_association = actual.class.associations[association[:name]] unless actual_association self. = "no association named #{association[:name]}" return false else self. = "association named #{association[:name]}" end matchers.each do |_, matcher| return false unless matcher.matches?(actual_association) end true end |
#with_direction(direction) ⇒ Object
162 163 164 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 162 def with_direction(direction) DirectionMatcher.new(self, direction).add end |
#with_model_class(model_class) ⇒ Object
178 179 180 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 178 def with_model_class(model_class) ModelClassesMatcher.new(self, model_class).add end |
#with_origin(origin) ⇒ Object
174 175 176 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 174 def with_origin(origin) OriginMatcher.new(self, origin).add end |
#with_type(type) ⇒ Object
166 167 168 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 166 def with_type(type) TypeMatcher.new(self, type).add end |
#without_type ⇒ Object
170 171 172 |
# File 'lib/neo4j/rspec/matchers/has_n.rb', line 170 def without_type TypeMatcher.new(self, false).add_negative end |