I have an array of hashes, which for the sake of argument looks like this:
[{"foo"=>"1", "bar"=>"1"}, {"foo"=>"2", "bar"=>"2"}]
Using Rspec, I want to test if "foo" => "2" exists in the array, but I don't care whether it's the first or second item. I've tried:
[{"foo" => "1", "bar" => "2"}, {"foo" => "2", "bar" => "2"}].should include("foo" => "2"))
But this doesn't work, as the hashes should match exactly. Is there any way to partially test each hash's content?
[{"foo" => "1", "bar" => "2"}, {"foo" => "2", "bar" => "2"}].flat_map(&:to_a).should include(["foo","2"])will work also.