[rspec-devel] [ rspec-Bugs-13278 ] should_receive fails too fast?
noreply at rubyforge.org
noreply at rubyforge.org
Wed Aug 22 10:04:08 EDT 2007
Bugs item #13278, was opened at 2007-08-22 13:49
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=13278&group_id=797
Category: mock module
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 3
Submitted By: Michael Hamann (michitux)
Assigned to: Nobody (None)
Summary: should_receive fails too fast?
Initial Comment:
I don't know if this is a bug.
I discovered the problem when I wanted to verify that a specific link in a view-template is created and so I mocked link_to with these arguments. But link_to is already called before the call I want to match with other arguments. And now the expectation fails although the correct arguments are passed to link_to, too. To reproduce this behavior I patched the specs of rspec, the diff is here: http://pastie.caboo.se/90016. A workaround is to stub the method before setting up the mock, then it works.
----------------------------------------------------------------------
>Comment By: David Chelimsky (dchelimsky)
Date: 2007-08-22 14:04
Message:
This is just the way mocks work. When you mock a method with specific arguments, it is only expecting that one call with those arguments. This is true of mocha, flexmock, jmock, easymock, etc.
To solve your problem you want to stub the method first and then mock it:
template.stub!(:link_to).and_return(whatever)
template.should_receive(:link_to).with(specific args).and_return(whatever)
----------------------------------------------------------------------
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=13278&group_id=797
More information about the rspec-devel
mailing list