2011-07-20 3 views
6

Есть ли способ, чтобы тесты модульного запуска capistrano в моем приложении Rails при запуске cap deploy и сбой, если они не пройдут? Я знаю, что это может и должно быть сделано установщиком, но мне бы хотелось, чтобы он был автоматическим. Любые идеи очень приветствуются.Автоматически запускать тесты при развертывании с помощью capistrano

Заранее благодарен!

EDIT: В итоге я использовал this в качестве решения.

ответ

4

Эта задача Capistrano будет запускать юнит-тесты на сервере развертывается в режиме производства:

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 

Найдено решение здесь: http://marklunds.com/articles/one/338

: D

+0

решением, которое вы размещены запускает тест на сервере. Я не думаю, что большинство будет делать tht .. – brayne

+2

В итоге я добавил [this] (https://gist.github.com/1097695) в файл deploy.rb. – Ian

1

Эта установка будет работать ваш тесты локально перед развертыванием.

Задача Capistrano, например. Библиотека/Capistrano/задачи/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 конфигурации,конфигурации/deploy.rb

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

Работы в Capistrano v3.x

0

конфигурации/deploy.rb

# Path of tests to be run, use array with empty string to run all tests 
set :tests, [''] 

namespace :deploy do 
    desc "Runs test before deploying, can't deploy unless they pass" 
    task :run_tests do 
    test_log = "log/capistrano.test.log" 
    tests = fetch(:tests) 
    tests.each do |test| 
     puts "--> Running tests: '#{test}', please wait ..." 
     unless system "bundle exec rspeC#{test} > #{test_log} 2>&1" 
     puts "--> Aborting deployment! One or more tests in '#{test}' failed. Results in: #{test_log}" 
     exit; 
     end 
     puts "--> '#{test}' passed" 
    end 
    puts "--> All tests passed, continuing deployment" 
    system "rm #{test_log}" 
    end 

    # Only allow a deploy with passing tests to be deployed 
    before :deploy, "deploy:run_tests" 

end 

Выполнить его с

cap production deploy:run_tests 
Смежные вопросы