gpt4 book ai didi

ruby-on-rails - 如何在 RSpec 中多说几次 "should_receive"

转载 作者:行者123 更新时间:2023-12-03 04:46:27 25 4
gpt4 key购买 nike

我的测试中有这个

Project.should_receive(:find).with(@project).and_return(@project)

但是当对象收到该方法调用两次时,我必须这样做

Project.should_receive(:find).with(@project).and_return(@project)
Project.should_receive(:find).with(@project).and_return(@project)

有什么办法可以这样说

Project.should_receive(:find).with(@project).and_return(@project).times(2)

最佳答案

这已经过时了。请查看Uri's answer下面

2次:

Project.should_receive(:find).twice.with(@project).and_return(@project)

恰好n次:

Project.should_receive(:find).exactly(n).times.with(@project).and_return(@project)

至少n次:

Project.should_receive(:msg).at_least(n).times.with(@project).and_return(@project)

更多详情请访问https://www.relishapp.com/rspec/rspec-mocks/v/2-13/docs/message-expectations/receive-counts接收计数

关于ruby-on-rails - 如何在 RSpec 中多说几次 "should_receive",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1328277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com