How to say “should_receive” more times in RSpec

前端 未结 4 774
无人共我
无人共我 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:32

    This is outdated. Please check Uri's answer below

    for 2 times:

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

    for exactly n times:

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

    for at least n times:

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

    more details at https://www.relishapp.com/rspec/rspec-mocks/v/2-13/docs/message-expectations/receive-counts under Receive Counts

    Hope it helps =)

提交回复
热议问题