# RAILS\_ENV changes to test after init

**URL:** <https://www.ruby-forum.com/t/rails-env-changes-to-test-after-init/155313>\
**Category:** Rails\
**Created:** [December 10, 2008, 2:40pm UTC](https://www.ruby-forum.com/t/rails-env-changes-to-test-after-init/155313 "2008-12-10T14:40:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nik\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ee59a6/32.png) [@Nik\_B](https://www.ruby-forum.com/u/Nik_B)\
**Post date:** [December 10, 2008, 2:40pm UTC](https://www.ruby-forum.com/t/rails-env-changes-to-test-after-init/155313/1 "2008-12-10T14:40:23Z")

</div>

I think RAILS\_ENV is getting set incorrectly, but I don’t know exactly  
how to find out where.

At the bottom of Rails::Initializer.run do |config| in environment.rb,  
RAILS\_ENV is the correct value (staging, development, production,  
etc).

Just below the initializer block, RAILS\_ENV has changed to ‘test’.

Any ideas?

---

<div class="post-metadata">

**Author:** ![Nik\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ee59a6/32.png) [@Nik\_B](https://www.ruby-forum.com/u/Nik_B)\
**Post date:** [December 10, 2008, 3:57pm UTC](https://www.ruby-forum.com/t/rails-env-changes-to-test-after-init/155313/2 "2008-12-10T15:57:59Z")

</div>

Turns out it was happening when rpsec-rails was being loaded.  
Conditional loading for the test environment solved this:

config.gem ‘rspec-rails’, :lib =\> ‘spec/rails’, :version =\> ‘1.1.11’  
if RAILS\_ENV == ‘test’
