Note to future readers: think RSpec does not consider your Hashes equal? One might be an OrderedHash, but from the regular RSpec output you can\'t tell. This was the problem tha
Since 8 months the gem rspec-matchers
has support for matching hashes:
expected.should be_hash_matching(subhash_or_equal)
see here for more details: https://github.com/rspec/rspec-expectations/pull/79
describe 'Hash' do
let(:x) { { :a => 1, :b => 2 } }
let(:y) { { :b => 2, :a => 1 } }
it "should be equal with ==" do
x.should == y
end
end
Passes. I'm not sure what's going on in your specific case. Do you have some failing examples you can share?
Programming Ruby has this to say:
Equality — Two hashes are equal if they have the same default value, they contain the same number of keys, and the value corresponding to each key in the first hash is equal (using ==) to the value for the same key in the second.
I believe the eql? method checks only that the two hashes have the same content So IIRC in Rspec2 you can do:
expected = {:foo => 1, 'baz' => 2}
expected.should be_eql({'baz' => 2, :foo => 1})
And the test should pass