How to say “should_receive” more times in RSpec

前端 未结 4 782
无人共我
无人共我 2020-12-23 12:47

I have this in my test

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

but when object receive that method call two times

4条回答
  •  长情又很酷
    2020-12-23 13:36

    The new expect syntax of rspec will look like this:

    for 2 times:

    expect(Project).to receive(:find).twice.with(@project).and_return(@project)
    

    for exactly n times:

    expect(Project).to receive(:find).exactly(n).times.with(@project).and_return(@project)
    

    for at least n times:

    expect(Project).to receive(:msg).at_least(n).times.with(@project).and_return(@project)
    

提交回复
热议问题