With Rails 2.2 around the corner, I decided to implement a scalable testing infrastructure for the declarative_authorization plugin. One great thing to notice at the RailsConf Europe was Ian’s garlic. Though only given as a side note in Ian’s talk on resources_controller, it provides a nice way of keeping your plugin tested against all those Rails versions.
Very easy to set up. Only add to your Rakefile a few lines that run garlic:
if File.directory?(File.join(File.dirname(__FILE__), 'garlic')) require File.join(File.dirname(__FILE__), 'garlic/lib/garlic_tasks') require File.join(File.dirname(__FILE__), 'garlic') end desc "clone the garlic repo (for running ci tasks)" task :get_garlic do sh "git clone git://github.com/ianwhite/garlic.git garlic" end |
And define the tasks that garlic should perform for you. In the declarative_authorization case, garlic should retrieve the plugin from the current path and take a few Rails versions as targets. For the test run, garlic just needs to run “rake”. This is the necessary recipe:
garlic do repo 'rails', :url => 'git://github.com/rails/rails' repo 'declarative_authorization', :path => '.' target 'edge' target '2.1-stable', :branch => 'origin/2-1-stable' target '2.2.0-RC1', :tag => 'v2.2.0' all_targets do prepare do plugin 'declarative_authorization', :clone => true end run do cd "vendor/plugins/declarative_authorization" do sh "rake" end end end end |
Thus, all that is needed to check my current declarative_authorization branch against all defined Rails versions is
rake get_garlic # just once
rake garlic:all |
Great, all declarative_authorization tests pass on 2.2.0-RC1!
All specified targets passed: edge, 2.1-stable, 2.2.0-RC1 |