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 Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)