Class: RSpec::Rabl::AttributeMatcher
- Inherits:
-
Object
- Object
- RSpec::Rabl::AttributeMatcher
- Defined in:
- lib/rspec/rabl/attribute_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(rendered_attribute, opts = {}) ⇒ AttributeMatcher
constructor
A new instance of AttributeMatcher.
- #matches?(subject) ⇒ Boolean
- #with(model_attribute) ⇒ Object
- #with_value(expected_value) ⇒ Object
Constructor Details
#initialize(rendered_attribute, opts = {}) ⇒ AttributeMatcher
Returns a new instance of AttributeMatcher.
4 5 6 7 |
# File 'lib/rspec/rabl/attribute_matcher.rb', line 4 def initialize(rendered_attribute, opts = {}) @rendered_attribute = rendered_attribute @opts = opts end |
Instance Method Details
#description ⇒ Object
9 10 11 |
# File 'lib/rspec/rabl/attribute_matcher.rb', line 9 def description "render the #{rendered_attribute} attribute" end |
#failure_message ⇒ Object
13 14 15 |
# File 'lib/rspec/rabl/attribute_matcher.rb', line 13 def "expected #{expected_value.inspect} in #{attribute_path}\n got #{rendered_value.inspect}" end |
#matches?(subject) ⇒ Boolean
17 18 19 20 |
# File 'lib/rspec/rabl/attribute_matcher.rb', line 17 def matches?(subject) @subject = subject attribute_rendered? && (!expected_value_set || rendered_value == expected_value) end |
#with(model_attribute) ⇒ Object
22 23 24 25 |
# File 'lib/rspec/rabl/attribute_matcher.rb', line 22 def with(model_attribute) @model_attribute = model_attribute self end |
#with_value(expected_value) ⇒ Object
27 28 29 30 31 |
# File 'lib/rspec/rabl/attribute_matcher.rb', line 27 def with_value(expected_value) @expected_value_set = true @expected_value = expected_value self end |