[rspec-users] [rspec-rails] rspec-rails forcing test environment?

Balint Erdi balint.erdi at gmail.com
Fri Jul 31 04:57:37 EDT 2009


Hi,

I realized that requiring rspec-rails somehow sets RAILS_ENV to
'test'. My experimental environment.rb file is the following:

puts "XXX RAILS_ENV: #{RAILS_ENV}"

Rails::Initializer.run do |config|
  (...)
  config.gem "rspec", :version => ">= 1.2.8", :lib => 'spec'
  config.gem "rspec-rails", :version => ">= 1.2.7.1", :lib => 'spec/
rails' # (1)
  (...)
end

puts "XXX RAILS_ENV: #{RAILS_ENV}"

When I run the server (./script/server), I see:

XXX RAILS_ENV: development
XXX RAILS_ENV: test

If I comment out the rspec-rails inclusion line (1), then the
RAILS_ENV remains 'development' after the config block. That's causing
me a problem because "in the real app" I set up a CouchDB database
depending on RAILS_ENV after the block.

One possible workaround is to put the rspec and rspec-rails lines into
the environment file for the test env. (test.rb), but that seems to
defeat the goal of having all dependencies in one place so that it is
clear and gem-related rake tasks can be conveniently run. (I am using
rails 2.3.2, rspec 1.2.8, rspec-rails 1.2.7.1)

Do you know of a better workaround or a real solution for the problem?

Thank you,
Balint


More information about the rspec-users mailing list