相关疑难解决方法(0)

Rspec:"array.should == another_array"但不关心订单

我经常想要比较数组并确保它们以任何顺序包含相同的元素.在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)

当数组元素未实现时,这会失败 #<=>

ruby testing rspec

229
推荐指数
5
解决办法
6万
查看次数

标签 统计

rspec ×1

ruby ×1

testing ×1