views:

475

answers:

2

I have this in my test

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)

Is there any way how to say something like

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

The only way I found to solve this is

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

but it doesn't seem like nice solution to me.

Darth
+6  A: 

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 http://rspec.info/documentation/mocks/message_expectations.html under Receive Counts

Hope it helps =)

Staelen