Last Updated: February 25, 2016
·
3.212K
· trybeee

Rspec array equality

[1,2,3].should =~ [1,3,2]

is the same as

[1,2,3].sort.should == [1,3,2].sort

If you need to test whether two arrays contain same elements disregarding its order, you could use "=~" method.

4 Responses
Add your response

Superb! Just what i missed for so long.

over 1 year ago ·

"If you need to test whether two arrays contain same elements disregarding its order"
In such a case you should you sets. ;)

over 1 year ago ·

@cypok yes, but only in case you have no duplicates.

over 1 year ago ·