Skip to content

Instantly share code, notes, and snippets.

@martinsvalin
Created March 30, 2012 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinsvalin/2249825 to your computer and use it in GitHub Desktop.
Save martinsvalin/2249825 to your computer and use it in GitHub Desktop.
Steps to reproduce bug in rspec-rails

Steps to reproduce bug in rspec-rails.

When render_views is enabled globally, it cannot be disabled with a local render_views(false) call.

Create rails project with rspec-rails, a simple controller with one action

rails new reproduce_bug
cd reproduce_bug
echo 'gem "rspec-rails"' >> Gemfile
bundle
rails g rspec:install
rails g controller bugs show

Configure RSpec to enable render_views globally, but disable for the show-action spec.

Edit spec/spec_helper.rb, add config.render_views inside the RSpec.configure block.

Edit spec/controllers/bugs_controller_spec.rb, add render_views false inside describe "GET 'show'" block.

Make the view blow up.

Edit app/views/bugs/show.html.erb, add <% raise "It's a trap!" %>

Watch the show-action spec fail

rspec spec/controllers/bugs_controller_spec.rb

1) BugsController GET 'show' returns http success
   Failure/Error: get 'show'
   ActionView::Template::Error:
     It's a trap!
require 'spec_helper'
describe BugsController do
describe "GET 'show'" do
render_views false
it "returns http success" do
get 'show'
response.should be_success
end
end
end
<% raise "It's a trap!" %>
<h1>Bugs#show</h1>
<p>Find me in app/views/bugs/show.html.erb</p>
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
RSpec.configure do |config|
config.render_views
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment