Class: RSpec::Rabl::AttributeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/rabl/attribute_matcher.rb

Instance Method Summary collapse

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

#descriptionObject



9
10
11
# File 'lib/rspec/rabl/attribute_matcher.rb', line 9

def description
  "render the #{rendered_attribute} attribute"
end

#failure_messageObject



13
14
15
# File 'lib/rspec/rabl/attribute_matcher.rb', line 13

def failure_message
  "expected #{expected_value.inspect} in #{attribute_path}\n  got #{rendered_value.inspect}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (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