Skip to content

Commit b913f6a

Browse files
committed
Prevent running in production mode by default.
Many setups start tests by truncating the database tables. Running the specs in production would, horribly, would delete all of the data. This checks to make sure Rails is not in production before loading rspec-rails and the configuration. If production mode is detected the run will abort immediately. Resolve #1382
1 parent 57d26eb commit b913f6a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/generators/rspec/install/templates/spec/rails_helper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# This file is copied to spec/ when you run 'rails generate rspec:install'
22
ENV['RAILS_ENV'] ||= 'test'
3-
require 'spec_helper'
43
require File.expand_path('../../config/environment', __FILE__)
4+
# Prevent database truncation if the environment is production
5+
abort("The Rails environment is running in production mode!") if Rails.env.production?
6+
require 'spec_helper'
57
require 'rspec/rails'
68
# Add additional requires below this line. Rails is not loaded until this point!
79

0 commit comments

Comments
 (0)