如何解决如何只测试RSpec中的多个方法调用之一?
def some_method
subject.put(1)
subject.put(2)
...
end
由于对put
的调用不止一次,因此以下操作失败,是否可以仅验证发生的第一个调用不关心其余调用?
expect(subject).to receive(:put).with(1).once
解决方法
玩了一会儿,以下内容起作用了。
allow(subject).to receive(:put)
expect(subject).to receive(:put).with(1).once
,
通常,您需要将设置和期望分开,例如:
before do
allow(subject).to receive(:put)
end
it 'invokes put' do
expect(subject).to receive(:put).with(1).once
end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。