I'm attempting to check if there is anything at all in an array, and I'm confused about the results.
markets.any? do |m|
m["market"]["name"] == "Atlanta"
end.should be_true
Returns You have a nil object when you didn't expect it!, You might have expected an instance of Array.
But
markets.empty? do |m|
m["market"]["name"] == "Atlanta"
end.should be_false
Doesn't error. But it seems backwards to me, because I want to test for true, not false. And I don't get why .any? thinks it's nill. BTW, there are 3 items in the array, and none are nil.
As per your comment, the market key is not present in hash, try following
markets.any? do |m|
m["name"] == "Atlanta"
end.should be_true
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