J2M
2008-Aug-08 20:46 UTC
[rspec-users] template.expect_render fails when partial is rendered from a helper
My spec; describe ''subnav rendering while logged in'' do before do template.stub!(:logged_in?).and_return(true) template.stub! (:current_profile).at_least(:once).and_return(mock_profile) end def do_render render "/homepages/show.html.erb" end it "should render the logged in partial for homepages" do template.expect_render(:partial => ''shared/subnav/home'', :locals => {:active => :home}) do_render end end passes if I render the partial directly in the view, render :partial => ''shared/subnav/home'', :locals => {:active => :home} but it fails if the partial is rendered by a helper; module ApplicationHelper def subnav(partial, args={}) active = args[:active] || :no_highlight if partial == :home partial = (logged_in? ? ''home'' : ''login'') end render :partial => "shared/subnav/#{partial}", :locals => {:active => active} end end Is there any way to check whether the helper renders it?
J2M
2008-Aug-14 14:20 UTC
[rspec-users] template.expect_render fails when partial is rendered from a helper
Is this expected behaviour? On Aug 8, 9:46?pm, J2M <james2mccar... at gmail.com> wrote:> My spec; > > ? describe ''subnav rendering while logged in'' do > > ? ? before do > ? ? ? template.stub!(:logged_in?).and_return(true) > ? ? ? template.stub! > (:current_profile).at_least(:once).and_return(mock_profile) > ? ? end > > ? ? def do_render > ? ? ? render "/homepages/show.html.erb" > ? ? end > > ? ? it "should render the logged in partial for homepages" do > ? ? ? template.expect_render(:partial => ''shared/subnav/home'', :locals > => {:active => :home}) > ? ? ? do_render > ? ? end > > ? end > > passes if I render the partial directly in the view, > > render :partial => ''shared/subnav/home'', :locals => {:active => :home} > > but it fails if the partial is rendered by a helper; > > module ApplicationHelper > ? def subnav(partial, args={}) > ? ? active = args[:active] || :no_highlight > ? ? if partial == :home > ? ? ? partial = (logged_in? ? ''home'' : ''login'') > ? ? end > ? ? render :partial => "shared/subnav/#{partial}", :locals => {:active > => active} > ? end > end > > Is there any way to check whether the helper renders it? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
David Chelimsky
2008-Aug-14 17:14 UTC
[rspec-users] template.expect_render fails when partial is rendered from a helper
On Fri, Aug 8, 2008 at 3:46 PM, J2M <james2mccarthy at gmail.com> wrote:> My spec; > > describe ''subnav rendering while logged in'' do > > before do > template.stub!(:logged_in?).and_return(true) > template.stub! > (:current_profile).at_least(:once).and_return(mock_profile) > end > > def do_render > render "/homepages/show.html.erb" > end > > it "should render the logged in partial for homepages" do > template.expect_render(:partial => ''shared/subnav/home'', :locals > => {:active => :home}) > do_render > end > > end > > passes if I render the partial directly in the view, > > render :partial => ''shared/subnav/home'', :locals => {:active => :home} > > but it fails if the partial is rendered by a helper; > > module ApplicationHelper > def subnav(partial, args={}) > active = args[:active] || :no_highlight > if partial == :home > partial = (logged_in? ? ''home'' : ''login'') > end > render :partial => "shared/subnav/#{partial}", :locals => {:active > => active} > end > end > > Is there any way to check whether the helper renders it?If the code in the subnav method is resulting in what you are assuming it is, this should work. I''d try putting exactly the same code (with everything hard coded and no conditional logic) in the subnav method and see if you get the same result. If you get an error, please copy the error in your response. Cheers, David