[rspec-users] rpsec-rails overwriting RAILS_ENV?

David Chelimsky dchelimsky at gmail.com
Thu Jan 15 09:47:20 EST 2009


On Thu, Jan 15, 2009 at 2:58 AM, Matt Wynne <matt at mattwynne.net> wrote:
> 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.

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

>
> cheers,
> Matt
>
> Matt Wynne
> http://blog.mattwynne.net
> http://www.songkick.com


More information about the rspec-users mailing list