Can someone please explain to me why this spec fails it "should work" do template.stub!(:render) template.should_receive(:render).with(:partial => "foo") render @template_with_render_partial_foo end but this spec passes it "should work" do @foo.stub!(:bar) @foo.should_receive(:bar).with(:baz) @foo.bar :baz end It seems like they should work similarly and indeed this has worked for me until I switched to gem rspec-rails from vendor/plugin [recent]. Not sure what I''m doing wrong here. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081107/65200647/attachment-0001.html>
Can someone please explain to me why this spec fails it "should work" do template.stub!(:render) template.should_receive(:render).with(:partial => "foo") render @template_with_render_partial_foo end but this spec passes it "should work" do @foo.stub!(:bar) @foo.should_receive(:bar).with(:baz) @foo.bar :baz end It seems like they should work similarly and indeed this has worked for me until I switched to gem rspec-rails from vendor/plugin [recent]. Not sure what I''m doing wrong here. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081107/3742989e/attachment.html>
On Fri, Nov 7, 2008 at 4:35 PM, Russell Norris <rsl at swimcommunity.org> wrote:> Can someone please explain to me why this spec fails > > it "should work" do > > template.stub!(:render) > > template.should_receive(:render).with(:partial => "foo") > > render @template_with_render_partial_foo > > end > > but this spec passes > > it "should work" do > > @foo.stub!(:bar) > > @foo.should_receive(:bar).with(:baz) > > @foo.bar :baz > > end > > It seems like they should work similarly and indeed this has worked for me > until I switched to gem rspec-rails from vendor/plugin [recent]. Not sure > what I''m doing wrong here. >In the first example, you call "stub!(:render)". This is stubbing all calls to render with any arguments. So you''ve stubbed the call that "render @template_with_render_partial_foo" makes. Try: template.stub!(:render).with(:partial => anything) -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
On Fri, Nov 7, 2008 at 4:35 PM, Russell Norris <rsl at swimcommunity.org> wrote:> Can someone please explain to me why this spec fails > > it "should work" do > > template.stub!(:render) > > template.should_receive(:render).with(:partial => "foo") > > render @template_with_render_partial_fooCan you put the rest of the spec and the view in? What failure message are you getting?> > end > > but this spec passes > > it "should work" do > > @foo.stub!(:bar) > > @foo.should_receive(:bar).with(:baz) > > @foo.bar :baz > > end > > It seems like they should work similarly and indeed this has worked for me > until I switched to gem rspec-rails from vendor/plugin [recent]. Not sure > what I''m doing wrong here.
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! RSL On Fri, Nov 7, 2008 at 4:59 PM, Zach Dennis <zach.dennis at gmail.com> wrote:> On Fri, Nov 7, 2008 at 4:35 PM, Russell Norris <rsl at swimcommunity.org> > wrote: > > Can someone please explain to me why this spec fails > > > > it "should work" do > > > > template.stub!(:render) > > > > template.should_receive(:render).with(:partial => "foo") > > > > render @template_with_render_partial_foo > > > > end > > > > but this spec passes > > > > it "should work" do > > > > @foo.stub!(:bar) > > > > @foo.should_receive(:bar).with(:baz) > > > > @foo.bar :baz > > > > end > > > > It seems like they should work similarly and indeed this has worked for > me > > until I switched to gem rspec-rails from vendor/plugin [recent]. Not sure > > what I''m doing wrong here. > > > > In the first example, you call "stub!(:render)". This is stubbing all > calls to render with any arguments. So you''ve stubbed the call that > "render @template_with_render_partial_foo" makes. > > Try: template.stub!(:render).with(:partial => anything) > > > -- > Zach Dennis > http://www.continuousthinking.com > http://www.mutuallyhuman.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081107/b45a801d/attachment.html>
Per David''s request i made a pastie of the whole view and the whole test of an example of this. as well as the output. http://pastie.org/309868 RSL 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! > > RSL > > > On Fri, Nov 7, 2008 at 4:59 PM, Zach Dennis <zach.dennis at gmail.com> wrote: > >> On Fri, Nov 7, 2008 at 4:35 PM, Russell Norris <rsl at swimcommunity.org> >> wrote: >> > Can someone please explain to me why this spec fails >> > >> > it "should work" do >> > >> > template.stub!(:render) >> > >> > template.should_receive(:render).with(:partial => "foo") >> > >> > render @template_with_render_partial_foo >> > >> > end >> > >> > but this spec passes >> > >> > it "should work" do >> > >> > @foo.stub!(:bar) >> > >> > @foo.should_receive(:bar).with(:baz) >> > >> > @foo.bar :baz >> > >> > end >> > >> > It seems like they should work similarly and indeed this has worked for >> me >> > until I switched to gem rspec-rails from vendor/plugin [recent]. Not >> sure >> > what I''m doing wrong here. >> > >> >> In the first example, you call "stub!(:render)". This is stubbing all >> calls to render with any arguments. So you''ve stubbed the call that >> "render @template_with_render_partial_foo" makes. >> >> Try: template.stub!(:render).with(:partial => anything) >> >> >> -- >> Zach Dennis >> http://www.continuousthinking.com >> http://www.mutuallyhuman.com >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081107/ec823331/attachment.html>
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.stub!(:render) template.should_receive(:render).with(:partial => "foo") render @template_with_render_partial_foo # in your view you call <%= render :partial => "foo" %> end Here''s what it is really doing: it "should work" do @controller.template.stub!(:render) @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" end 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 http://www.continuousthinking.com http://www.mutuallyhuman.com