[rspec-users] rpsec-rails overwriting RAILS_ENV?

Matt Wynne matt at mattwynne.net
Thu Jan 15 03:58:47 EST 2009

Hi folks,

We have a "features" environment for Rails, where we run the Cucumber  
stuff. This lets us run specs and features in different databases,  
which can be handy.

I think I've found that rspec-rails 1.1.12 is doing something nasty to  
the RAILS_ENV constant to force it to == "test"

Line 1 of vendor/gems/rspec-rails-1.1.12/lib/spec/rails.rb:

     silence_warnings { RAILS_ENV = "test" }

It seem like when I require this gem (which we use in the features  
env) it's clobbering my environment setting.

I've noticed this problem running a rake task:

     rake db:create RAILS_ENV=features

Where RAILS_ENV was changing back to "test" before the rake task ran!  
and it's definitely happening in spec/rails.

What was the intention behind making it so forceful? Would it be OK to  
make it do something more like the following:

     RAILS_ENV ||= "test"

Shouldn't we be leaving it up to rails to set this constant anyway?


Matt Wynne

More information about the rspec-users mailing list