Skip to content

Instantly share code, notes, and snippets.

@ianmurrays
Created July 21, 2011 17:26
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ianmurrays/1097695 to your computer and use it in GitHub Desktop.
Save ianmurrays/1097695 to your computer and use it in GitHub Desktop.
Runs test locally before deploying on capistrano.
set :test_log, "logs/capistrano.test.log"
namespace :deploy do
before 'deploy:update_code' do
puts "--> Running tests, please wait ..."
unless system "bundle exec rake > #{test_log} 2>&1" #' > /dev/null'
puts "--> Tests failed. Run `cat #{test_log}` to see what went wrong."
exit
else
puts "--> Tests passed"
system "rm #{test_log}"
end
end
end
@brunomperes
Copy link

Probably what @cheshire137 did, but I had to do some adjustments: http://stackoverflow.com/a/37708034/2087198

@thomasdarde
Copy link

Here is an updated version for capistrano3 / sshkit

namespace :deploy do
  desc "Runs test before deploying, can't deploy unless they pass"
  task :run_tests do
    run_locally do
      test_log = "log/capistrano.test.log"
      tests = fetch(:tests)
      tests.each do |test|
        info "--> Running tests locally: '#{test}', please wait ..."
        unless test(:rspec, "--tag ~js #{test}  > #{test_log} 2>&1")
          warn "--> Tests: '#{test}' failed. Results in: #{test_log} and below:"
          execute :cat, test_log
          exit;
        end
        info "--> '#{test}' passed"
      end
      info "--> All tests passed"
      execute :rm, test_log
    end
  end
  before :deploy, "deploy:run_tests"
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment