RSpec view test for render :partial with :locals?

I was working on some rspec views tests and I've noticed that partial renderization can be tricky.

For example, if we have an index page that renders the objects list in a partial template.

In my case I was testing using a 'GivingClub' list:

describe "giving_clubs" do
  before do
    @giving_clubs = [mock_model(GivingClub)]
    assigns[:giving_clubs] = @giving_clubs
  end

  it "expect render giving clubs list" do
    template.expect_render(:partial => "/giving_clubs/list", :locals => { :giving_clubs => @giving_clubs })
    render "/giving_clubs/index"
  end
end

Do not forget the assigns before call template.expect_render. Locals works fine in this way.

Rspec quickref

Hey wanderers

Sorry for all this time frozen, the crew and I have a lot to post about, but our current assignments has kept everyone pretty busy(but that's not an excuse, so let me blow the dust off this blog).

So, just stumbled on Dave Astels (for those of you who don't know the guy, he's one of the responsible for the creation of the rspec behavior driven development framework, I'll post more specifically about it later, but you can find tons of info on the web about it) rspec QuickRef. For those of us who are using rspec a lot, this might come in handy. I know it did for me.

Just a tip this time folks, but I'll try and get some cooler tutorial next time.

Hugs to you all