Read more

Enabling view rendering for controller specs

Arne Hartherz
January 19, 2012Software engineer at makandra GmbH

Views are normally (for good reason) not rendered in controller specs. If you need it to happen, use:

RSpec 1 (Rails 2):

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

integrate_views Show archive.org snapshot

RSpec 2 (Rails 3):

render_views Show archive.org snapshot

Note that you can't use that inside it blocks but need to put it in the nesting example group, like this:

    describe '#update' do
      context 'when rendering views' do
        
        integrate_views
        
        it 'should not fail' do
          # This will detect errors that happen during view rendering as well:
          expect { put :update, :id => 23 }.to_not raise_error
        end

      end
    end

Wrap spec examples into their own "rendering" context so you don't render views for other specs that don't need it to happen.

Posted by Arne Hartherz to makandra dev (2012-01-19 12:51)