[mocha-developer] Expecting calls with two different parameters

James Mead jamesmead44 at gmail.com
Mon Oct 9 12:57:58 EDT 2006

On 09/10/06, Bryan Helmkamp <bhelmkamp at gmail.com> wrote:
> I think it is interesting that the following won't work for my example:
> @controller.expects(:render).times(2)
> @controller.expects(:render).with(:action => "edit")
> It results in:
> :render(:action => 'edit'): expected calls: 1, actual calls: 0
> Even though the render method is called twice, and one of those calls
> is with the :action => "edit" parameter.  It's like the first
> expectation is blocking the second one from passing.

Thanks for taking the time to explain more fully.

I think part of the confusion comes from the fact that it's not obvious that
object.expects(:blah) matches calls to blah() with any parameters, whereas
object.expects(:blah).with() matches only calls to blah() with no

Your last example is interesting. You're right that the first expectation is
blocking the second. The first expectation that matches an incoming call has
its 'actual' count incremented. But it would be relatively straightforward
to increment the count for ANY expectations that match. I need to think
about whether it has any other ramifications.

Interestingly, if you switch the order in which the expectations are setup
you get a different error...

@controller.expects(:render).with(:action => "edit")

:render(): expected calls: 2, actual calls: 1

This is because the call to render() drops through to the second
expectation, but the call to render(:action => "edit") is matched by the
first expectation.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/mocha-developer/attachments/20061009/c1f5a387/attachment.html 

More information about the mocha-developer mailing list