Class: Crspec::Matchers::HaveAttributesMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- Crspec::Matchers::HaveAttributesMatcher
- Defined in:
- lib/crspec/matchers.rb
Instance Attribute Summary
Attributes inherited from BaseMatcher
Instance Method Summary collapse
Methods inherited from BaseMatcher
#and, #failure_message_when_negated, #initialize, #or
Constructor Details
This class inherits a constructor from Crspec::Matchers::BaseMatcher
Instance Method Details
#failure_message ⇒ Object
469 470 471 472 473 474 475 476 477 478 |
# File 'lib/crspec/matchers.rb', line 469 def details = @mismatches.map do |attr, val| if val == :no_method "#{attr}: (does not respond)" else "#{attr}: expected #{@expected[attr].inspect}, got #{val.inspect}" end end "Expected #{@actual.inspect} to have attributes #{@expected.inspect}:\n #{details.join("\n ")}" end |
#matches?(actual) ⇒ Boolean
455 456 457 458 459 460 461 462 463 464 465 466 467 |
# File 'lib/crspec/matchers.rb', line 455 def matches?(actual) @actual = actual @mismatches = {} @expected.each do |attr, value| unless actual.respond_to?(attr) @mismatches[attr] = :no_method next end actual_value = actual.public_send(attr) @mismatches[attr] = actual_value unless value == actual_value || value === actual_value end @mismatches.empty? end |