This project is archived and is in readonly mode.

#2691 ✓stale
Brad Sumersford

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

Reported by Brad Sumersford | May 21st, 2009 @ 06:57 PM | in 3.x

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.

Comments and changes to this ticket

  • Chris Jones

    Chris Jones January 20th, 2010 @ 04:43 AM

    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.)

  • 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:12 AM

    • Importance changed from “” to “”

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

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:58 PM

    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:58 PM

    • State changed from “open” to “stale”

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