[Engine Testing] Dependency issue with ApplicationController

I seem to be having a dependency issue when running my test while
applying a mixin implemented by an engine into my Application
controller. I found a work around but wanted to post the problem, cause
and workarounds in hope that a solution can be put into the Engines

Let me break it down:

  1. I define a mix in my engine under lib/my_engine/foo.rb. We’ll call
    the mixin MyEngine::Foo.

  2. I then put the following in my application controller to apply the
    mixin to all controllers:

class ApplicationController < ActionController::Base
include MyEngine::Foo

  1. Running this program seems to work fine

  2. When I run my testing it cannot seem to find the module MyEngine::Foo

I have traced the problem to the following:

  1. My test_helper.rb in my engine has the following for the first line:

require File.expand_path(File.join(File.dirname(FILE),

as suggested by the documentation.

  1. This requires the environment which of course starts the process of
    booting Rails.

  2. When loading the “engine” plugin is loading it requires the testing

  3. The testing extensions require ‘test_help’ provided by Rails.

  4. ‘test_help’ in requires ‘application’. This loads my
    ApplicationController class.

  5. My ApplicationController tries to include my mixin but it cannot find
    the module because my engine has not initialized yet (since it comes
    after the engine plugin alphabetically). Hence leading to my problem.


  1. Make the “engines” plugin load after the problem plugin
  2. Comment out the “require ‘test_help’”. It is not necessary anyway
    since the test_helper generated by rails requires it later.

Tom W. recently committed this change to the 1.2 release branch,
which can be grabbed from


… which means it’ll be in the next release.



Excellent! Thanks Tom!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs