public
Created

Steps to reproduce bug in rspec-rails

  • Download Gist
a_bug_report.md
Markdown

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!
bugs_controller_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13
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
show.html.erb
HTML+ERB
1 2 3
<% raise "It's a trap!" %>
<h1>Bugs#show</h1>
<p>Find me in app/views/bugs/show.html.erb</p>
spec_helper.rb
Ruby
1 2 3 4 5 6 7 8 9
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.