This project is archived and is in readonly mode.
rake test runs initializers in development environment
Reported by Gaius Centus Novus | June 19th, 2009 @ 06:41 PM | in 3.x
To reproduce:
- create a fresh Rails app (
rails temp
) - run
rake db:migrate
to generate an emptydb/schema.rb
- add
raise "in development mode!"
to the bottom ofconfig/environments/development.rb
-
run
rake test
(or justrake
); the error is raised:Invoke test (first_time) Execute test Invoke test:units (first_time) Invoke db:test:prepare (first_time) Invoke db:abort_if_pending_migrations (first_time) Invoke environment (first_time) Execute environment Invoke test:functionals (first_time) Invoke db:test:prepare Execute test:functionals /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:test" "/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb"
Invoke test:integration (first_time) Invoke db:test:prepare ** Execute test:integration /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:test" "/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb"
Errors running test:units!
Alternatively, if you just run rake test:units
:
** Invoke test:units (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
in development mode!
/private/tmp/test/config/environments/development.rb:19:in `load_environment'
My environment:
ruby --version
ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
gem list rails
rails (2.3.2, 1.2.6)
Comments and changes to this ticket
-
Andy Atkinson June 22nd, 2009 @ 07:18 AM
Would you mind describing how this is a problem in your application? If I saw this personally, I wouldn't think it is a Rails bug necessarily, perhaps I'm missing something about initializers.
-
Carsten Gehling June 22nd, 2009 @ 09:56 AM
It is a problem, if you try to test a Mailer. Since config/environments/development.rb is run instead of config/environments/test.rb, you do not get config.action_mailer.delivery_method = :test set
This again means, that when your test-suite sends a mail, ActionMailer::Base.deliveries is not updated, so your tests will fail.
-
Gaius Centus Novus June 22nd, 2009 @ 12:33 PM
I ran into it when I had done a
config.middleware.use
in myconfig/development.rb
that I expected not to be run in test mode. -
Mat Schaffer October 31st, 2009 @ 01:05 AM
I ran into this same problem trying to set up Workling in an initializer, but I couldn't select the appropriate dispatcher for testing.
As a work around I added this to my rspec.rake. I expect you could use a similar strategy for test:unit. I'll probably have to figure that out shortly too.
spec_prereq = [:set_rails_env, File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop] task :set_rails_env do ENV['RAILS_ENV'] = 'test' end
This doesn't suppress the evaluation of development.rb, sadly. But at least I can put some if statements in my initializer to do the right thing.
-
Kamal Fariz November 11th, 2009 @ 03:06 PM
- Tag changed from 2.3.2, development.rb, evironment, test, testunit to 2.3.2, 2.3.4, development.rb, evironment, test, testunit
Confirmed on rails 2.3.4
-
Rohit Arondekar October 9th, 2010 @ 04:03 AM
- State changed from new to stale
- Importance changed from to
Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.
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>