Module: RSpec::Notifications::PayloadMatcher
- Defined in:
- lib/rspec/notifications/payload_matcher.rb
Overview
Matches an expected payload against an actual notification payload.
Matching is partial at the top level: only the keys named in expected are checked, so unrelated payload keys are ignored. Values are compared with RSpec’s fuzzy matching, which supports embedded matchers (e.g. kind_of(Integer)), regexps, ranges, and nested structures. Nested hashes are compared exactly – use a_hash_including(…) for a nested partial match.
Class Method Summary collapse
Class Method Details
.matches?(expected, actual) ⇒ Boolean
16 17 18 19 20 21 22 23 24 |
# File 'lib/rspec/notifications/payload_matcher.rb', line 16 def matches?(expected, actual) return true if expected.nil? return false unless actual.is_a?(Hash) expected.all? do |key, value| actual.key?(key) && RSpec::Support::FuzzyMatcher.values_match?(value, actual.fetch(key)) end end |