This project is archived and is in readonly mode.
rake default test task does not use the test.rb environment
-
Neeraj Singh
- 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 StartedThis is on ruby 1.8.7
Another way to test would be to add raise 'boom' at the top of your test.rb .
-
Neeraj Singh
I tested with rails edge.
-
Sidu Ponnappa
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
- State changed from invalid to open
-
Jeff Kreeftmeijer
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)
- Assigned user set to Prem Sichanugrist (sikachu)
-
Prem Sichanugrist (sikachu)
- 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 defaultNote 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
testand 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
testand 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 --tracewith 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 thetestenvironment.[~/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 defaultSo, I think this is the expected behavior, as normally
db:abort_if_pending_migrationstask will run every time you runraketo make sure you have migrated yourdevelopmentdatabase. And that task is actually the one that depends onenvironment, which loads the defaultdevelopmentenvironment and output that "Load development" line for you.From your original problem, I think there's some misconfiguration in your
config/environements/test.rbfile 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 :)