Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

`rake test(:functionals|:units|....)` loads the environment twice

#4759

Here's the current flow.

** 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
==> [config/environments/development.rb loads here] <==
** ultrasphinx: configuration file not found for "development" environment
** ultrasphinx: please run 'rake ultrasphinx:configure'
** ultrasphinx: spelling support not available (raspell configuration raised "uninitialized constant Ultrasphinx::Spell::Aspell")
** 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
==> [config/environment.rb loads here] <==
==> [config/environments/test.rb loads here] <==
Loaded suite /home/augustl/.rvm/gems/ruby-1.8.7-p249@global/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
......................................

The data for the bracketed annotations were found by adding puts statements to those files.

This becomes more of a problem the longer the environment takes to load. For example, the rails3 branch of gitorious.org takes 20-25 seconds to load because of the high number of routes (which I will probably file a separate issue for - that's a long time!). Here (and attached) is the output of rake routes. Having to wait about a minute for the tests to start running makes TDD rather tedious.

Reported by August Lilleaas · June 3rd, 2010 @ 04:16 PM

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Daniel Abrahamsson
    Daniel Abrahamsson

    I'm facing the same issue with running my tests, due to the double loading of the environment.What is the reason that the environment is loaded twice?

    December 16th, 2010 @ 11:27 AM

  2. Roger Leite
    Roger Leite

    I tested with rails 3.0.4, created an empty application and scaffold of users.
    With a "puts" in config/environment.rb, i did:

    rake test -t
    (in /home/roger/dev/trivial/temp/raketest) 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 ENV LOADED !
    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 ENV LOADED !
    Loaded suite /home/roger/.rvm/gems/ruby-1.8.7-p330@global/gems/rake-0.8.7/lib/rake/rake_test_loader
    Started
    . Finished in 0.027144 seconds.

    1 tests, 1 assertions, 0 failures, 0 errors
    Invoke test:functionals (first_time) Invoke test:prepare ** Execute test:functionals ENV LOADED !
    Loaded suite /home/roger/.rvm/gems/ruby-1.8.7-p330@global/gems/rake-0.8.7/lib/rake/rake_test_loader
    Started
    ....... Finished in 0.171518 seconds.

    7 tests, 10 assertions, 0 failures, 0 errors
    Invoke test:integration (first_time) Invoke test:prepare ** Execute test:integration

    I tried to test with rails edge too (changing Gemfile to use gem 'rails', :git => 'git://github.com/rails/rails.git'), and i got an error:


    (in /home/roger/dev/trivial/temp/raketest) 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 Invoke test:functionals (first_time) Invoke test:prepare ** Execute test:functionals /home/roger/.rvm/gems/ruby-1.8.7-p330@rails-edge/bundler/gems/rails-8276a240207a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb:23: uninitialized constant Rack::Session::Abstract::SessionHash (NameError)

    {mkd-extraction-a95f96cb27b5f9de47f004b440afe16e}

    Invoke test:integration (first_time) Invoke test:prepare ** Execute test:integration Errors running test:units, test:functionals!

    February 16th, 2011 @ 10:36 AM

  3. Roger Leite
    Roger Leite

    Trying to clean the previous message

    I tested with rails 3.0.4, created an empty application and scaffold of users.
    With a "puts" in config/environment.rb, i did:

    rake test -t

    I tried to test with rails edge too (changing Gemfile to use gem 'rails', :git => 'git://github.com/rails/rails.git'), and i got an error.

    Put the output at gist: https://gist.github.com/829168

    February 16th, 2011 @ 10:43 AM

  4. Roger Leite
    Roger Leite

    Looking at source, i realized two things:
    1. https://github.com/rails/rails/blob/master/railties/lib/rails/appli... Rails, raises exception if application is already initialized.
    2. Task test ( https://github.com/rails/rails/blob/master/railties/lib/rails/test_... ) invokes "test:units test:functionals test:integration". I think they are running in different process.

    Somebody can help me ?

    February 16th, 2011 @ 10:56 AM

  5. Christopher Meiklejohn
    Christopher Meiklejohn

    Hi Roger,

    I'm not running into any problems running the test suite on the rails master branch -- can you try doing this again?

    Thanks,
    Chris

    March 3rd, 2011 @ 04:37 AM

  6. Christopher Meiklejohn
    Christopher Meiklejohn

    Roger,

    Keep in mind if you are running edge rails, you need to be running edge rack as well, which is probably why you are getting the SessionHash error.

    March 3rd, 2011 @ 05:18 AM

  7. Roger Leite
    Roger Leite

    I didn't know about edge rack ...
    Sorry for the false positive.

    Thanks for the tip Christopher! It worked.

    March 3rd, 2011 @ 02:42 PM