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?
how about?
hashes = [{"foo" => "1", "bar" => "2"}, {"foo" => "2", "bar" => "2"}] expect(hashes).to include(include('foo' => '2')) 
                        Use Composable Matchers
hashes = [{"foo" => "1", "bar" => "2"}, {"foo" => "2", "bar" => "2"}] expect(hashes)   .to match([     a_hash_including('foo' => '2'),      a_hash_including('foo' => '1')   ]) 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With