Forum: RSpec rpsec-rails overwriting RAILS_ENV?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Matt W. (Guest)
on 2009-01-15 11:00
(Received via mailing list)
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?

cheers,
Matt

Matt W.
http://blog.mattwynne.net
http://www.songkick.com
David C. (Guest)
on 2009-01-15 16:56
(Received via mailing list)
On Thu, Jan 15, 2009 at 2:58 AM, Matt W. <removed_email_address@domain.invalid> 
wrote:
>
>    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.

Change require 'spec' to require 'spec/expectations' and you'll be ok.

>
> 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?

That was 2 years ago - I don't remember the motivation.

> 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?

As long as it works, that's fine :) Please enter a lighthouse ticket for
this.

Thanks,
David
This topic is locked and can not be replied to.