Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Better hash match
# I want to have better messaging, diffs, etc. here
RSpec::Matchers.define :include_hash do |expected|
match do |actual|
binding.pry
!expected.map {|k,v| actual[k] == v }.include?(false)
end
failure_message_for_should do |actual|
"expected that #{actual} would include all the key/values of #{expected}"
end
failure_message_for_should_not do |actual|
"expected that #{actual} would not include all the key/values of #{expected}"
end
description do
"include all the key/values of #{expected}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment