On 09/10/06, <b class="gmail_sendername">Bryan Helmkamp</b> <<a href="mailto:bhelmkamp@gmail.com">bhelmkamp@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I think it is interesting that the following won't work for my example:<br><br>@controller.expects(:render).times(2)<br>@controller.expects(:render).with(:action => "edit")<br><br>It results in:<br><br>:render(:action => 'edit'): expected calls: 1, actual calls: 0
<br><br>Even though the render method is called twice, and one of those calls<br>is with the :action => "edit" parameter. It's like the first<br>expectation is blocking the second one from passing.</blockquote>
<div><br>Thanks for taking the time to explain more fully.<br><br>I think part of the confusion comes from the fact that it's not obvious that <span style="font-family: courier new,monospace;">object.expects(:blah)</span>
matches calls to <span style="font-family: courier new,monospace;">blah()</span> with any parameters, whereas <span style="font-family: courier new,monospace;">object.expects(:blah).with()</span> matches only calls to <span style="font-family: courier new,monospace;">
blah()</span> with no parameters.<br><br>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.
<br><br>Interestingly, if you switch the order in which the expectations are setup you get a different error...<br><br><span style="font-family: courier new,monospace;">@controller.expects(:render).with(:action => "edit")
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">@controller.expects(:render).times(2)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">:render(): expected calls: 2, actual calls: 1</span><br><br>This is because the call to <span style="font-family: courier new,monospace;">
render()</span> drops through to the second expectation, but the call to <span style="font-family: courier new,monospace;">render(:action => "edit")</span> is matched by the first expectation.<br></div><br></div>
-- <br>James.<br><a href="http://blog.floehopper.org">http://blog.floehopper.org</a>