怎么说“should_receive"在 RSpec 中更多次 [英] How to say "should_receive" more times in RSpec

查看:36
本文介绍了怎么说“should_receive"在 RSpec 中更多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的测试中有这个

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

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

but when object receive that method call two times, I have to do

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 的回答

两次:

This is outdated. Please check Uri's answer below

for 2 times:

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接收计数

希望有帮助 =)

这篇关于怎么说“should_receive"在 RSpec 中更多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆