This project is archived and is in readonly mode.
rake default test task does not use the test.rb environment
Reported by Sidu Ponnappa | September 8th, 2010 @ 10:13 AM
Tested on ruby 1.8.7 and 1.9.2 with Rails 3.0.0 on OSX
10.6.4
To replicate:
> rails new Dummy
> cd Dummy
> rake db:migrate
- Edit config/environments/development.rb and add
puts 'Loading development'
to it. - Edit config/environments/test.rb and add
puts 'Loading test'
to it. > rake --trace
The outputs looks like this (note that 'Loading test' is never
printed):
~/Work/Dummy λ rake --trace
(in /Users/sidu/Work/Dummy)
Invoke default (first_time)
Invoke test (first_time)
Execute test
Invoke test:units (first_time)
Invoke test:prepare (first_time)
Invoke db:test:prepare (first_time)
Invoke db:abort_if_pending_migrations (first_time)
Invoke environment (first_time)
Execute environment
Loading development
Execute db:abort_if_pending_migrations
Execute db:test:prepare
Invoke db:test:load (first_time)
Invoke db:test:purge (first_time)
Invoke environment
Execute db:test:purge
Execute db:test:load
Invoke db:schema:load (first_time)
Invoke environment
Execute db:schema:load
Execute test:prepare
Execute test:units
Invoke test:functionals (first_time)
Invoke test:prepare
Execute test:functionals
Invoke test:integration (first_time)
Invoke test:prepare
Execute test:integration
Execute default
Comments and changes to this ticket
-
Neeraj Singh September 8th, 2010 @ 11:28 AM
- State changed from new to invalid
- Importance changed from to Low
You don't need to run with trace. I am getting the right result.
$ rake (in /Users/nsingh/dev/rails_tickets/r3_5580) Loading test /Users/nsingh/dev/rails_tickets/r3_5580/config/routes.rb:1: warning: multiple values for a block parameter (0 for 1) from /Users/nsingh/dev/rails_tickets/r3_5580/vendor/rails/actionpack/lib/action_dispatch/routing/route_set.rb:231 Loaded suite /Users/nsingh/.rvm/gems/ree-1.8.7-2010.01/gems/rake-0.8.7/lib/rake/rake_test_loader Started . Finished in 0.007541 seconds. 1 tests, 1 assertions, 0 failures, 0 errors Loading test /Users/nsingh/dev/rails_tickets/r3_5580/config/routes.rb:1: warning: multiple values for a block parameter (0 for 1) from /Users/nsingh/dev/rails_tickets/r3_5580/vendor/rails/actionpack/lib/action_dispatch/routing/route_set.rb:231 Loaded suite /Users/nsingh/.rvm/gems/ree-1.8.7-2010.01/gems/rake-0.8.7/lib/rake/rake_test_loader Started ....... Finished in 0.120012 seconds. 7 tests, 10 assertions, 0 failures, 0 errors Loaded suite /Users/nsingh/.rvm/gems/ree-1.8.7-2010.01/bin/rake Started
This is on ruby 1.8.7
Another way to test would be to add raise 'boom' at the top of your test.rb .
-
Sidu Ponnappa September 8th, 2010 @ 11:39 AM
I didn't create any tests as part of the setup. Try it without any tests and it breaks as I've described. This matters when using RSpec, because there won't be any Test::Unit tests, but there are Rspec specs being run - and none of my test environment specific config loads.
-
Neeraj Singh September 8th, 2010 @ 01:17 PM
- State changed from invalid to open
-
Jeff Kreeftmeijer September 9th, 2010 @ 08:18 PM
I followed Sidu's steps and was able to reproduce the problem:
$ rake --trace (in /Users/jeff/rails/apps/rake_test_env) ** Invoke default (first_time) ** Invoke test (first_time) ** Execute test ** Invoke test:units (first_time) ** Invoke test:prepare (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment (first_time) ** Execute environment Loading development ** Execute db:abort_if_pending_migrations ** Execute db:test:prepare ** Invoke db:test:load (first_time) ** Invoke db:test:purge (first_time) ** Invoke environment ** Execute db:test:purge ** Execute db:test:load ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load ** Execute test:prepare ** Execute test:units ** Invoke test:functionals (first_time) ** Invoke test:prepare ** Execute test:functionals ** Invoke test:integration (first_time) ** Invoke test:prepare ** Execute test:integration ** Execute default
-
Prem Sichanugrist (sikachu) September 10th, 2010 @ 02:16 PM
- Assigned user set to Prem Sichanugrist (sikachu)
-
Prem Sichanugrist (sikachu) September 12th, 2010 @ 10:02 AM
- State changed from open to invalid
I've tried to reproduce your problem, and I can confirm that there's no "Loading test" output when I have no test case in
test/*
. However, when I add a unit test then I got this output:[master][~/Projects/test_edge] rake --trace (in /Users/sikachu/Projects/test_edge) ** Invoke default (first_time) ** Invoke test (first_time) ** Execute test ** Invoke test:units (first_time) ** Invoke test:prepare (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment (first_time) ** Execute environment >> Loading development ** Execute db:abort_if_pending_migrations ** Execute db:test:prepare ** Invoke db:test:load (first_time) ** Invoke db:test:purge (first_time) ** Invoke environment ** Execute db:test:purge ** Execute db:test:load ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load ** Execute test:prepare ** Execute test:units >> Loading test Loaded suite /Users/sikachu/.rvm/gems/ruby-1.8.7-p302@rails3/gems/rake-0.8.7/lib/rake/rake_test_loader Started . Finished in 0.022144 seconds. 1 tests, 1 assertions, 0 failures, 0 errors ** Invoke test:functionals (first_time) ** Invoke test:prepare ** Execute test:functionals ** Invoke test:integration (first_time) ** Invoke test:prepare ** Execute test:integration ** Execute default
Note that you'll see both "Loading development" and "Loading test" in my output. But why?
Turns out that when Rails staring the test, it actually change the environment to
test
and then execute another Ruby process to load new environment. You can see that intest/test_helper.rb
**test/test_helper.rb** ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help'
You said that you're using RSpec, and I think RSpec is doing the same thing by changing environment to
test
and then execute another Ruby process to load new environment. It does that intest/spec_helper.rb
**spec/spec_helper.rb** # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails'
And yet when I run
rake --trace
with rspec installed, you can see that it has almost the same output as test_unit. Also, you could see that it creating another Ruby process before loading thetest
environment.[~/Projects/test_rspec] rake --trace (in /Users/sikachu/Projects/test_rspec) ** Invoke default (first_time) ** Invoke spec (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment (first_time) ** Execute environment >> Loading development ** Execute db:abort_if_pending_migrations ** Execute db:test:prepare ** Invoke db:test:load (first_time) ** Invoke db:test:purge (first_time) ** Invoke environment ** Execute db:test:purge ** Execute db:test:load ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load ** Execute spec /Users/sikachu/.rvm/rubies/ruby-1.8.7-p302/bin/ruby -S bundle exec /Users/sikachu/.rvm/rubies/ruby-1.8.7-p302/bin/ruby -Ilib -Ispec "./spec/models/user_spec.rb" >> Loading test . Finished in 0.01218 seconds 1 example, 0 failures ** Execute default
So, I think this is the expected behavior, as normally
db:abort_if_pending_migrations
task will run every time you runrake
to make sure you have migrated yourdevelopment
database. And that task is actually the one that depends onenvironment
, which loads the defaultdevelopment
environment and output that "Load development" line for you.From your original problem, I think there's some misconfiguration in your
config/environements/test.rb
file which causes RSpec not load the configuration.I'm marking this as invalid again, as I think this is the expected behavior and I think my examples are clear :)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>