开发者

How to replace Rspec's ENV["RAILS_ENV"] ||= 'test' deprecated in Rails 3.0?

I'开发者_StackOverflowm using rails (3.0.4) and rspec-rails (2.5.0). When I runrails generate rspec:install it producesspec_helper.rb` that contains this line:

ENV["RAILS_ENV"] ||= 'test'

When I run rake spec I get this warning on in the terminal:

DEPRECATION WARNING: RAILS_ENV is deprecated. Please use ::Rails.env.

This isn't as annoying since that only runs once inside my Spork.prefork, but I'd like to get past that deprecation if possible. I'm new to Rails and haven't found mention of this in the rspec-rails issues or anywhere else.


Dup of my response in the GitHub issue:

That warning is telling you that the constant RAILS_ENV is deprecated, not the environment variable ENV["RAILS_ENV"]. If you clone the Rails repo and check out the v3.0.4 tag, and search for RAILS_ENV, you'll see that Rails, itself, uses ENV["RAILS_ENV"] in several places.

Must be coming from somewhere else in your app.


Must be new in Rails 3.0.4. This ought to work:

Remove the ENV["RAILS_ENV"] || = 'test' from spec/spec_helper.rb

Look for the require rspec/rails line.

Add ::Rails.env ||= 'test' immediately after it.

It would be a good idea to open an issue on the rspec-rails tracker, as this is going to need changing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜