Skip to content

Instantly share code, notes, and snippets.

@cbartlett
Created September 11, 2012 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbartlett/3700171 to your computer and use it in GitHub Desktop.
Save cbartlett/3700171 to your computer and use it in GitHub Desktop.
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