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
Constructor Details
#initialize(expected_macro, key) ⇒ AssociationMatcher
Returns a new instance of AssociationMatcher.
8 9 10 11 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 8 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.
6 7 8 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 6 def expected_macro @expected_macro end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 6 def key @key end |
Instance Method Details
#description ⇒ Object
19 20 21 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 19 def description "have a #{expected_macro} association with :#{key}" end |
#failure_message ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 23 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
31 32 33 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 31 def "expected #{model_name} to not #{description}" end |
#matches?(model_or_instance) ⇒ Boolean
13 14 15 16 17 |
# File 'lib/warp/model_matchers/association_matcher.rb', line 13 def matches?(model_or_instance) @model_or_instance = model_or_instance association && values_match?(expected_macro, assocation_macro) end |