Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically run tests on deploy with capistrano

Is there a way to have capistrano run unit tests on my Rails app when I run cap deploy, and fail if they don't pass? I know this can and should be done by the deployer, but I'd love it to be automatic. Any ideas would be greatly appreciated.

Thanks in advance!

EDIT: I ended up using this as a solution.

like image 837
Ian Avatar asked Jul 20 '11 22:07

Ian


2 Answers

This capistrano task will run the unit tests on the server being deployed, in production mode:

desc "Run the full tests on the deployed app." 
task :run_tests do
 run "cd #{release_path} && RAILS_ENV=production rake && cat /dev/null > log/test.log" 
end

Found the solution here: http://marklunds.com/articles/one/338

:D

like image 139
Ian Avatar answered Nov 20 '22 19:11

Ian


This setup will run your tests locally before deploying.

Capistrano task, e.g. lib/capistrano/tasks/deploy.rake

namespace :deploy do
  desc 'Run test suite before deployment'
  task :test_suite do
    run_locally do
      execute :rake, 'test'
    end
  end
end

Capistrano config, config/deploy.rb

before 'deploy:starting', 'deploy:test_suite'

Works in Capistrano v3.x

like image 32
Daniel B. Avatar answered Nov 20 '22 19:11

Daniel B.