Rspec: “array.should == another_array” but without concern for order

前端 未结 6 2046

I often want to compare arrays and make sure that they contain the same elements, in any order. Is there a concise way to do this in RSpec?

Here are methods that are

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 10:22

    I've found =~ to be unpredictable and it has failed for no apparent reason. Past 2.14, you should probably use

    expect([1, 2, 3]).to match_array([2, 3, 1])
    

提交回复
热议问题