Testing HighVoltage pages

I’m upgrading an old site of mine and decided to use HighVoltage for the static pages on the site. This is what I started with, and it fails at the “to have_content” because response.body is empty…

describe PagesController do
  it "links to FAQ page" do
    http_login_with_credentials
    get :show, id: 'FAQ'
    expect(response.status).to eq 200 
    puts "#{response.inspect}"
    expect(response.body).to have_content('Frequently Asked Questions')  # Fail
    expect(response.body).to have_css 'a[href="/secrets"]', :text => 'mylist'
  end
end

Why is that? I’d like to understand so that I don’t waste a bunch more time with a flawed test.

I did get a different set of tests running which work and cover what I need, I think:

describe PagesController, '#show' do
  %w{about FAQ changes}.each do |page|
    context 'on GET to /pages/#{page}' do
      before do
        get :show, :id => page
      end 
      it { should respond_with :success }
      it { should render_template(page) }
    end 
  end 
end

What do you think of this test… adequate/sufficient?

Thanks mcuh…

I think you shouldn’t be testing functionality in a library that is already covered by tests. If you want to make sure that your HighVoltage pages are working and associated with the proper URLs, a better and lighter approach would be to have integration tests that visit the url/path and confirm that some title or other distinctive text is present on the page.

I can’t tell from your code snippet, but I think your first test is failing because it’s in spec/controllers and not spec/integration or spec/acceptance, and therefore views aren’t loaded. Controller tests don’t load render views by default (they merely check that the proper template file exists in the filesystem).

If you do want to render the views, you can do so with the render_views method. There’s some relish documentation here: render_views - Controller specs - RSpec Rails - RSpec - Relish

Thanks, Geoff… makes sense. I wasn’t explicitly testing the library; I just wanted to make sure I was using it correctly, so I’ll refactor as you suggest.