Trunksters, I just added a couple of methods to ActionView::Base in Spec::Rails (as of r2136) that lets you do this in view examples: describe ''/things/index.html.erb'' do it "should render _thing with a collection of things" do assigns[:things] = things = [Object.new] template.expect_render(:partial => ''thing'', :collection => things) render ''/things/index.html.erb'' end end This solves two big problems - mocking nested partials and mocking :object and :collection in partials. template.expect_render wraps part of ''spec/mocks'', but not the whole framework - so we get the expectation matching benefit w/o conflicting with other mock frameworks that ppl might choose to use. There is also template.stub_render(opts) in case you just want to stub the render w/o verification. I would LOVE it if some of you would try this method out and provide feedback before we release it. Please feel to ask any questions about this on this list. Thanks, David
Hi, I''d like to stub out a partial call but not sure how. I tried something like this it "should render partial foo" do template.stub_render("bar/foo") render "/layouts/bar.html.erb" response.should render("bar/foo") end but the partial is still getting called On Jun 27, 2007, at 1:31 AM, David Chelimsky wrote:> Trunksters, > > I just added a couple of methods to ActionView::Base in Spec::Rails > (as of r2136) that lets you do this in view examples: > > describe ''/things/index.html.erb'' do > it "should render _thing with a collection of things" do > assigns[:things] = things = [Object.new] > template.expect_render(:partial => ''thing'', :collection => things) > render ''/things/index.html.erb'' > end > end > > This solves two big problems - mocking nested partials and mocking > :object and :collection in partials. > > template.expect_render wraps part of ''spec/mocks'', but not the whole > framework - so we get the expectation matching benefit w/o conflicting > with other mock frameworks that ppl might choose to use. > > There is also template.stub_render(opts) in case you just want to stub > the render w/o verification. > > I would LOVE it if some of you would try this method out and provide > feedback before we release it. Please feel to ask any questions about > this on this list. > > Thanks, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
oops, my bad this works (asserts pass, and partial not called) template.expect_render(:partial => ''bar/foo'') render "/layouts/bar.html.erb" so does this: template.stub_render(:partial => ''bar/foo'') render "/layouts/bar.html.erb" neither case seems to try to render the partial On Aug 11, 2007, at 6:11 AM, Jonathan Linowes wrote:> > Hi, I''d like to stub out a partial call but not sure how. > > I tried something like this > > it "should render partial foo" do > template.stub_render("bar/foo") > render "/layouts/bar.html.erb" > response.should render("bar/foo") > end > > but the partial is still getting called > > > On Jun 27, 2007, at 1:31 AM, David Chelimsky wrote: > >> Trunksters, >> >> I just added a couple of methods to ActionView::Base in Spec::Rails >> (as of r2136) that lets you do this in view examples: >> >> describe ''/things/index.html.erb'' do >> it "should render _thing with a collection of things" do >> assigns[:things] = things = [Object.new] >> template.expect_render(:partial => ''thing'', :collection => >> things) >> render ''/things/index.html.erb'' >> end >> end >> >> This solves two big problems - mocking nested partials and mocking >> :object and :collection in partials. >> >> template.expect_render wraps part of ''spec/mocks'', but not the whole >> framework - so we get the expectation matching benefit w/o >> conflicting >> with other mock frameworks that ppl might choose to use. >> >> There is also template.stub_render(opts) in case you just want to >> stub >> the render w/o verification. >> >> I would LOVE it if some of you would try this method out and provide >> feedback before we release it. Please feel to ask any questions about >> this on this list. >> >> Thanks, >> David >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On 8/11/07, Jonathan Linowes <jonathan at parkerhill.com> wrote:> oops, my bad > > this works (asserts pass, and partial not called) > > template.expect_render(:partial => ''bar/foo'') > render "/layouts/bar.html.erb" > > so does this: > > template.stub_render(:partial => ''bar/foo'') > render "/layouts/bar.html.erb" > > neither case seems to try to render the partialRight - the difference is that stub_render won''t complain if the partial is not rendered, so if what you mean to do is specify that it should be rendered, then you should use expects_render.> > > > On Aug 11, 2007, at 6:11 AM, Jonathan Linowes wrote: > > > > > Hi, I''d like to stub out a partial call but not sure how. > > > > I tried something like this > > > > it "should render partial foo" do > > template.stub_render("bar/foo") > > render "/layouts/bar.html.erb" > > response.should render("bar/foo") > > end > > > > but the partial is still getting called > > > > > > On Jun 27, 2007, at 1:31 AM, David Chelimsky wrote: > > > >> Trunksters, > >> > >> I just added a couple of methods to ActionView::Base in Spec::Rails > >> (as of r2136) that lets you do this in view examples: > >> > >> describe ''/things/index.html.erb'' do > >> it "should render _thing with a collection of things" do > >> assigns[:things] = things = [Object.new] > >> template.expect_render(:partial => ''thing'', :collection => > >> things) > >> render ''/things/index.html.erb'' > >> end > >> end > >> > >> This solves two big problems - mocking nested partials and mocking > >> :object and :collection in partials. > >> > >> template.expect_render wraps part of ''spec/mocks'', but not the whole > >> framework - so we get the expectation matching benefit w/o > >> conflicting > >> with other mock frameworks that ppl might choose to use. > >> > >> There is also template.stub_render(opts) in case you just want to > >> stub > >> the render w/o verification. > >> > >> I would LOVE it if some of you would try this method out and provide > >> feedback before we release it. Please feel to ask any questions about > >> this on this list. > >> > >> Thanks, > >> David > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >