Testing Rails Engine plugins with Rails 3

Does anybody have any ideas for how to test a Rails Engine plugin with Rails 3?

To test a Rails Engine plugin, you have to embed a full Rails application inside of the plugin's test folder. There are a couple of old tricks for loading the plugin into the embedded Rails app, for testing: Testing Rails Engine Gems – Justin Ball Those tricks don't work any more with Rails 3, and the config.plugin_paths setting has been refactored away.

I've been looking at some of the more prominent Rails Engine plugins, like Clearance, Devise, etc. I haven't been able to find any examples of an embedded Rails 3 app for testing, even in the Rails 3 branch for Clearance.

Does anybody have any ideas for how to test a Rails Engine plugin with

Rails 3?

To test a Rails Engine plugin, you have to embed a full Rails

application inside of the plugin’s test folder. There are a couple of

old tricks for loading the plugin into the embedded Rails app, for

testing: http://www.justinball.com/2009/06/16/testing-rails-engine-gems/

Those tricks don’t work any more with Rails 3, and the

config.plugin_paths setting has been refactored away.

I’ve been looking at some of the more prominent Rails Engine plugins,

like Clearance, Devise, etc. I haven’t been able to find any examples

of an embedded Rails 3 app for testing, even in the Rails 3 branch for

Clearance.

Rails 3 branch for clearance is work-in-progress as it depends upon several other gems like formtastic. Inside your test/ directory create a rails_root which is a symlink to a rails3 application. Does that not work?

Anuj

Hello Anuj, thank you for your help.

My problem is: how do I get the Rails app that's in test/rails_root to load the plugin? The Rails app is inside of the plugin, rather than the plugin being inside of the Rails app like normal. test/rails_root/ vendor/plugins is empty so it doesn't load any plugins.

I have seen a couple of different references to ways to provide Rails with an alternate plugin loading path, but the one that appears to be 'most correct' and least hackish is the config.plugin_paths setting which was refactored out of Rails, here: http://github.com/rails/rails/commit/82b9b151ffde44305d67744c0bfd9bb5505f6fbe

Rails::Plugin::Locator has also been factored out of Rails, so overriding it and adding to the list of plugin_locators is no longer possible.

I'm not content with the current testing strategy for Clearance. It has served us well for the 2.x series of Rails but not for Rails 3 while maintaining backwards compatibility.

The most extensive backwards Rails compatibility testing of a library I've seen is in Hoptoad Notifier:

http://github.com/thoughtbot/hoptoad_notifier/blob/master/features/step_definitions/rails_application_steps.rb

That allows us to support a pretty good range of versions of Rails:

http://github.com/thoughtbot/hoptoad_notifier/blob/master/SUPPORTED_RAILS_VERSIONS

I'd like to see this extracted into it's own library for testing your library for backwards Rails compatibility. It also needs to be extended to work with Rails 3.

Not sure if this helps you, but I'm treating all my engine plugins as standalone rails applications. What this means is each engine plugin is theoretically able to run as a standalone application and can therefor be tested the same way as any other rails application. I think the overhead is acceptable and it has worked well for the past couple years.

Daniel

Hello Anuj, thank you for your help.

My problem is: how do I get the Rails app that’s in test/rails_root to load the plugin? The Rails app is inside of the plugin, rather than the plugin being inside of the Rails app like normal. test/rails_root/ vendor/plugins is empty so it doesn’t load any plugins.

Jose Valim seems to be creating a gem to test rails plugins: see

http://github.com/josevalim/enginex