class RSpecJsonMatchers::AbsenceMatcher
This is a special matcher that always returns false under normal circumstances, used to indicate keys that should not be present in a given API response.
The only circumstance where the matcher may return true is in the class method `is_an_absence_matcher?`, which takes a matcher and feeds a special `ABSENCE_MARKER` value into it which should fail every possible matcher other than AbsenceMatcher
, which it passes. We can use this to determine whether it's OK for a given key to be absent from a response. TODO: try to make this explanation less confusing.
Constants
- ABSENCE_MARKER
Public Class Methods
is_an_absence_matcher?(matcher)
click to toggle source
Test whether the given matcher is either an instance of AbsenceMatcher
or a compound matcher containing an AbsenceMatcher
, like 'absent.or(a_kind_of(Integer))'.
# File lib/rspec_json_matchers/absence_matcher.rb, line 18 def self.is_an_absence_matcher?(matcher) matcher === ABSENCE_MARKER && !(matcher === Object.new) end
new()
click to toggle source
# File lib/rspec_json_matchers/absence_matcher.rb, line 22 def initialize @expected = ABSENCE_MARKER end
Public Instance Methods
description()
click to toggle source
# File lib/rspec_json_matchers/absence_matcher.rb, line 26 def description 'absent' end