在RSpec的mock docs上我发现了
期望(double)。接收(:msg).exactly(3).times.and_return(value1,value2,value3)
#第一次返回value1,第二次返回value2,等等。
如果我执行相同的with
参数,例如。
期望(double)。接收(:msg).exactly(3).times.with(value1,value2,value3)
RSpec自然希望msg
被value1, value2, value3
调用三次。
有没有办法说called the first time with value1, the second time with value 2, etc
?
答案 0 :(得分:0)
尝试使用.ordered
,如下所示:
expect(double).to receive(:msg).with(value1).ordered
expect(double).to receive(:msg).with(value2).ordered
expect(double).to receive(:msg).with(value3).ordered