sneakin-capistrano 2.5.5

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.
Files changed (107) hide show
  1. data/CHANGELOG.rdoc +761 -0
  2. data/Manifest +104 -0
  3. data/README.rdoc +66 -0
  4. data/Rakefile +35 -0
  5. data/bin/cap +4 -0
  6. data/bin/capify +78 -0
  7. data/capistrano.gemspec +48 -0
  8. data/examples/sample.rb +14 -0
  9. data/lib/capistrano/callback.rb +45 -0
  10. data/lib/capistrano/cli/execute.rb +84 -0
  11. data/lib/capistrano/cli/help.rb +125 -0
  12. data/lib/capistrano/cli/help.txt +75 -0
  13. data/lib/capistrano/cli/options.rb +224 -0
  14. data/lib/capistrano/cli/ui.rb +40 -0
  15. data/lib/capistrano/cli.rb +47 -0
  16. data/lib/capistrano/command.rb +283 -0
  17. data/lib/capistrano/configuration/actions/file_transfer.rb +47 -0
  18. data/lib/capistrano/configuration/actions/inspect.rb +46 -0
  19. data/lib/capistrano/configuration/actions/invocation.rb +293 -0
  20. data/lib/capistrano/configuration/callbacks.rb +148 -0
  21. data/lib/capistrano/configuration/connections.rb +200 -0
  22. data/lib/capistrano/configuration/execution.rb +132 -0
  23. data/lib/capistrano/configuration/loading.rb +197 -0
  24. data/lib/capistrano/configuration/namespaces.rb +197 -0
  25. data/lib/capistrano/configuration/roles.rb +73 -0
  26. data/lib/capistrano/configuration/servers.rb +85 -0
  27. data/lib/capistrano/configuration/variables.rb +127 -0
  28. data/lib/capistrano/configuration.rb +43 -0
  29. data/lib/capistrano/errors.rb +15 -0
  30. data/lib/capistrano/extensions.rb +57 -0
  31. data/lib/capistrano/logger.rb +59 -0
  32. data/lib/capistrano/processable.rb +53 -0
  33. data/lib/capistrano/recipes/compat.rb +32 -0
  34. data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
  35. data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
  36. data/lib/capistrano/recipes/deploy/remote_dependency.rb +105 -0
  37. data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
  38. data/lib/capistrano/recipes/deploy/scm/base.rb +196 -0
  39. data/lib/capistrano/recipes/deploy/scm/bzr.rb +83 -0
  40. data/lib/capistrano/recipes/deploy/scm/cvs.rb +152 -0
  41. data/lib/capistrano/recipes/deploy/scm/darcs.rb +85 -0
  42. data/lib/capistrano/recipes/deploy/scm/git.rb +274 -0
  43. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
  44. data/lib/capistrano/recipes/deploy/scm/none.rb +44 -0
  45. data/lib/capistrano/recipes/deploy/scm/perforce.rb +133 -0
  46. data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
  47. data/lib/capistrano/recipes/deploy/scm.rb +19 -0
  48. data/lib/capistrano/recipes/deploy/strategy/base.rb +79 -0
  49. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
  50. data/lib/capistrano/recipes/deploy/strategy/copy.rb +210 -0
  51. data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
  52. data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
  53. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +56 -0
  54. data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
  55. data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
  56. data/lib/capistrano/recipes/deploy.rb +562 -0
  57. data/lib/capistrano/recipes/standard.rb +37 -0
  58. data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
  59. data/lib/capistrano/recipes/upgrade.rb +33 -0
  60. data/lib/capistrano/role.rb +102 -0
  61. data/lib/capistrano/server_definition.rb +56 -0
  62. data/lib/capistrano/shell.rb +260 -0
  63. data/lib/capistrano/ssh.rb +99 -0
  64. data/lib/capistrano/task_definition.rb +70 -0
  65. data/lib/capistrano/transfer.rb +216 -0
  66. data/lib/capistrano/version.rb +18 -0
  67. data/lib/capistrano.rb +2 -0
  68. data/setup.rb +1346 -0
  69. data/test/cli/execute_test.rb +132 -0
  70. data/test/cli/help_test.rb +165 -0
  71. data/test/cli/options_test.rb +317 -0
  72. data/test/cli/ui_test.rb +28 -0
  73. data/test/cli_test.rb +17 -0
  74. data/test/command_test.rb +286 -0
  75. data/test/configuration/actions/file_transfer_test.rb +61 -0
  76. data/test/configuration/actions/inspect_test.rb +65 -0
  77. data/test/configuration/actions/invocation_test.rb +224 -0
  78. data/test/configuration/callbacks_test.rb +220 -0
  79. data/test/configuration/connections_test.rb +349 -0
  80. data/test/configuration/execution_test.rb +175 -0
  81. data/test/configuration/loading_test.rb +132 -0
  82. data/test/configuration/namespace_dsl_test.rb +311 -0
  83. data/test/configuration/roles_test.rb +144 -0
  84. data/test/configuration/servers_test.rb +121 -0
  85. data/test/configuration/variables_test.rb +184 -0
  86. data/test/configuration_test.rb +88 -0
  87. data/test/deploy/local_dependency_test.rb +76 -0
  88. data/test/deploy/remote_dependency_test.rb +114 -0
  89. data/test/deploy/scm/accurev_test.rb +23 -0
  90. data/test/deploy/scm/base_test.rb +55 -0
  91. data/test/deploy/scm/git_test.rb +184 -0
  92. data/test/deploy/scm/mercurial_test.rb +129 -0
  93. data/test/deploy/scm/none_test.rb +35 -0
  94. data/test/deploy/strategy/copy_test.rb +258 -0
  95. data/test/extensions_test.rb +69 -0
  96. data/test/fixtures/cli_integration.rb +5 -0
  97. data/test/fixtures/config.rb +5 -0
  98. data/test/fixtures/custom.rb +3 -0
  99. data/test/logger_test.rb +123 -0
  100. data/test/role_test.rb +11 -0
  101. data/test/server_definition_test.rb +121 -0
  102. data/test/shell_test.rb +90 -0
  103. data/test/ssh_test.rb +104 -0
  104. data/test/task_definition_test.rb +101 -0
  105. data/test/transfer_test.rb +160 -0
  106. data/test/utils.rb +38 -0
  107. metadata +306 -0
@@ -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(:invoke_command).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
@@ -0,0 +1,23 @@
1
+ require "utils"
2
+ require 'capistrano/recipes/deploy/scm/accurev'
3
+
4
+ class AccurevTest < Test::Unit::TestCase
5
+ include Capistrano::Deploy::SCM
6
+
7
+ def test_internal_revision_to_s
8
+ assert_equal 'foo/1', Accurev::InternalRevision.new('foo', 1).to_s
9
+ assert_equal 'foo/highest', Accurev::InternalRevision.new('foo', 'highest').to_s
10
+ end
11
+
12
+ def test_internal_revision_parse
13
+ revision = Accurev::InternalRevision.parse('foo')
14
+ assert_equal 'foo', revision.stream
15
+ assert_equal 'highest', revision.transaction_id
16
+ assert_equal 'foo/highest', revision.to_s
17
+
18
+ revision = Accurev::InternalRevision.parse('foo/1')
19
+ assert_equal 'foo', revision.stream
20
+ assert_equal '1', revision.transaction_id
21
+ assert_equal 'foo/1', revision.to_s
22
+ end
23
+ end
@@ -0,0 +1,55 @@
1
+ require "utils"
2
+ require 'capistrano/recipes/deploy/scm/base'
3
+
4
+ class DeploySCMBaseTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::Base
6
+ default_command "floopy"
7
+ end
8
+
9
+ def setup
10
+ @config = { }
11
+ def @config.exists?(name); key?(name); end
12
+
13
+ @source = TestSCM.new(@config)
14
+ end
15
+
16
+ def test_command_should_default_to_default_command
17
+ assert_equal "floopy", @source.command
18
+ @source.local { assert_equal "floopy", @source.command }
19
+ end
20
+
21
+ def test_command_should_use_scm_command_if_available
22
+ @config[:scm_command] = "/opt/local/bin/floopy"
23
+ assert_equal "/opt/local/bin/floopy", @source.command
24
+ end
25
+
26
+ def test_command_should_use_scm_command_in_local_mode_if_local_scm_command_not_set
27
+ @config[:scm_command] = "/opt/local/bin/floopy"
28
+ @source.local { assert_equal "/opt/local/bin/floopy", @source.command }
29
+ end
30
+
31
+ def test_command_should_use_local_scm_command_in_local_mode_if_local_scm_command_is_set
32
+ @config[:scm_command] = "/opt/local/bin/floopy"
33
+ @config[:local_scm_command] = "/usr/local/bin/floopy"
34
+ assert_equal "/opt/local/bin/floopy", @source.command
35
+ @source.local { assert_equal "/usr/local/bin/floopy", @source.command }
36
+ end
37
+
38
+ def test_command_should_use_default_if_scm_command_is_default
39
+ @config[:scm_command] = :default
40
+ assert_equal "floopy", @source.command
41
+ end
42
+
43
+ def test_command_should_use_default_in_local_mode_if_local_scm_command_is_default
44
+ @config[:scm_command] = "/foo/bar/floopy"
45
+ @config[:local_scm_command] = :default
46
+ @source.local { assert_equal "floopy", @source.command }
47
+ end
48
+
49
+ def test_local_mode_proxy_should_treat_messages_as_being_in_local_mode
50
+ @config[:scm_command] = "/foo/bar/floopy"
51
+ @config[:local_scm_command] = :default
52
+ assert_equal "floopy", @source.local.command
53
+ assert_equal "/foo/bar/floopy", @source.command
54
+ end
55
+ end
@@ -0,0 +1,184 @@
1
+ require "utils"
2
+ require 'capistrano/recipes/deploy/scm/git'
3
+
4
+ class DeploySCMGitTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::Git
6
+ default_command "git"
7
+ end
8
+
9
+ def setup
10
+ @config = { :repository => "." }
11
+ def @config.exists?(name); key?(name); end
12
+
13
+ @source = TestSCM.new(@config)
14
+ end
15
+
16
+ def test_head
17
+ assert_equal "HEAD", @source.head
18
+
19
+ # With :branch
20
+ @config[:branch] = "master"
21
+ assert_equal "master", @source.head
22
+ end
23
+
24
+ def test_origin
25
+ assert_equal "origin", @source.origin
26
+ @config[:remote] = "username"
27
+ assert_equal "username", @source.origin
28
+ end
29
+
30
+ def test_checkout
31
+ @config[:repository] = "git@somehost.com:project.git"
32
+ dest = "/var/www"
33
+ rev = 'c2d9e79'
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
+
36
+ # With :scm_command
37
+ git = "/opt/local/bin/git"
38
+ @config[:scm_command] = git
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
+
41
+ # with submodules
42
+ @config[:git_enable_submodules] = true
43
+ assert_equal "#{git} clone -q git@somehost.com:project.git /var/www && cd /var/www && #{git} checkout -q -b deploy #{rev} && #{git} submodule -q init && #{git} submodule -q sync && #{git} submodule -q update", @source.checkout(rev, dest)
44
+ end
45
+
46
+ def test_checkout_with_verbose_should_not_use_q_switch
47
+ @config[:repository] = "git@somehost.com:project.git"
48
+ @config[:scm_verbose] = true
49
+ dest = "/var/www"
50
+ rev = 'c2d9e79'
51
+ assert_equal "git clone git@somehost.com:project.git /var/www && cd /var/www && git checkout -b deploy #{rev}", @source.checkout(rev, dest)
52
+ end
53
+
54
+ def test_diff
55
+ assert_equal "git diff master", @source.diff('master')
56
+ assert_equal "git diff master..branch", @source.diff('master', 'branch')
57
+ end
58
+
59
+ def test_log
60
+ assert_equal "git log master..", @source.log('master')
61
+ assert_equal "git log master..branch", @source.log('master', 'branch')
62
+ end
63
+
64
+ def test_query_revision
65
+ revision = @source.query_revision('HEAD') do |o|
66
+ assert_equal "git ls-remote . HEAD", o
67
+ "d11006102c07c94e5d54dd0ee63dca825c93ed61\tHEAD"
68
+ end
69
+ assert_equal "d11006102c07c94e5d54dd0ee63dca825c93ed61", revision
70
+ end
71
+
72
+ def test_query_revision_has_whitespace
73
+ revision = @source.query_revision('HEAD') do |o|
74
+ assert_equal "git ls-remote . HEAD", o
75
+ "d11006102c07c94e5d54dd0ee63dca825c93ed61\tHEAD\r"
76
+ end
77
+ assert_equal "d11006102c07c94e5d54dd0ee63dca825c93ed61", revision
78
+ end
79
+
80
+ def test_query_revision_deprecation_error
81
+ assert_raise(ArgumentError) do
82
+ revision = @source.query_revision('origin/release') {}
83
+ end
84
+ end
85
+
86
+ def test_command_should_be_backwards_compatible
87
+ # 1.x version of this module used ":git", not ":scm_command"
88
+ @config[:git] = "/srv/bin/git"
89
+ assert_equal "/srv/bin/git", @source.command
90
+ end
91
+
92
+ def test_sync
93
+ dest = "/var/www"
94
+ rev = 'c2d9e79'
95
+ assert_equal "cd #{dest} && git fetch -q origin && git reset -q --hard #{rev}", @source.sync(rev, dest)
96
+
97
+ # With :scm_command
98
+ git = "/opt/local/bin/git"
99
+ @config[:scm_command] = git
100
+ assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} reset -q --hard #{rev}", @source.sync(rev, dest)
101
+
102
+ # with submodules
103
+ @config[:git_enable_submodules] = true
104
+ assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} reset -q --hard #{rev} && #{git} submodule -q init && for mod in `#{git} submodule status | awk '{ print $2 }'`; do #{git} config -f .git/config submodule.${mod}.url `#{git} config -f .gitmodules --get submodule.${mod}.url` && echo Synced $mod; done && #{git} submodule -q sync && #{git} submodule -q update", @source.sync(rev, dest)
105
+ end
106
+
107
+ def test_sync_with_remote
108
+ dest = "/var/www"
109
+ rev = 'c2d9e79'
110
+ remote = "username"
111
+ repository = "git@somehost.com:project.git"
112
+
113
+ @config[:repository] = repository
114
+ @config[:remote] = remote
115
+
116
+ 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)
117
+ end
118
+
119
+ def test_shallow_clone
120
+ @config[:repository] = "git@somehost.com:project.git"
121
+ @config[:git_shallow_clone] = 1
122
+ dest = "/var/www"
123
+ rev = 'c2d9e79'
124
+ 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)
125
+ end
126
+
127
+ def test_remote_clone
128
+ @config[:repository] = "git@somehost.com:project.git"
129
+ @config[:remote] = "username"
130
+ dest = "/var/www"
131
+ rev = 'c2d9e79'
132
+ 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)
133
+ end
134
+
135
+ def test_remote_clone_with_submodules
136
+ @config[:repository] = "git@somehost.com:project.git"
137
+ @config[:remote] = "username"
138
+ @config[:git_enable_submodules] = true
139
+ dest = "/var/www"
140
+ rev = 'c2d9e79'
141
+ assert_equal "git clone -q -o username git@somehost.com:project.git /var/www && cd /var/www && git checkout -q -b deploy #{rev} && git submodule -q init && git submodule -q sync && git submodule -q update", @source.checkout(rev, dest)
142
+ end
143
+
144
+ # Tests from base_test.rb, makin' sure we didn't break anything up there!
145
+ def test_command_should_default_to_default_command
146
+ assert_equal "git", @source.command
147
+ @source.local { assert_equal "git", @source.command }
148
+ end
149
+
150
+ def test_command_should_use_scm_command_if_available
151
+ @config[:scm_command] = "/opt/local/bin/git"
152
+ assert_equal "/opt/local/bin/git", @source.command
153
+ end
154
+
155
+ def test_command_should_use_scm_command_in_local_mode_if_local_scm_command_not_set
156
+ @config[:scm_command] = "/opt/local/bin/git"
157
+ @source.local { assert_equal "/opt/local/bin/git", @source.command }
158
+ end
159
+
160
+ def test_command_should_use_local_scm_command_in_local_mode_if_local_scm_command_is_set
161
+ @config[:scm_command] = "/opt/local/bin/git"
162
+ @config[:local_scm_command] = "/usr/local/bin/git"
163
+ assert_equal "/opt/local/bin/git", @source.command
164
+ @source.local { assert_equal "/usr/local/bin/git", @source.command }
165
+ end
166
+
167
+ def test_command_should_use_default_if_scm_command_is_default
168
+ @config[:scm_command] = :default
169
+ assert_equal "git", @source.command
170
+ end
171
+
172
+ def test_command_should_use_default_in_local_mode_if_local_scm_command_is_default
173
+ @config[:scm_command] = "/foo/bar/git"
174
+ @config[:local_scm_command] = :default
175
+ @source.local { assert_equal "git", @source.command }
176
+ end
177
+
178
+ def test_local_mode_proxy_should_treat_messages_as_being_in_local_mode
179
+ @config[:scm_command] = "/foo/bar/git"
180
+ @config[:local_scm_command] = :default
181
+ assert_equal "git", @source.local.command
182
+ assert_equal "/foo/bar/git", @source.command
183
+ end
184
+ end
@@ -0,0 +1,129 @@
1
+ require "utils"
2
+ require 'capistrano/recipes/deploy/scm/mercurial'
3
+
4
+ class DeploySCMMercurialTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::Mercurial
6
+ default_command "hg"
7
+ end
8
+
9
+ def setup
10
+ @config = { }
11
+ def @config.exists?(name); key?(name); end
12
+
13
+ @source = TestSCM.new(@config)
14
+ end
15
+
16
+ def test_head
17
+ assert_equal "tip", @source.head
18
+ end
19
+
20
+ def test_checkout
21
+ @config[:repository] = "http://example.com/project-hg"
22
+ dest = "/var/www"
23
+ assert_equal "hg clone --noupdate http://example.com/project-hg /var/www && hg update --repository /var/www --clean 8a8e00b8f11b", @source.checkout('8a8e00b8f11b', dest)
24
+ end
25
+
26
+ def test_diff
27
+ assert_equal "hg diff --rev tip", @source.diff('tip')
28
+ assert_equal "hg diff --rev 1 --rev 2", @source.diff('1', '2')
29
+ end
30
+
31
+ def test_log
32
+ assert_equal "hg log --rev 8a8e00b8f11b", @source.log('8a8e00b8f11b')
33
+ assert_equal "hg log --rev 0:3", @source.log('0', '3')
34
+ end
35
+
36
+ def test_query_revision
37
+ assert_equal "hg log -r 8a8e00b8f11b --template '{node|short}'", @source.query_revision('8a8e00b8f11b') { |o| o }
38
+ end
39
+
40
+ def test_username_should_be_backwards_compatible
41
+ # older versions of this module required :scm_user var instead
42
+ # of the currently preferred :scm_username
43
+ require 'capistrano/logger'
44
+ @config[:scm_user] = "fred"
45
+ text = "user:"
46
+ assert_equal "fred\n", @source.handle_data(mock_state, :test_stream, text)
47
+ # :scm_username takes priority
48
+ @config[:scm_username] = "wilma"
49
+ assert_equal "wilma\n", @source.handle_data(mock_state, :test_stream, text)
50
+ end
51
+
52
+ def test_sync
53
+ dest = "/var/www"
54
+ assert_equal "hg pull --repository /var/www && hg update --repository /var/www --clean 8a8e00b8f11b", @source.sync('8a8e00b8f11b', dest)
55
+
56
+ # With :scm_command
57
+ @config[:scm_command] = "/opt/local/bin/hg"
58
+ assert_equal "/opt/local/bin/hg pull --repository /var/www && /opt/local/bin/hg update --repository /var/www --clean 8a8e00b8f11b", @source.sync('8a8e00b8f11b', dest)
59
+ end
60
+
61
+ def test_export
62
+ dest = "/var/www"
63
+ assert_raise(NotImplementedError) { @source.export('8a8e00b8f11b', dest) }
64
+ end
65
+
66
+ def test_sends_password_if_set
67
+ require 'capistrano/logger'
68
+ text = "password:"
69
+ @config[:scm_password] = "opensesame"
70
+ assert_equal "opensesame\n", @source.handle_data(mock_state, :test_stream, text)
71
+ end
72
+
73
+ def test_prompts_for_password_if_preferred
74
+ require 'capistrano/logger'
75
+ require 'capistrano/cli'
76
+ Capistrano::CLI.stubs(:password_prompt).with("hg password: ").returns("opensesame")
77
+ @config[:scm_prefer_prompt] = true
78
+ text = "password:"
79
+ assert_equal "opensesame\n", @source.handle_data(mock_state, :test_stream, text)
80
+ end
81
+
82
+
83
+ # Tests from base_test.rb, makin' sure we didn't break anything up there!
84
+ def test_command_should_default_to_default_command
85
+ assert_equal "hg", @source.command
86
+ @source.local { assert_equal "hg", @source.command }
87
+ end
88
+
89
+ def test_command_should_use_scm_command_if_available
90
+ @config[:scm_command] = "/opt/local/bin/hg"
91
+ assert_equal "/opt/local/bin/hg", @source.command
92
+ end
93
+
94
+ def test_command_should_use_scm_command_in_local_mode_if_local_scm_command_not_set
95
+ @config[:scm_command] = "/opt/local/bin/hg"
96
+ @source.local { assert_equal "/opt/local/bin/hg", @source.command }
97
+ end
98
+
99
+ def test_command_should_use_local_scm_command_in_local_mode_if_local_scm_command_is_set
100
+ @config[:scm_command] = "/opt/local/bin/hg"
101
+ @config[:local_scm_command] = "/usr/local/bin/hg"
102
+ assert_equal "/opt/local/bin/hg", @source.command
103
+ @source.local { assert_equal "/usr/local/bin/hg", @source.command }
104
+ end
105
+
106
+ def test_command_should_use_default_if_scm_command_is_default
107
+ @config[:scm_command] = :default
108
+ assert_equal "hg", @source.command
109
+ end
110
+
111
+ def test_command_should_use_default_in_local_mode_if_local_scm_command_is_default
112
+ @config[:scm_command] = "/foo/bar/hg"
113
+ @config[:local_scm_command] = :default
114
+ @source.local { assert_equal "hg", @source.command }
115
+ end
116
+
117
+ def test_local_mode_proxy_should_treat_messages_as_being_in_local_mode
118
+ @config[:scm_command] = "/foo/bar/hg"
119
+ @config[:local_scm_command] = :default
120
+ assert_equal "hg", @source.local.command
121
+ assert_equal "/foo/bar/hg", @source.command
122
+ end
123
+
124
+ private
125
+
126
+ def mock_state
127
+ { :channel => { :host => "abc" } }
128
+ end
129
+ end
@@ -0,0 +1,35 @@
1
+ require 'utils'
2
+ require 'capistrano/recipes/deploy/scm/none'
3
+
4
+ class DeploySCMNoneTest < Test::Unit::TestCase
5
+ class TestSCM < Capistrano::Deploy::SCM::None
6
+ default_command 'none'
7
+ end
8
+
9
+ def setup
10
+ @config = {}
11
+ def @config.exists?(name); key?(name); end
12
+ @source = TestSCM.new(@config)
13
+ end
14
+
15
+ def test_the_truth
16
+ assert true
17
+ end
18
+
19
+ def test_checkout_on_linux
20
+ Capistrano::Deploy::LocalDependency.stubs(:on_windows?).returns(false)
21
+ @config[:repository] = '.'
22
+ rev = ''
23
+ dest = '/var/www'
24
+ assert_equal "cp -R . /var/www", @source.checkout(rev, dest)
25
+ end
26
+
27
+ def test_checkout_on_windows
28
+ Capistrano::Deploy::LocalDependency.stubs(:on_windows?).returns(true)
29
+ @config[:repository] = '.'
30
+ rev = ''
31
+ dest = 'c:/Documents and settings/admin/tmp'
32
+ assert_equal "xcopy . \"c:/Documents and settings/admin/tmp\" /S/I/Y/Q/E", @source.checkout(rev, dest)
33
+ end
34
+
35
+ end