Class: Warp::ModelMatchers::AttributeMatcher
- Inherits:
-
Matcher
- Object
- Warp::Matcher
- Matcher
- Warp::ModelMatchers::AttributeMatcher
- Defined in:
- lib/warp/model_matchers/attribute_matcher.rb
Instance Attribute Summary collapse
-
#attr_name ⇒ Object
readonly
Returns the value of attribute attr_name.
Attributes inherited from Matcher
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(attr_name) ⇒ AttributeMatcher
constructor
A new instance of AttributeMatcher.
- #matches?(model_or_instance) ⇒ Boolean
Constructor Details
#initialize(attr_name) ⇒ AttributeMatcher
Returns a new instance of AttributeMatcher.
8 9 10 |
# File 'lib/warp/model_matchers/attribute_matcher.rb', line 8 def initialize(attr_name) @attr_name = attr_name.to_sym end |
Instance Attribute Details
#attr_name ⇒ Object (readonly)
Returns the value of attribute attr_name.
6 7 8 |
# File 'lib/warp/model_matchers/attribute_matcher.rb', line 6 def attr_name @attr_name end |
Instance Method Details
#description ⇒ Object
18 19 20 |
# File 'lib/warp/model_matchers/attribute_matcher.rb', line 18 def description "have attribute #{description_of(attr_name)}" end |
#failure_message ⇒ Object
22 23 24 |
# File 'lib/warp/model_matchers/attribute_matcher.rb', line 22 def "expected #{model_name} to #{description}" end |
#failure_message_when_negated ⇒ Object
26 27 28 |
# File 'lib/warp/model_matchers/attribute_matcher.rb', line 26 def "expected #{model_name} to not #{description}" end |
#matches?(model_or_instance) ⇒ Boolean
12 13 14 15 16 |
# File 'lib/warp/model_matchers/attribute_matcher.rb', line 12 def matches?(model_or_instance) @model_or_instance = model_or_instance attributes.any? {|actual| values_match?(attr_name, actual) } end |