capistrano 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +50 -2
- data/lib/capistrano/cli/execute.rb +1 -0
- data/lib/capistrano/cli/options.rb +4 -0
- data/lib/capistrano/cli/ui.rb +13 -0
- data/lib/capistrano/command.rb +2 -2
- data/lib/capistrano/configuration.rb +2 -1
- data/lib/capistrano/configuration/actions/file_transfer.rb +5 -1
- data/lib/capistrano/configuration/actions/invocation.rb +45 -18
- data/lib/capistrano/configuration/callbacks.rb +3 -3
- data/lib/capistrano/configuration/execution.rb +8 -3
- data/lib/capistrano/configuration/loading.rb +20 -21
- data/lib/capistrano/recipes/deploy.rb +56 -27
- data/lib/capistrano/recipes/deploy/local_dependency.rb +6 -2
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +2 -0
- data/lib/capistrano/recipes/deploy/scm/git.rb +21 -12
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +2 -1
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +2 -1
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +22 -34
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +1 -1
- data/lib/capistrano/version.rb +1 -14
- data/test/cli/execute_test.rb +1 -1
- data/test/cli/options_test.rb +7 -1
- data/test/configuration/actions/file_transfer_test.rb +20 -1
- data/test/configuration/actions/invocation_test.rb +16 -10
- data/test/configuration/callbacks_test.rb +16 -2
- data/test/configuration/loading_test.rb +6 -1
- data/test/deploy/local_dependency_test.rb +73 -0
- data/test/deploy/remote_dependency_test.rb +114 -0
- data/test/deploy/scm/git_test.rb +22 -8
- data/test/deploy/scm/mercurial_test.rb +10 -4
- data/test/deploy/strategy/copy_test.rb +16 -11
- data/test/role_test.rb +11 -0
- data/test/server_definition_test.rb +14 -1
- metadata +5 -3
- data/test/version_test.rb +0 -24
@@ -117,6 +117,11 @@ class ConfigurationLoadingTest < Test::Unit::TestCase
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
+
def test_require_from_config_should_return_false_when_called_a_second_time_with_same_args
|
121
|
+
assert @config.require("#{File.dirname(__FILE__)}/../fixtures/custom")
|
122
|
+
assert_equal false, @config.require("#{File.dirname(__FILE__)}/../fixtures/custom")
|
123
|
+
end
|
124
|
+
|
120
125
|
def test_require_in_multiple_instances_should_load_recipes_in_each_instance
|
121
126
|
config2 = MockConfig.new
|
122
127
|
@config.require "#{File.dirname(__FILE__)}/../fixtures/custom"
|
@@ -124,4 +129,4 @@ class ConfigurationLoadingTest < Test::Unit::TestCase
|
|
124
129
|
assert_equal :custom, @config.ping
|
125
130
|
assert_equal :custom, config2.ping
|
126
131
|
end
|
127
|
-
end
|
132
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/recipes/deploy/local_dependency'
|
3
|
+
|
4
|
+
class LocalDependencyTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@config = { }
|
7
|
+
@dependency = Capistrano::Deploy::LocalDependency.new(@config)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_use_standard_error_message
|
11
|
+
setup_for_one_path_entry(false)
|
12
|
+
@dependency.command("cat")
|
13
|
+
assert_equal "`cat' could not be found in the path on the local host", @dependency.message
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_use_alternative_message_if_provided
|
17
|
+
setup_for_one_path_entry(false)
|
18
|
+
@dependency.command("cat").or("Sorry")
|
19
|
+
assert_equal "Sorry", @dependency.message
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_env_with_no_path_should_never_find_command
|
23
|
+
ENV.expects(:[]).with("PATH").returns(nil)
|
24
|
+
assert !@dependency.command("cat").pass?
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_env_with_one_path_entry_should_fail_if_command_not_found
|
28
|
+
setup_for_one_path_entry(false)
|
29
|
+
assert !@dependency.command("cat").pass?
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_env_with_one_path_entry_should_pass_if_command_found
|
33
|
+
setup_for_one_path_entry(true)
|
34
|
+
assert @dependency.command("cat").pass?
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_env_with_three_path_entries_should_fail_if_command_not_found
|
38
|
+
setup_for_three_path_entries(false)
|
39
|
+
assert !@dependency.command("cat").pass?
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_env_with_three_path_entries_should_pass_if_command_found
|
43
|
+
setup_for_three_path_entries(true)
|
44
|
+
assert @dependency.command("cat").pass?
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_env_with_one_path_entry_on_windows_should_pass_if_command_found_with_extension
|
48
|
+
setup_for_one_path_entry_on_windows(true)
|
49
|
+
assert @dependency.command("cat").pass?
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def setup_for_one_path_entry(command_found)
|
55
|
+
ENV.expects(:[]).with("PATH").returns("/bin")
|
56
|
+
File.expects(:executable?).with("/bin/cat").returns(command_found)
|
57
|
+
end
|
58
|
+
|
59
|
+
def setup_for_three_path_entries(command_found)
|
60
|
+
path = %w(/bin /usr/bin /usr/local/bin).join(File::PATH_SEPARATOR)
|
61
|
+
ENV.expects(:[]).with("PATH").returns(path)
|
62
|
+
File.expects(:executable?).with("/usr/bin/cat").returns(command_found)
|
63
|
+
File.expects(:executable?).at_most(1).with("/bin/cat").returns(false)
|
64
|
+
File.expects(:executable?).at_most(1).with("/usr/local/bin/cat").returns(false)
|
65
|
+
end
|
66
|
+
|
67
|
+
def setup_for_one_path_entry_on_windows(command_found)
|
68
|
+
Capistrano::Deploy::LocalDependency.expects(:on_windows?).returns(true)
|
69
|
+
ENV.expects(:[]).with("PATH").returns("/cygwin/bin")
|
70
|
+
File.stubs(:executable?).returns(false)
|
71
|
+
File.expects(:executable?).with("/cygwin/bin/cat.exe").returns(command_found)
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/recipes/deploy/remote_dependency'
|
3
|
+
|
4
|
+
class RemoteDependencyTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@config = { }
|
7
|
+
@dependency = Capistrano::Deploy::RemoteDependency.new(@config)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_use_standard_error_message_for_directory
|
11
|
+
setup_for_a_configuration_run("test -d /data", false)
|
12
|
+
@dependency.directory("/data")
|
13
|
+
assert_equal "`/data' is not a directory (host)", @dependency.message
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_use_standard_error_message_for_file
|
17
|
+
setup_for_a_configuration_run("test -f /data/foo.txt", false)
|
18
|
+
@dependency.file("/data/foo.txt")
|
19
|
+
assert_equal "`/data/foo.txt' is not a file (host)", @dependency.message
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_use_standard_error_message_for_writable
|
23
|
+
setup_for_a_configuration_run("test -w /data/foo.txt", false)
|
24
|
+
@dependency.writable("/data/foo.txt")
|
25
|
+
assert_equal "`/data/foo.txt' is not writable (host)", @dependency.message
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_use_standard_error_message_for_command
|
29
|
+
setup_for_a_configuration_run("which cat", false)
|
30
|
+
@dependency.command("cat")
|
31
|
+
assert_equal "`cat' could not be found in the path (host)", @dependency.message
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_use_standard_error_message_for_gem
|
35
|
+
setup_for_a_configuration_gem_run("capistrano", "9.9", false)
|
36
|
+
@dependency.gem("capistrano", 9.9)
|
37
|
+
assert_equal "gem `capistrano' 9.9 could not be found (host)", @dependency.message
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_fail_if_directory_not_found
|
41
|
+
setup_for_a_configuration_run("test -d /data", false)
|
42
|
+
assert !@dependency.directory("/data").pass?
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_pass_if_directory_found
|
46
|
+
setup_for_a_configuration_run("test -d /data", true)
|
47
|
+
assert @dependency.directory("/data").pass?
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_should_fail_if_file_not_found
|
51
|
+
setup_for_a_configuration_run("test -f /data/foo.txt", false)
|
52
|
+
assert !@dependency.file("/data/foo.txt").pass?
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_should_pas_if_file_found
|
56
|
+
setup_for_a_configuration_run("test -f /data/foo.txt", true)
|
57
|
+
assert @dependency.file("/data/foo.txt").pass?
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_should_fail_if_writable_not_found
|
61
|
+
setup_for_a_configuration_run("test -w /data/foo.txt", false)
|
62
|
+
assert !@dependency.writable("/data/foo.txt").pass?
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_should_pass_if_writable_found
|
66
|
+
setup_for_a_configuration_run("test -w /data/foo.txt", true)
|
67
|
+
assert @dependency.writable("/data/foo.txt").pass?
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_should_fail_if_command_not_found
|
71
|
+
setup_for_a_configuration_run("which cat", false)
|
72
|
+
assert !@dependency.command("cat").pass?
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_should_pass_if_command_found
|
76
|
+
setup_for_a_configuration_run("which cat", true)
|
77
|
+
assert @dependency.command("cat").pass?
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_should_fail_if_gem_not_found
|
81
|
+
setup_for_a_configuration_gem_run("capistrano", "9.9", false)
|
82
|
+
assert !@dependency.gem("capistrano", 9.9).pass?
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_should_pass_if_gem_found
|
86
|
+
setup_for_a_configuration_gem_run("capistrano", "9.9", true)
|
87
|
+
assert @dependency.gem("capistrano", 9.9).pass?
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_should_use_alternative_message_if_provided
|
91
|
+
setup_for_a_configuration_run("which cat", false)
|
92
|
+
@dependency.command("cat").or("Sorry")
|
93
|
+
assert_equal "Sorry (host)", @dependency.message
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def setup_for_a_configuration_run(command, passing)
|
99
|
+
expectation = @config.expects(:run).with(command, {})
|
100
|
+
if passing
|
101
|
+
expectation.returns(true)
|
102
|
+
else
|
103
|
+
error = Capistrano::CommandError.new
|
104
|
+
error.expects(:hosts).returns(["host"])
|
105
|
+
expectation.raises(error)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def setup_for_a_configuration_gem_run(name, version, passing)
|
110
|
+
@config.expects(:fetch).with(:gem_command, "gem").returns("gem")
|
111
|
+
find_gem_cmd = "gem specification --version '#{version}' #{name} 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }'"
|
112
|
+
setup_for_a_configuration_run(find_gem_cmd, passing)
|
113
|
+
end
|
114
|
+
end
|
data/test/deploy/scm/git_test.rb
CHANGED
@@ -31,12 +31,20 @@ class DeploySCMGitTest < Test::Unit::TestCase
|
|
31
31
|
@config[:repository] = "git@somehost.com:project.git"
|
32
32
|
dest = "/var/www"
|
33
33
|
rev = 'c2d9e79'
|
34
|
-
assert_equal "git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest)
|
34
|
+
assert_equal "git clone -q git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
|
35
35
|
|
36
36
|
# With :scm_command
|
37
37
|
git = "/opt/local/bin/git"
|
38
38
|
@config[:scm_command] = git
|
39
|
-
assert_equal "#{git} clone git@somehost.com:project.git /var/www && cd /var/www && #{git} checkout -b deploy #{rev}", @source.checkout(rev, dest)
|
39
|
+
assert_equal "#{git} clone -q git@somehost.com:project.git /var/www && cd /var/www && #{git} checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_checkout_with_verbose_should_not_use_q_switch
|
43
|
+
@config[:repository] = "git@somehost.com:project.git"
|
44
|
+
@config[:scm_verbose] = true
|
45
|
+
dest = "/var/www"
|
46
|
+
rev = 'c2d9e79'
|
47
|
+
assert_equal "git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest)
|
40
48
|
end
|
41
49
|
|
42
50
|
def test_diff
|
@@ -45,7 +53,7 @@ class DeploySCMGitTest < Test::Unit::TestCase
|
|
45
53
|
end
|
46
54
|
|
47
55
|
def test_log
|
48
|
-
assert_equal "git log master", @source.log('master')
|
56
|
+
assert_equal "git log master..", @source.log('master')
|
49
57
|
assert_equal "git log master..branch", @source.log('master', 'branch')
|
50
58
|
end
|
51
59
|
|
@@ -57,6 +65,12 @@ class DeploySCMGitTest < Test::Unit::TestCase
|
|
57
65
|
assert_equal "d11006102c07c94e5d54dd0ee63dca825c93ed61", revision
|
58
66
|
end
|
59
67
|
|
68
|
+
def test_query_revision_deprecation_error
|
69
|
+
assert_raise(ArgumentError) do
|
70
|
+
revision = @source.query_revision('origin/release') {}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
60
74
|
def test_command_should_be_backwards_compatible
|
61
75
|
# 1.x version of this module used ":git", not ":scm_command"
|
62
76
|
@config[:git] = "/srv/bin/git"
|
@@ -66,12 +80,12 @@ class DeploySCMGitTest < Test::Unit::TestCase
|
|
66
80
|
def test_sync
|
67
81
|
dest = "/var/www"
|
68
82
|
rev = 'c2d9e79'
|
69
|
-
assert_equal "cd #{dest} && git fetch
|
83
|
+
assert_equal "cd #{dest} && git fetch -q origin && git reset -q --hard #{rev}", @source.sync(rev, dest)
|
70
84
|
|
71
85
|
# With :scm_command
|
72
86
|
git = "/opt/local/bin/git"
|
73
87
|
@config[:scm_command] = git
|
74
|
-
assert_equal "cd #{dest} && #{git} fetch
|
88
|
+
assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} reset -q --hard #{rev}", @source.sync(rev, dest)
|
75
89
|
end
|
76
90
|
|
77
91
|
def test_sync_with_remote
|
@@ -83,7 +97,7 @@ class DeploySCMGitTest < Test::Unit::TestCase
|
|
83
97
|
@config[:repository] = repository
|
84
98
|
@config[:remote] = remote
|
85
99
|
|
86
|
-
assert_equal "cd #{dest} && git config remote.#{remote}.url #{repository} && git config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/* && git fetch
|
100
|
+
assert_equal "cd #{dest} && git config remote.#{remote}.url #{repository} && git config remote.#{remote}.fetch +refs/heads/*:refs/remotes/#{remote}/* && git fetch -q #{remote} && git reset -q --hard #{rev}", @source.sync(rev, dest)
|
87
101
|
end
|
88
102
|
|
89
103
|
def test_shallow_clone
|
@@ -91,7 +105,7 @@ class DeploySCMGitTest < Test::Unit::TestCase
|
|
91
105
|
@config[:git_shallow_clone] = 1
|
92
106
|
dest = "/var/www"
|
93
107
|
rev = 'c2d9e79'
|
94
|
-
assert_equal "git clone --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest)
|
108
|
+
assert_equal "git clone -q --depth 1 git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
|
95
109
|
end
|
96
110
|
|
97
111
|
def test_remote_clone
|
@@ -99,7 +113,7 @@ class DeploySCMGitTest < Test::Unit::TestCase
|
|
99
113
|
@config[:remote] = "username"
|
100
114
|
dest = "/var/www"
|
101
115
|
rev = 'c2d9e79'
|
102
|
-
assert_equal "git clone -o username git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest)
|
116
|
+
assert_equal "git clone -q -o username git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev}", @source.checkout(rev, dest)
|
103
117
|
end
|
104
118
|
|
105
119
|
# Tests from base_test.rb, makin' sure we didn't break anything up there!
|
@@ -43,10 +43,10 @@ class DeploySCMMercurialTest < Test::Unit::TestCase
|
|
43
43
|
require 'capistrano/logger'
|
44
44
|
@config[:scm_user] = "fred"
|
45
45
|
text = "user:"
|
46
|
-
assert_equal "fred\n", @source.handle_data(
|
46
|
+
assert_equal "fred\n", @source.handle_data(mock_state, :test_stream, text)
|
47
47
|
# :scm_username takes priority
|
48
48
|
@config[:scm_username] = "wilma"
|
49
|
-
assert_equal "wilma\n", @source.handle_data(
|
49
|
+
assert_equal "wilma\n", @source.handle_data(mock_state, :test_stream, text)
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_sync
|
@@ -67,7 +67,7 @@ class DeploySCMMercurialTest < Test::Unit::TestCase
|
|
67
67
|
require 'capistrano/logger'
|
68
68
|
text = "password:"
|
69
69
|
@config[:scm_password] = "opensesame"
|
70
|
-
assert_equal "opensesame\n", @source.handle_data(
|
70
|
+
assert_equal "opensesame\n", @source.handle_data(mock_state, :test_stream, text)
|
71
71
|
end
|
72
72
|
|
73
73
|
def test_prompts_for_password_if_preferred
|
@@ -76,7 +76,7 @@ class DeploySCMMercurialTest < Test::Unit::TestCase
|
|
76
76
|
Capistrano::CLI.stubs(:password_prompt).with("hg password: ").returns("opensesame")
|
77
77
|
@config[:scm_prefer_prompt] = true
|
78
78
|
text = "password:"
|
79
|
-
assert_equal "opensesame\n", @source.handle_data(
|
79
|
+
assert_equal "opensesame\n", @source.handle_data(mock_state, :test_stream, text)
|
80
80
|
end
|
81
81
|
|
82
82
|
|
@@ -120,4 +120,10 @@ class DeploySCMMercurialTest < Test::Unit::TestCase
|
|
120
120
|
assert_equal "hg", @source.local.command
|
121
121
|
assert_equal "/foo/bar/hg", @source.command
|
122
122
|
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def mock_state
|
127
|
+
{ :channel => { :host => "abc" } }
|
128
|
+
end
|
123
129
|
end
|
@@ -53,13 +53,12 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
53
53
|
|
54
54
|
@strategy.expects(:system).with(:local_checkout)
|
55
55
|
@strategy.expects(:system).with("zip -qr 1234567890.zip 1234567890")
|
56
|
-
@strategy.expects(:
|
56
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.zip", "/tmp/1234567890.zip")
|
57
57
|
@strategy.expects(:run).with("cd /u/apps/test/releases && unzip -q /tmp/1234567890.zip && rm /tmp/1234567890.zip")
|
58
58
|
|
59
59
|
mock_file = mock("file")
|
60
60
|
mock_file.expects(:puts).with("154")
|
61
61
|
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
62
|
-
File.expects(:open).with("/temp/dir/1234567890.zip", "rb").yields(StringIO.new).returns(:mock_file_contents)
|
63
62
|
|
64
63
|
FileUtils.expects(:rm).with("/temp/dir/1234567890.zip")
|
65
64
|
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
@@ -75,20 +74,29 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
75
74
|
|
76
75
|
@strategy.expects(:system).with(:local_checkout)
|
77
76
|
@strategy.expects(:system).with("tar cjf 1234567890.tar.bz2 1234567890")
|
78
|
-
@strategy.expects(:
|
77
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.bz2", "/tmp/1234567890.tar.bz2")
|
79
78
|
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xjf /tmp/1234567890.tar.bz2 && rm /tmp/1234567890.tar.bz2")
|
80
79
|
|
81
80
|
mock_file = mock("file")
|
82
81
|
mock_file.expects(:puts).with("154")
|
83
82
|
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
84
|
-
File.expects(:open).with("/temp/dir/1234567890.tar.bz2", "rb").yields(StringIO.new).returns(:mock_file_contents)
|
85
83
|
|
86
84
|
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.bz2")
|
87
85
|
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
88
86
|
|
89
87
|
@strategy.deploy!
|
90
88
|
end
|
91
|
-
|
89
|
+
|
90
|
+
def test_deploy_with_unknown_compression_type_should_error
|
91
|
+
@config[:copy_compression] = :bogus
|
92
|
+
Dir.expects(:tmpdir).returns("/temp/dir")
|
93
|
+
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
|
94
|
+
@strategy.stubs(:system)
|
95
|
+
File.stubs(:open)
|
96
|
+
|
97
|
+
assert_raises(ArgumentError) { @strategy.deploy! }
|
98
|
+
end
|
99
|
+
|
92
100
|
def test_deploy_with_custom_copy_dir_should_use_that_as_tmpdir
|
93
101
|
Dir.expects(:tmpdir).never
|
94
102
|
Dir.expects(:chdir).with("/other/path").yields
|
@@ -97,13 +105,12 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
97
105
|
|
98
106
|
@strategy.expects(:system).with(:local_checkout)
|
99
107
|
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
100
|
-
@strategy.expects(:
|
108
|
+
@strategy.expects(:upload).with("/other/path/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
|
101
109
|
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
102
110
|
|
103
111
|
mock_file = mock("file")
|
104
112
|
mock_file.expects(:puts).with("154")
|
105
113
|
File.expects(:open).with("/other/path/1234567890/REVISION", "w").yields(mock_file)
|
106
|
-
File.expects(:open).with("/other/path/1234567890.tar.gz", "rb").yields(StringIO.new).returns(:mock_file_contents)
|
107
114
|
|
108
115
|
FileUtils.expects(:rm).with("/other/path/1234567890.tar.gz")
|
109
116
|
FileUtils.expects(:rm_rf).with("/other/path/1234567890")
|
@@ -119,13 +126,12 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
119
126
|
|
120
127
|
@strategy.expects(:system).with(:local_checkout)
|
121
128
|
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
122
|
-
@strategy.expects(:
|
129
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/somewhere/else/1234567890.tar.gz")
|
123
130
|
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /somewhere/else/1234567890.tar.gz && rm /somewhere/else/1234567890.tar.gz")
|
124
131
|
|
125
132
|
mock_file = mock("file")
|
126
133
|
mock_file.expects(:puts).with("154")
|
127
134
|
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
128
|
-
File.expects(:open).with("/temp/dir/1234567890.tar.gz", "rb").yields(StringIO.new).returns(:mock_file_contents)
|
129
135
|
|
130
136
|
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
131
137
|
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
@@ -226,13 +232,12 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|
226
232
|
def prepare_standard_compress_and_copy!
|
227
233
|
Dir.expects(:chdir).with("/temp/dir").yields
|
228
234
|
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
|
229
|
-
@strategy.expects(:
|
235
|
+
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
|
230
236
|
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
|
231
237
|
|
232
238
|
mock_file = mock("file")
|
233
239
|
mock_file.expects(:puts).with("154")
|
234
240
|
File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
|
235
|
-
File.expects(:open).with("/temp/dir/1234567890.tar.gz", "rb").yields(StringIO.new).returns(:mock_file_contents)
|
236
241
|
|
237
242
|
FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
|
238
243
|
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
|
data/test/role_test.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "utils"
|
2
|
+
require 'capistrano/role'
|
3
|
+
|
4
|
+
class RoleTest < Test::Unit::TestCase
|
5
|
+
def test_clearing_a_populated_role_should_yield_no_servers
|
6
|
+
role = Capistrano::Role.new("app1.capistrano.test", lambda { "app2.capistrano.test" })
|
7
|
+
assert_equal 2, role.servers.size
|
8
|
+
role.clear
|
9
|
+
assert role.servers.empty?
|
10
|
+
end
|
11
|
+
end
|
@@ -62,6 +62,19 @@ class ServerDefinitionTest < Test::Unit::TestCase
|
|
62
62
|
server = Capistrano::ServerDefinition.new("www.capistrano.test", :primary => true)
|
63
63
|
assert_equal true, server.options[:primary]
|
64
64
|
end
|
65
|
+
|
66
|
+
def test_default_user_should_try_to_guess_username
|
67
|
+
ENV.stubs(:[]).returns(nil)
|
68
|
+
assert_equal "not-specified", Capistrano::ServerDefinition.default_user
|
69
|
+
|
70
|
+
ENV.stubs(:[]).returns(nil)
|
71
|
+
ENV.stubs(:[]).with("USERNAME").returns("ryan")
|
72
|
+
assert_equal "ryan", Capistrano::ServerDefinition.default_user
|
73
|
+
|
74
|
+
ENV.stubs(:[]).returns(nil)
|
75
|
+
ENV.stubs(:[]).with("USER").returns("jamis")
|
76
|
+
assert_equal "jamis", Capistrano::ServerDefinition.default_user
|
77
|
+
end
|
65
78
|
|
66
79
|
def test_comparison_should_match_when_host_user_port_are_same
|
67
80
|
s1 = server("jamis@www.capistrano.test:8080")
|
@@ -105,4 +118,4 @@ class ServerDefinitionTest < Test::Unit::TestCase
|
|
105
118
|
assert_equal "jamis@www.capistrano.test", server("jamis@www.capistrano.test").to_s
|
106
119
|
assert_equal "jamis@www.capistrano.test:1234", server("jamis@www.capistrano.test:1234").to_s
|
107
120
|
end
|
108
|
-
end
|
121
|
+
end
|