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.

Gem Plugin does not load rails/init.rb when config.gem is placed in development.rb

#2691

When adding development only gems like 'faker' I place them in the development.rb configuration and all works as advertised.

Unfortunately, if the gem is dependent on plugin functionality, fiveruns_tuneup for example, the rails/init.rb in the gem plugin only fires when the config.gem entry is put in the main environment.rb and not in any of the environment specific configurations.

This is due to the Rails Initializer calling add_plugin_load_paths before it calls load_environment. The add_plugin_load_paths method will load all the plugins (and call rails/init.rb if available) and cache them, unfortunately before the environment specific configuration gets a chance to load any gems it may need.

If this is intentional, it's not very intuitive as the config.gem declarations do work in the environment specific configuration, just not completely.

Reported by Brad Sumersford · May 21st, 2009 @ 06:57 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Chris Jones
    Chris Jones

    I can confirm this issue in Rails 2.3.5. Here are steps to reproduce:

    Add the following to config/test.rb:

    config.gem "webrat"
    config.gem "contest"
    config.gem "stories"
    

    Generate a new integration test and add the following in the test class:

    story "Show that the bug is valid" do
      scenario "With webrat" do
        visit "/"
      end
    end
    

    Install gems with rake gems:install and then rake test:integration. The test will fail:

    Started
    E
    Finished in 0.051676 seconds.
    
      1) Error:
    test_With_webrat(SignUpTest::TestShowThatTheBugIsValid):
    NoMethodError: undefined method `visit' for #<SignUpTest::TestShowThatTheBugIsValid:0x102288180>
        /test/integration/sign_up_test.rb:8:in `test_With_webrat'
    
    1 tests, 0 assertions, 0 failures, 1 errors
    

    It fails because the code in rails/init.rb in the Stories gem is not executed.

    Note that configuring the gem dependencies in config/environment.rb, like Brad says, works as expected. (Also note that you can wrap those same dependencies with if RAILS_ENV == "test" to load them only in the test environment.)

    January 20th, 2010 @ 04:43 AM

  2. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  3. Rohit Arondekar
    Rohit Arondekar
    • Importance changed from to

    Any updates here? This is still an issue on latest 2.x or 3.x releases?

    October 9th, 2010 @ 04:12 AM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:58 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:58 PM