Skip to content

Loading…

rake spec loads development environment #8591

Closed
RunsFor opened this Issue · 8 comments

4 participants

@RunsFor

Hi. I have some issues with using rspec in rails 3.2.9.
When I run rake spec, seems that it loads a development environment.
RAILS_ENV='test' rake spec solves this problem, but i don't think that it's a right way to do it.
Could somebody help me and give some hints?
I'm new at rails and don't know exactly, which configurations files or maybe command output should be provided.
Appreciate any help. Thanx!

@steveklabnik
Ruby on Rails member

This is exactly how things are supposed to work. If you're having some sort of problem, please ask a question on either the rspec-users on rubyonrails-talk mailing lists. This is not a bug.

@rafaelfranca
Ruby on Rails member
@pixeltrix
Ruby on Rails member

Is this related to the regression on master in #7175 since the commit that caused that is in 3-2-stable as well

@RunsFor

Changing ENV["RAILS_ENV"] ||= 'test' to ENV["RAILS_ENV"] = 'test' in my spec_helper.rb file does not work. Is it ok?

@rafaelfranca
Ruby on Rails member
@RunsFor

Sure. I pushed it here

@rafaelfranca
Ruby on Rails member

Got it, as @steveklabnik said it is expected. When you run any rake/rails command the environment that will be loaded first is the development. When you run rake spec it will load the development environment, so it will load the spec_helper.rb file, and finally it will load the test environment.

Here the debug info that I got running the application

$ rake spec
"Loaded development environment"
/Users/rafaelmfranca/.rbenv/versions/1.9.3-p327/bin/ruby -S rspec ./spec/helpers/main_helper_spec.rb
"Environment before load spec_helper: "
"Loaded test environment"
"Environment after load spec_helper: test"

$ rake db:version
"Loaded development environment"
Current version: 20121223225231

This is one of the reason that rspec-rails recomends you to put the gem in the :test and :development groups in the Gemfile.

@pixeltrix #7175 was fixed in 3.2.8 release.

@RunsFor

it works for me. Thanx! I think I understand it more now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.