Created
July 29, 2016 17:28
-
-
Save knowuh/93860603392876df8b5148f72ce6b345 to your computer and use it in GitHub Desktop.
rspec matcher for finding a hash inside an array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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