This project is archived and is in readonly mode.

#2819 ✓stale
Gaius Centus Novus

rake test runs initializers in development environment

Reported by Gaius Centus Novus | June 19th, 2009 @ 06:41 PM | in 3.x

To reproduce:

  1. create a fresh Rails app (rails temp)
  2. run rake db:migrate to generate an empty db/schema.rb
  3. add raise "in development mode!" to the bottom of config/environments/development.rb
  4. run rake test (or just rake); 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

  • Carsten Gehling

    Carsten Gehling June 20th, 2009 @ 01:29 PM

    Confirmed on rails 2.2.2

  • Andy Atkinson

    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

    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

    Gaius Centus Novus June 22nd, 2009 @ 12:33 PM

    I ran into it when I had done a config.middleware.use in my config/development.rb that I expected not to be run in test mode.

  • Mat Schaffer

    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

    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

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Rohit Arondekar

    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.

  • bingbing

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>

Pages