Class: Warp::ModelMatchers::AssociationMatcher
- Inherits:
-
Matcher
- Object
- Warp::Matcher
- Matcher
- Warp::ModelMatchers::AssociationMatcher
- Defined in:
- lib/warp/model_matchers/association_matcher.rb
Instance Attribute Summary collapse
-
#expected_macro ⇒ Object
readonly
Returns the value of attribute expected_macro.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Attributes inherited from Matcher
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected_macro, key) ⇒ AssociationMatcher
constructor
A new instance of AssociationMatcher.
- #matches?(model_or_instance) ⇒ Boolean
Methods inherited from Warp::Matcher
#description_of, #failure_message_for_should, #failure_message_for_should_not, #values_match?
Constructor Details
#initialize(expected_macro, key) ⇒ AssociationMatcher
Returns a new instance of AssociationMatcher.
6 7 8 9 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 6 def initialize(expected_macro, key) @expected_macro = expected_macro @key = key end |
Instance Attribute Details
#expected_macro ⇒ Object (readonly)
Returns the value of attribute expected_macro.
4 5 6 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 4 def expected_macro @expected_macro end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 4 def key @key end |
Instance Method Details
#description ⇒ Object
17 18 19 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 17 def description "have a #{expected_macro} association with :#{key}" end |
#failure_message ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 21 def if association "expected #{model_name} to #{description}, but had a #{assocation_macro} association with :#{key}" else "expected #{model_name} to #{description}" end end |
#failure_message_when_negated ⇒ Object
29 30 31 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 29 def "expected #{model_name} to not #{description}" end |
#matches?(model_or_instance) ⇒ Boolean
11 12 13 14 15 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 11 def matches?(model_or_instance) @model_or_instance = model_or_instance association && values_match?(expected_macro, assocation_macro) end |