リストに必要な要素が過不足なく含まれていることをチェックするとき,いちいちリストをソートしなくても=~
を使えばよい
array1.should =~ array2
マッチしなかった場合は足りない/余計な要素を別途表示してくれるので,そういう点でもsortして==より=~
の方がよい.
# test
[:zero, :one, :three].should =~ [:one, :two]
# log
Failure/Error: [:zero, :one, :three].should =~ [:one, :two]
expected collection contained: [:one, :two]
actual collection contained: [:one, :three, :zero]
the missing elements were: [:two]
the extra elements were: [:three, :zero]