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
plugin.
Let me break it down:
-
I define a mix in my engine under lib/my_engine/foo.rb. We’ll call
the mixin MyEngine::Foo. -
I then put the following in my application controller to apply the
mixin to all controllers:
class ApplicationController < ActionController::Base
include MyEngine::Foo
end
-
Running this program seems to work fine
-
When I run my testing it cannot seem to find the module MyEngine::Foo
I have traced the problem to the following:
- My test_helper.rb in my engine has the following for the first line:
require File.expand_path(File.join(File.dirname(FILE),
‘/…/…/…/…/test/test_helper’))
as suggested by the documentation.
-
This requires the environment which of course starts the process of
booting Rails. -
When loading the “engine” plugin is loading it requires the testing
extensions. -
The testing extensions require ‘test_help’ provided by Rails.
-
‘test_help’ in requires ‘application’. This loads my
ApplicationController class. -
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.
Workarounds:
- Make the “engines” plugin load after the problem plugin
- Comment out the “require ‘test_help’”. It is not necessary anyway
since the test_helper generated by rails requires it later.