Skip to content

RAILS_ENV gets set to 'development' (not 'test') when running rake spec #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joehorsnell opened this issue Aug 1, 2012 · 2 comments
Closed

Comments

@joehorsnell
Copy link

Hi,

When running "rake spec" with a Rails 3.2.7 app and RSpec 2.11.0, Rails.env is getting set to 'development', rather than defaulting to 'test'. The spec_helper has the ENV["RAILS_ENV"] ||= 'test' line right at the top (as generated by "rails g rspec:install") but it's too late at that point, that environment variable has already been set.

I will zip and attach (if possible) a sample Rails app to recreate the issue, but a bit of debugging shows that the RAILS_ENV environment variable is being set from the following before spec_helper is loaded:

Setting RAILS_ENV = development
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/tasks/misc.rake:4:in block in <top (required)>' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:205:incall'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:205:in block in execute' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:200:ineach'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:200:in execute' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:158:inblock in invoke_with_call_chain'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:151:ininvoke_with_call_chain'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:176:in block in invoke_prerequisites' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:174:ineach'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:174:in invoke_prerequisites' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:157:inblock in invoke_with_call_chain'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:151:ininvoke_with_call_chain'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:176:in block in invoke_prerequisites' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:174:ineach'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:174:in invoke_prerequisites' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:157:inblock in invoke_with_call_chain'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:151:ininvoke_with_call_chain'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:176:in block in invoke_prerequisites' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:174:ineach'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:174:in invoke_prerequisites' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:157:inblock in invoke_with_call_chain'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:151:ininvoke_with_call_chain'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:176:in block in invoke_prerequisites' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:174:ineach'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:174:in invoke_prerequisites' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:157:inblock in invoke_with_call_chain'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:151:ininvoke_with_call_chain'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/task.rb:144:in invoke' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/application.rb:116:ininvoke_task'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/application.rb:94:in block (2 levels) in top_level' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/application.rb:94:ineach'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/application.rb:94:in block in top_level' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/application.rb:133:instandard_exception_handling'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/application.rb:88:in top_level' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/application.rb:66:inblock in run'
/Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/application.rb:133:in standard_exception_handling' /Users/joe/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rake/application.rb:63:inrun'
/Users/joe/.rbenv/versions/1.9.3-p194/bin/rake:32:in `

'
/Users/joe/.rbenv/versions/1.9.3-p194/bin/ruby -S rspec ./spec/rspec_test_env_spec.rb

Cheers,

Joe.

@alindeman
Copy link
Contributor

This is an issue with Rails 3.2.7. Hopefully 3.2.8 will be released soon: rails/rails#7175

@joehorsnell
Copy link
Author

Fantastic - thanks very much for the quick response.

rodrigobdz added a commit to rodrigobdz/rspec-rails that referenced this issue Jan 22, 2018
This is a solution to tests running in development environment as stated in issues rspec#70 and rspec#586.
Before Rails 3.2.7 ENV['RAILS_ENV'] ||= 'test' ran tests without issues in test env as discussed in rails/rails#7175 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants