Testing the view in Rspec is just great. It allows you to test the view in total isolation. It just does the render. Make sure you set up some data that is needed, and then check if all areas are available for instance.

Now for Rspec2 a lot of things have changed:

  • have_tag is no longer supported: use have_selector from webrat instead
  • response is deprecated, use rendered instead
  • the assignment has changed, write assign(:events, [stub_model(Event)]) instead of using the old assigns[:events]=[ ...] notation

Let me show you a full example, because that always makes things clearer:

require 'spec_helper'

DUMMY_NUMBER="dummy number"
DUMMY_MESSAGE="dummy message"

describe "envelopes/index.html.haml" do
  before (:each) do
    envelope = mock_model(Envelope)
    envelope.should_receive(:destination).and_return(DUMMY_NUMBER)
    envelope.should_receive(:message).and_return(DUMMY_MESSAGE)
    assign(:envelopes, [envelope])
    render
  end

  it ("has a h1")  { rendered.should have_selector('h1')}
  it ("shows the correct title") { rendered.should contain(t('envelopes.list.title')) }
  it ("have a table-grid") { rendered.should have_selector('.grid') }
  it ("shows the destination") { rendered.should contain(DUMMY_NUMBER) }
  it ("shows the message") { rendered.should contain(DUMMY_MESSAGE) }
end