[rspec-users] a MockExpectationError problem

Patrick J. Collins
Sun, 25 Apr 2010 22:25:25 -0000

Here is a gist of my code:
http://gist.github.com/378778

> 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.