Class: Minicrest::NoEntry

Inherits:
HashEntryMatcher show all
Defined in:
lib/minicrest/hash_entry_matchers.rb

Overview

Matcher that checks if no entries in a hash match a given condition.

Instance Method Summary collapse

Methods inherited from HashEntryMatcher

#hash?, #initialize

Methods inherited from Matcher

#&, #|

Constructor Details

This class inherits a constructor from Minicrest::HashEntryMatcher

Instance Method Details

#descriptionObject



102
103
104
# File 'lib/minicrest/hash_entry_matchers.rb', line 102

def description
  'no entries match condition'
end

#failure_message(actual) ⇒ Object



106
107
108
109
110
111
# File 'lib/minicrest/hash_entry_matchers.rb', line 106

def failure_message(actual)
  return "expected a Hash, but got #{actual.inspect}" unless hash?(actual)

  matching_entry = actual.find { |k, v| entry_matches?(k, v) }
  "expected no entries to match, but entry #{matching_entry.inspect} did"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
99
100
# File 'lib/minicrest/hash_entry_matchers.rb', line 96

def matches?(actual)
  return false unless hash?(actual)

  actual.none? { |k, v| entry_matches?(k, v) }
end

#negated_failure_message(actual) ⇒ Object



113
114
115
116
117
# File 'lib/minicrest/hash_entry_matchers.rb', line 113

def negated_failure_message(actual)
  return "expected a Hash, but got #{actual.inspect}" unless hash?(actual)

  'expected some entries to match, but none did'
end