2
可以說我有方法#sum
它需要一個數組並計算所有元素的總和。我正在琢磨它:RSpec預計接收數組的方法,但順序並不重要
before do
expect(calculation_service).to receive(:sum?).with([1, 2, 3]) { 6 }
end
不幸的是我的測試套裝隨機傳遞數組。因爲這個錯誤提出:
Failure/Error: subject { do_crazy_stuff! }
#<InstanceDouble() (CalculationService)> received :sum? with unexpected arguments
expected: ([1, 2, 3])
got: ([3, 2, 1])
是否有可能存根方法調用忽略數組元素的順序? array_including(1, 2, 3)
不保證有關數組大小,所以它可能不是最好的解決方案