Hey guys. I would like to test the following behavior: render :update do |page| page.replace_html ''errors'', :partial => ''signup_errors'', :locals => { :errors => ''errors''} end } I''m doing: controller.should_receive(:render).with(:update) But I am not sure on how to test the block. Maybe checking out what is the class of the page var and setting up an expection on it? Any suggestions appreciated, Marcelo. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100614/70f567c9/attachment-0001.html>
On Jun 14, 2010, at 6:40 PM, Marcelo de Moraes Serpa wrote:> Hey guys. > > I would like to test the following behavior: > > render :update do |page| > page.replace_html ''errors'', :partial => ''signup_errors'', :locals => { :errors => ''errors''} > end > } > > I''m doing: > > controller.should_receive(:render).with(:update) > > But I am not sure on how to test the block. Maybe checking out what is the class of the page var and setting up an expection on it?Hmmm. The common idiom for this is: page = double(''page'') controller.stub(:render).with(:update).and_yield(page) page.should_receive(:replace_html).with(...) This does not seem to work with rspec-2/rails-3. Don''t know why yet (won''t be able to look for a bit), but my guess is that something (like rspec :) ) is adding render() to the controller even later than this stub does. I''ll follow up if I learn something. HTH, David
On 2010-06-14 6:40 PM, Marcelo de Moraes Serpa wrote:> Hey guys. > > I would like to test the following behavior: > > render :update do |page| > page.replace_html ''errors'', :partial => ''signup_errors'', > :locals => { :errors => ''errors''} > end > } > > I''m doing: > > controller.should_receive(:render).with(:update) > > But I am not sure on how to test the block. Maybe checking out what is > the class of the page var and setting up an expection on it? > > Any suggestions appreciated, > > Marcelo.I don''t know if this is the "right" way to do it, but if I''m going to test this code: render :update do |page| page.replace :flash_messages, :partial => ''_partials/web/layouts/flash_messages'' end I use this: it ''should render update'' do page = mock(''page'') page.should_receive(:replace).with(:flash_messages, :partial => ''_partials/web/layouts/flash_messages'') controller.should_receive(:render).with(:update).and_yield(page) xhr :post, :create, <some params> end Peace, Phillip
On Jun 14, 2010, at 7:05 PM, David Chelimsky wrote:> On Jun 14, 2010, at 6:40 PM, Marcelo de Moraes Serpa wrote: > >> Hey guys. >> >> I would like to test the following behavior: >> >> render :update do |page| >> page.replace_html ''errors'', :partial => ''signup_errors'', :locals => { :errors => ''errors''} >> end >> } >> >> I''m doing: >> >> controller.should_receive(:render).with(:update) >> >> But I am not sure on how to test the block. Maybe checking out what is the class of the page var and setting up an expection on it? > > Hmmm. The common idiom for this is: > > page = double(''page'') > controller.stub(:render).with(:update).and_yield(page) > page.should_receive(:replace_html).with(...) > > This does not seem to work with rspec-2/rails-3. Don''t know why yet (won''t be able to look for a bit), but my guess is that something (like rspec :) ) is adding render() to the controller even later than this stub does. I''ll follow up if I learn something.Looks like action_pack calls render twice (the 2nd time in action_controller/metal/implicit_render.rb:10:in `default_render''), so we''ve got to stub the :render call twice: page = double(''page'') controller.stub(:render) controller.stub(:render).with(:update).and_yield(page) page.should_receive(:replace_html).with(...) Bummer. It seems like this is a rails bug (render should only get called once, and there is code that prevents it from being called twice, but not _all_ of the time), but I''m not sure if I can make that case or not. I''ll try :) Cheers, David
Thanks for the heads out, David :) On Mon, Jun 14, 2010 at 9:35 PM, David Chelimsky <dchelimsky at gmail.com>wrote:> > On Jun 14, 2010, at 7:05 PM, David Chelimsky wrote: > > > On Jun 14, 2010, at 6:40 PM, Marcelo de Moraes Serpa wrote: > > > >> Hey guys. > >> > >> I would like to test the following behavior: > >> > >> render :update do |page| > >> page.replace_html ''errors'', :partial => ''signup_errors'', > :locals => { :errors => ''errors''} > >> end > >> } > >> > >> I''m doing: > >> > >> controller.should_receive(:render).with(:update) > >> > >> But I am not sure on how to test the block. Maybe checking out what is > the class of the page var and setting up an expection on it? > > > > Hmmm. The common idiom for this is: > > > > page = double(''page'') > > controller.stub(:render).with(:update).and_yield(page) > > page.should_receive(:replace_html).with(...) > > > > This does not seem to work with rspec-2/rails-3. Don''t know why yet > (won''t be able to look for a bit), but my guess is that something (like > rspec :) ) is adding render() to the controller even later than this stub > does. I''ll follow up if I learn something. > > Looks like action_pack calls render twice (the 2nd time in > action_controller/metal/implicit_render.rb:10:in `default_render''), so we''ve > got to stub the :render call twice: > > page = double(''page'') > controller.stub(:render) > controller.stub(:render).with(:update).and_yield(page) > page.should_receive(:replace_html).with(...) > > Bummer. It seems like this is a rails bug (render should only get called > once, and there is code that prevents it from being called twice, but not > _all_ of the time), but I''m not sure if I can make that case or not. I''ll > try :) > > Cheers, > David > _______________________________________________ > 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/20100615/c9dc8ade/attachment-0001.html>
Por nada! ps - em ingl?s, a frase ? "heads up" :) On Jun 15, 2010, at 5:27 PM, Marcelo de Moraes Serpa wrote:> Thanks for the heads out, David :) > > On Mon, Jun 14, 2010 at 9:35 PM, David Chelimsky <dchelimsky at gmail.com> wrote: > > On Jun 14, 2010, at 7:05 PM, David Chelimsky wrote: > > > On Jun 14, 2010, at 6:40 PM, Marcelo de Moraes Serpa wrote: > > > >> Hey guys. > >> > >> I would like to test the following behavior: > >> > >> render :update do |page| > >> page.replace_html ''errors'', :partial => ''signup_errors'', :locals => { :errors => ''errors''} > >> end > >> } > >> > >> I''m doing: > >> > >> controller.should_receive(:render).with(:update) > >> > >> But I am not sure on how to test the block. Maybe checking out what is the class of the page var and setting up an expection on it? > > > > Hmmm. The common idiom for this is: > > > > page = double(''page'') > > controller.stub(:render).with(:update).and_yield(page) > > page.should_receive(:replace_html).with(...) > > > > This does not seem to work with rspec-2/rails-3. Don''t know why yet (won''t be able to look for a bit), but my guess is that something (like rspec :) ) is adding render() to the controller even later than this stub does. I''ll follow up if I learn something. > > Looks like action_pack calls render twice (the 2nd time in action_controller/metal/implicit_render.rb:10:in `default_render''), so we''ve got to stub the :render call twice: > > page = double(''page'') > controller.stub(:render) > controller.stub(:render).with(:update).and_yield(page) > page.should_receive(:replace_html).with(...) > > Bummer. It seems like this is a rails bug (render should only get called once, and there is code that prevents it from being called twice, but not _all_ of the time), but I''m not sure if I can make that case or not. I''ll try :) > > Cheers, > 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-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100615/55a77d1d/attachment.html>
Ah! Thanks for the heads up about heads out ;) Obrigado, Marcelo. On Tue, Jun 15, 2010 at 5:34 PM, David Chelimsky <dchelimsky at gmail.com>wrote:> Por nada! > > ps - em ingl?s, a frase ? "heads up" :) > > On Jun 15, 2010, at 5:27 PM, Marcelo de Moraes Serpa wrote: > > Thanks for the heads out, David :) > > On Mon, Jun 14, 2010 at 9:35 PM, David Chelimsky <dchelimsky at gmail.com>wrote: > >> >> On Jun 14, 2010, at 7:05 PM, David Chelimsky wrote: >> >> > On Jun 14, 2010, at 6:40 PM, Marcelo de Moraes Serpa wrote: >> > >> >> Hey guys. >> >> >> >> I would like to test the following behavior: >> >> >> >> render :update do |page| >> >> page.replace_html ''errors'', :partial => ''signup_errors'', >> :locals => { :errors => ''errors''} >> >> end >> >> } >> >> >> >> I''m doing: >> >> >> >> controller.should_receive(:render).with(:update) >> >> >> >> But I am not sure on how to test the block. Maybe checking out what is >> the class of the page var and setting up an expection on it? >> > >> > Hmmm. The common idiom for this is: >> > >> > page = double(''page'') >> > controller.stub(:render).with(:update).and_yield(page) >> > page.should_receive(:replace_html).with(...) >> > >> > This does not seem to work with rspec-2/rails-3. Don''t know why yet >> (won''t be able to look for a bit), but my guess is that something (like >> rspec :) ) is adding render() to the controller even later than this stub >> does. I''ll follow up if I learn something. >> >> Looks like action_pack calls render twice (the 2nd time in >> action_controller/metal/implicit_render.rb:10:in `default_render''), so we''ve >> got to stub the :render call twice: >> >> page = double(''page'') >> controller.stub(:render) >> controller.stub(:render).with(:update).and_yield(page) >> page.should_receive(:replace_html).with(...) >> >> Bummer. It seems like this is a rails bug (render should only get called >> once, and there is code that prevents it from being called twice, but not >> _all_ of the time), but I''m not sure if I can make that case or not. I''ll >> try :) >> >> Cheers, >> 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100615/de42b544/attachment.html>
David Chelimsky wrote:> > Looks like action_pack calls render twice (the 2nd time in > action_controller/metal/implicit_render.rb:10:in `default_render''), so > we''ve got to stub the :render call twice: > > page = double(''page'') > controller.stub(:render) > controller.stub(:render).with(:update).and_yield(page) > page.should_receive(:replace_html).with(...) > > Bummer. It seems like this is a rails bug (render should only get called > once, and there is code that prevents it from being called twice, but > not _all_ of the time), but I''m not sure if I can make that case or not. > I''ll try :)Have this problem been reported to the rails project. I am not using rspec, but trying to stub away rendering and run into the same situation; have to call #expects twice using Mocha framework. Could it be this ticket: https://rails.lighthouseapp.com/projects/8994/tickets/2279-render-layout-with-block-and-multiple-yields -- Posted via http://www.ruby-forum.com/.