[rspec-users] Confusion At Failing Specs

Zach Dennis zach.dennis at gmail.com
Fri Nov 7 20:17:07 EST 2008

On Fri, Nov 7, 2008 at 5:17 PM, Russell Norris <rsl at swimcommunity.org> wrote:
> Zach,
> Thank you so much. That works for me.
> I'm still confused why stubbing all calls to :bar on @foo would allow
> @foo.should_receive(:bar).with(:baz) when this doesn't work though. But I
> feel like I'm looking a gift horse in the mouth here!

The reason this doesn't work is because rspec's "render" method in
your view example is just wrapping a call to the actual template.
Here's what I mean. Given your example:

  it "should work" do
    template.should_receive(:render).with(:partial => "foo")
    render @template_with_render_partial_foo
    # in your view you call <%= render :partial => "foo" %>

Here's what it is really doing:

  it "should work" do
    @controller.template.should_receive(:render).with(:partial => "foo")
    @controller.template.render @template_with_render_partial_foo
    # in your view you call <%= render :partial => "foo" %>
    @controller.template.render :partial => "foo"

The @controller.template is the actual template that gets rendered.
The "render" call in your example is made on the same template object
that the actual "render :partial" call is made on. So, when you make
the call to render the @template_with_render_partial_foo you have
stubbed out that render method and it never actually renders anything
causing your  example to fail because it never gets to the view
template that calls 'render :partial => "foo"'

Hopefully this helps clear it up?

Zach Dennis

More information about the rspec-users mailing list