我经常想要比较数组并确保它们以任何顺序包含相同的元素.在RSpec中有一个简洁的方法吗?
以下是不可接受的方法:
#to_set
例如:
expect(array.to_set).to eq another_array.to_set
Run Code Online (Sandbox Code Playgroud)
要么
array.to_set.should == another_array.to_set
Run Code Online (Sandbox Code Playgroud)
当数组包含重复项时,这会失败.
#sort
例如:
expect(array.sort).to eq another_array.sort
Run Code Online (Sandbox Code Playgroud)
要么
array.sort.should == another_array.sort
Run Code Online (Sandbox Code Playgroud)
当数组元素未实现时,这会失败 #<=>