[rspec-users] a MockExpectationError problem

Patrick J. Collins patrick at collinatorstudios.com
Sun Apr 25 18:25:25 EDT 2010

Here is a gist of my code:

> Use stub when you just want to provide the plumbing. Use should_receive when
> you are setting an expectation. As an example, you could do
> Photo.stub(:create) just to provide the method to avoid errors when your code
> calls it. But if you actually want to verify that your code calls it, then do

Well, as you can see by my code, I am actually doing a loop

@card.addresses.each ....  This is calling the @country = get_country ||
Country.find_by_name("United States")

So-- the number of times .find_by_name needs to be intercepted by
.should_receive is dependent on the number of addresses in a vcard.

This was the problem I didn't know how to address, and using stub! resolved it,
but like I said--  I didn't know if there's a more appropriate way to do it.

Patrick J. Collins

More information about the rspec-users mailing list