Class: RSpec::SleepingKingStudios::Matchers::Core::DeepMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::SleepingKingStudios::Matchers::Core::DeepMatcher
- Defined in:
- lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb
Overview
Matcher for performing a deep comparison between two objects.
Constant Summary
Constants included from Description
Description::DEFAULT_EXPECTED_ITEMS
Instance Attribute Summary
Attributes inherited from BaseMatcher
Instance Method Summary collapse
- #description ⇒ Object
-
#does_not_match?(actual) ⇒ Boolean
Inverse of #matches? method.
-
#failure_message ⇒ Object
Message for when the object does not match, but was expected to.
-
#failure_message_when_negated ⇒ Object
Message for when the object matches, but was expected not to.
-
#initialize(expected) ⇒ DeepMatcher
constructor
A new instance of DeepMatcher.
-
#matches?(actual) ⇒ Boolean
Performs a deep comparison between the actual object and the expected object.
Constructor Details
#initialize(expected) ⇒ DeepMatcher
Returns a new instance of DeepMatcher.
14 15 16 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb', line 14 def initialize(expected) @expected = expected end |
Instance Method Details
#description ⇒ Object
19 20 21 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb', line 19 def description "match #{format_expected(@expected)}" end |
#does_not_match?(actual) ⇒ Boolean
Inverse of #matches? method.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb', line 31 def does_not_match? actual super if matcher?(@expected) delegate_to_negated_matcher(@expected) elsif @expected.is_a?(Array) && actual.is_a?(Array) diff_arrays_negated elsif @expected.is_a?(Hash) && actual.is_a?(Hash) diff_hashes_negated else delegate_to_negated_matcher(equality_matcher) end !@matches end |
#failure_message ⇒ Object
Message for when the object does not match, but was expected to. Make sure to always call #matches? first to set up the matcher state.
48 49 50 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb', line 48 def @failure_message end |
#failure_message_when_negated ⇒ Object
Message for when the object matches, but was expected not to. Make sure to always call #matches? first to set up the matcher state.
53 54 55 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb', line 53 def @failure_message_when_negated end |
#matches?(actual) ⇒ Boolean
Performs a deep comparison between the actual object and the expected object. The type of comparison depends on the type of the expected object:
-
If the expected object is an RSpec matcher, the #matches? method on the matcher is called with the expected object.
-
If the expected object is an Array, then each item is compared based on the type of the expected item.
-
If the expected object is a Hash, then the keys must match and each value is compared based on the type of the expected value.
-
Otherwise, the two objects are compared using an equality comparison.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb', line 72 def matches?(actual) super if matcher?(@expected) delegate_to_matcher(@expected) elsif @expected.is_a?(Array) && actual.is_a?(Array) diff_arrays elsif @expected.is_a?(Hash) && actual.is_a?(Hash) diff_hashes else delegate_to_matcher(equality_matcher) end @matches end |