From f2f23f32d973b632a43d2573f32cf021ef0a53dd Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Sat, 25 Jun 2011 17:10:30 -0400 Subject: [PATCH] On a dry run, don't throw an error when trying to use the current_release variable --- lib/capistrano/recipes/deploy.rb | 2 +- test/recipes_test.rb | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/recipes_test.rb diff --git a/lib/capistrano/recipes/deploy.rb b/lib/capistrano/recipes/deploy.rb index c3ad49ae..6b50e142 100644 --- a/lib/capistrano/recipes/deploy.rb +++ b/lib/capistrano/recipes/deploy.rb @@ -56,7 +56,7 @@ _cset(:current_path) { File.join(deploy_to, current_dir) } _cset(:release_path) { File.join(releases_path, release_name) } _cset(:releases) { capture("ls -x #{releases_path}", :except => { :no_release => true }).split.sort } -_cset(:current_release) { File.join(releases_path, releases.last) } +_cset(:current_release) { releases.length > 0 ? File.join(releases_path, releases.last) : nil } _cset(:previous_release) { releases.length > 1 ? File.join(releases_path, releases[-2]) : nil } _cset(:current_revision) { capture("cat #{current_path}/REVISION", :except => { :no_release => true }).chomp } diff --git a/test/recipes_test.rb b/test/recipes_test.rb new file mode 100644 index 00000000..36753e87 --- /dev/null +++ b/test/recipes_test.rb @@ -0,0 +1,25 @@ +require 'utils' +require 'capistrano/configuration' + +class RecipesTest < Test::Unit::TestCase + + def setup + @config = Capistrano::Configuration.new + @config.stubs(:logger).returns(stub_everything) + end + + def test_current_releases_does_not_cause_error_on_dry_run + @config.dry_run = true + @config.load 'deploy' + @config.load do + set :application, "foo" + task :dry_run_test do + fetch :current_release + end + end + + assert_nothing_raised do + @config.dry_run_test + end + end +end \ No newline at end of file