I’m working on an engine that extends ActionController::Base like this
module MyEngine
class Engine < Rails::Engine
config.after_initialize do
ActionController::Base.class_eval do
include MyEngine::ControllerExtension
end
end
end
end
This works in the development environment (rails server). It does not
work for specs. No matter if I run rake spec or rspec spec/some_spec.rb.
rake spec indirectly loads the application through this line in Rakefile
require File.expand_path(‘…/config/application’, FILE)
in the normal course of rake initialization. During this,
ActionController::Base is loaded and the #after_initialize callback of
MyEngine is called.
Then, when a spec is loaded, that in turn loads spec/spec_helper.rb,
containing this line
require File.dirname(FILE) + “/…/config/environment” unless
defined?(Rails)
Which causes, among other things, a reload of ActionController::Base,
but this time the engine callback is not executed. Thus, the specs
blow up as soon as they run into a method defined in the engine. But,
wait, why is that require executed at all? Isn’t Rails defined at that
point? Apparently it is not and I have no idea why.
rspec spec/some_spec.rb is slightly different. Here
ActionController::Base is loaded just once, but the engine callback is
not executed.
rspec and associated gems are 2.0.0.beta.15
rails is 3.0.0.beta4
I’m stumped.
Michael
–
Michael S.
mailto:[email protected]
http://www.schuerig.de/michael/