Class: Warp::ModelMatchers::AttributeMatcher

Inherits:
Matcher show all
Defined in:
lib/warp/model_matchers/attribute_matcher.rb

Instance Attribute Summary collapse

Attributes inherited from Matcher

#model_or_instance

Instance Method Summary collapse

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

#descriptionObject



18
19
20
# File 'lib/warp/model_matchers/attribute_matcher.rb', line 18

def description
  "have attribute #{description_of(attr_name)}"
end

#failure_messageObject



22
23
24
# File 'lib/warp/model_matchers/attribute_matcher.rb', line 22

def failure_message
  "expected #{model_name} to #{description}"
end

#failure_message_when_negatedObject



26
27
28
# File 'lib/warp/model_matchers/attribute_matcher.rb', line 26

def failure_message_when_negated
  "expected #{model_name} to not #{description}"
end

#matches?(model_or_instance) ⇒ Boolean

Returns:

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