How to configure RSPEC to never work on RAILS_ENV

I was trying to run some test due to the changes I made ... so I ran RAILS_ENV=production bundle exec rspec

which was very stupid as the rspec (tests) were set to truncate all tables and that was exactly what happened in PRODUCTION !! and you can imagine the consequences

Is there a way to configure rspec to never run when RAILS_ENV = production, so this can never happen to anyone.

What other tips or recommendations can be applied to prevent similar errors.

UPDATE: I created an ISSUE for the rspec-rails command and they just committed a change that fixes this issue https://github.com/rspec/rspec-rails/pull/1383/files

+3


source to share


2 answers


In your spec_helper.rb

before appointment RAILS_ENV

:



raise "Not in test" unless ENV['RAILS_ENV'] == "test"

      

+3


source


In yours Gemfile

refer to any test (for example, rspec-rails

or rspec

) in the group for environments development

and test

only , not toplevel, for example:

group :development, :test do
  gem 'rspec-rails', '~> 3.0'
end

      



Then bonding without developing and testing the gems on your production machine. Without the gem, the rspec

tests would not have run. Add a switch --without

on deployment:

bundle install --without development test

      

+5


source







All Articles