Class: RSpec::SleepingKingStudios::Matchers::Core::DeepMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::SleepingKingStudios::Matchers::Core::DeepMatcher
- Includes:
- Matchers::Composable
- 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.
16 17 18 19 20 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb', line 16 def initialize(expected) super() @expected = expected end |
Instance Method Details
#description ⇒ Object
23 24 25 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb', line 23 def description "match #{format_expected(@expected)}" end |
#does_not_match?(actual) ⇒ Boolean
Inverse of #matches? method.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb', line 35 def does_not_match?(actual) # rubocop:disable Metrics/MethodLength, Naming/PredicatePrefix 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.
52 53 54 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb', line 52 def # rubocop:disable Style/TrivialAccessors @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.
57 58 59 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb', line 57 def # rubocop:disable Style/TrivialAccessors @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.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rspec/sleeping_king_studios/matchers/core/deep_matcher.rb', line 76 def matches?(actual) # rubocop:disable Metrics/MethodLength 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 |