Does an RSpec2 matcher for matching Hashes exist?

前端 未结 3 2177
渐次进展
渐次进展 2021-02-12 23:10

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

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-12 23:20

    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.

提交回复
热议问题