Skip to content

Instantly share code, notes, and snippets.

@knowuh
Created July 29, 2016 17:28
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 knowuh/93860603392876df8b5148f72ce6b345 to your computer and use it in GitHub Desktop.
Save knowuh/93860603392876df8b5148f72ce6b345 to your computer and use it in GitHub Desktop.
rspec matcher for finding a hash inside an array.
RSpec::Matchers.define :include_hash do |comp_hash|
match do |actual|
found = false
actual.each do |test|
hash_matched = true
comp_hash.each_pair do |key,value|
hash_matched = hash_matched && test.has_key?(key) && test[key] == value
end
found = hash_matched
break if found
end
found
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment