running tests on deploy

published Oct 19, 2007

A simple Capistrano 2.0 recipe, installable as a plugin, that runs all of your tests before the final symlink test.


This plug-in is a Capistrano extension. It requires Capistrano 2.0.0 or greater.

Once installed, running cap deploy will run all of your tests before doing the final symlink.

If the tests fail, the symlink will not be created and your deployment will roll back.

to deploy without tests,

cap deploy:without_tests


Plugin installation

You should be able to install with the following command (from rails root):

Rails 3:
rails plugin install

Rails 2:
script/plugin install

If that doesn’t work, send me an e-mail at

Capistrano configuration

This plugin requires Capistrano 2.0.0 or greater.
To upgrade to the latest version (currently 2.1.0)

gem install capistrano

Once the plug-in is installed, make sure that the recipes are seen by Capistrano

cap -T | grep deploy:without_tests

should return

cap deploy:without_tests # deploy without running tests

If capistrano is not seeing the deploy:without_tests task, then you need to update your Capfile.

(The following is from a post by Jamis Buck)

In Capistrano 2.1.0 or above:
you can delete your Capify file in rails root, and then, from rails root, run

capify .

If you do not want to delete your Capify file, or if you are using Capistrano 2.0.0, add the following line to your Capify file:

Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }


The deploy:run_tests task is executed before the symlink
task. The run_tests task does the following:

  • prepares your test db with rake db:test:prepare
  • runs all of your tests with rake test at a nice level of -10

The deploy:run_tests task won’t work if you call it by itself, as it runs from the
release_path directory, which won’t exist unless called after deploy:update_code.

to deploy without tests, cap deploy:without_tests

you can also set the run_tests option to 0 from the command line like this:

cap -S run_tests=0 deploy

this allows you to do things like deploying with migrations but without tests:

cap -S run_tests=0 deploy:migrations


The original idea for the :run_tests task is from the testing rails blog,
which, sadly, seems to be defunct.

blog comments powered by Disqus