rake spec loads development environment #8591

Closed
RunsFor opened this Issue Dec 23, 2012 · 8 comments

Comments

Projects
None yet
4 participants
@RunsFor

RunsFor commented Dec 23, 2012

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

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Dec 23, 2012

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.

Member

steveklabnik commented Dec 23, 2012

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

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Dec 23, 2012

Member

It seems like a bug for me

Member

rafaelfranca commented Dec 23, 2012

It seems like a bug for me

@pixeltrix

This comment has been minimized.

Show comment
Hide comment
@pixeltrix

pixeltrix Dec 23, 2012

Member

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

Member

pixeltrix commented Dec 23, 2012

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

@RunsFor

This comment has been minimized.

Show comment
Hide comment
@RunsFor

RunsFor Dec 23, 2012

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

RunsFor commented Dec 23, 2012

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

@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Dec 23, 2012

Member

If this doesn't work so maybe something else is adding this behavior. Could
you create a sample application reproducing the issue?

Member

rafaelfranca commented Dec 23, 2012

If this doesn't work so maybe something else is adding this behavior. Could
you create a sample application reproducing the issue?

@RunsFor

This comment has been minimized.

Show comment
Hide comment
@RunsFor

RunsFor Dec 23, 2012

Sure. I pushed it here

RunsFor commented Dec 23, 2012

Sure. I pushed it here

@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Dec 23, 2012

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.

Member

rafaelfranca commented Dec 23, 2012

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

This comment has been minimized.

Show comment
Hide comment
@RunsFor

RunsFor Dec 24, 2012

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

RunsFor commented Dec 24, 2012

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