[rspec-users] rspec-rails render_views doesn't render layouts? / how to check flash isn't rendered

nruth nick.rutherford at gmail.com
Sun Aug 28 09:57:38 EDT 2011


I'm trying to test that "static" pages (they're ERB, but get cached), 
generated through rails, don't render any stray flash notices left over by 
the authentication system (Devise) or wherever else.

I've tried writing this controller spec, but it appears that response.body 
only renders the template, not its layouts?

  describe "so that static caching can be used" do
    render_views
    specify "flash notices are not rendered" do
      flash[:notice] = "flash boo"
      flash[:error] = "flash boo"
      flash[:alert] = "flash boo"
      get :show, :page => 'privacy_policy'
      response.body.should have_content('flash boo')
    end
  end

class StaticPagesController < ApplicationController
  layout 'master'

  def show
    response.headers['Cache-Control'] = "public, max-age=#{6.hours}"
    render "static_pages/#{params[:page]}"
  end
end


I've tried changing to a layout which does render flash notices, and even 
inserting the text into the layout template, but can't make the spec fail. 
Is there a way to ask rspec to render the template with the appropriate 
layouts as well?

Is a controller spec the wrong way to try and do this? 
It seems out of place, as it's more to do with which layouts are being used, 
and their contents, but the rendering process starts at the controller, it 
receives the result, and I can manipulate the flash hash contents before 
rendering.

Versions:
rails (3.0.10)
rspec-rails (2.6.1)
rspec-core (2.6.4)

I've also posted on stackoverflow @ 
http://stackoverflow.com/questions/7221388/rspec-render-views-ignores-layouts-want-to-test-static-cached-page-does-not-disp 

Thanks, Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110828/cf42b7d8/attachment.html>


More information about the rspec-users mailing list