Class: Minicrest::AllEntries

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

Overview

Matcher that checks if all 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



52
53
54
# File 'lib/minicrest/hash_entry_matchers.rb', line 52

def description
  'all entries match condition'
end

#failure_message(actual) ⇒ Object



56
57
58
59
60
61
# File 'lib/minicrest/hash_entry_matchers.rb', line 56

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

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/minicrest/hash_entry_matchers.rb', line 46

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

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

#negated_failure_message(_actual) ⇒ Object



63
64
65
# File 'lib/minicrest/hash_entry_matchers.rb', line 63

def negated_failure_message(_actual)
  'expected not all entries to match, but they all did'
end