tags:

views:

262

answers:

1

Hi All,

I am writing specs for View, that has a menu (which is in a partial) rendered in layout. I want to write specs for selected menu. Here is the code

it "should have User Administration link" do
    template.stub!(:render).and_return(:partial => "layouts/admin/menu")
    do_render
    #render :partial => "layouts/admin/menu" #do
    response.should have_tag('div.menu1')
    response.should have_tag('ul') do
      response.should have_tag('li')do
        with_tag("a[href=?]", admin_users_path)
      end
    end
  end

This spec is failing. I am not getting right way to write specs for partials, I have tried with: template.should_receive(:render).with(:partial => "/layout/admin/menu") too.

Thanks and regards, Pravin.

A: 

I don't think this line:

template.stub!(:render).and_return(:partial => "layouts/admin/menu")

is doing what you think it's doing. RSpec is not going to call template.render :partial => "layouts/admin/menu". It's just going to stub out render and return {:partial => "layouts/admin/menu"} when render is called.

Why stub render at all? You want the view to actually render so the response body has that data you want to test, unless I'm missing something, which I may be. : )

Dave Sims