[rspec-users] template.expect_render fails when partial is rendered from a helper

David Chelimsky dchelimsky at gmail.com
Thu Aug 14 13:14:33 EDT 2008


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


More information about the rspec-users mailing list