capistrano 2.8.0 → 3.19.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.
Files changed (239) hide show
  1. checksums.yaml +7 -0
  2. data/.docker/Dockerfile +7 -0
  3. data/.docker/ssh_key_rsa +49 -0
  4. data/.docker/ssh_key_rsa.pub +1 -0
  5. data/.docker/ubuntu_setup.sh +23 -0
  6. data/.github/issue_template.md +19 -0
  7. data/.github/pull_request_template.md +22 -0
  8. data/.github/release-drafter.yml +25 -0
  9. data/.github/workflows/ci.yml +80 -0
  10. data/.github/workflows/release-drafter.yml +18 -0
  11. data/.gitignore +23 -8
  12. data/.rubocop.yml +62 -0
  13. data/CHANGELOG.md +1 -0
  14. data/CONTRIBUTING.md +63 -0
  15. data/DEVELOPMENT.md +112 -0
  16. data/Gemfile +42 -9
  17. data/LICENSE.txt +21 -0
  18. data/README.md +221 -0
  19. data/RELEASING.md +17 -0
  20. data/Rakefile +17 -8
  21. data/UPGRADING-3.7.md +86 -0
  22. data/bin/cap +2 -3
  23. data/bin/capify +7 -89
  24. data/capistrano.gemspec +29 -43
  25. data/docker-compose.yml +8 -0
  26. data/features/configuration.feature +28 -0
  27. data/features/deploy.feature +92 -0
  28. data/features/deploy_failure.feature +17 -0
  29. data/features/doctor.feature +11 -0
  30. data/features/installation.feature +21 -0
  31. data/features/sshconnect.feature +11 -0
  32. data/features/stage_failure.feature +9 -0
  33. data/features/step_definitions/assertions.rb +162 -0
  34. data/features/step_definitions/cap_commands.rb +21 -0
  35. data/features/step_definitions/setup.rb +91 -0
  36. data/features/subdirectory.feature +9 -0
  37. data/features/support/docker_gateway.rb +53 -0
  38. data/features/support/env.rb +1 -0
  39. data/features/support/remote_command_helpers.rb +29 -0
  40. data/features/support/remote_ssh_helpers.rb +33 -0
  41. data/lib/Capfile +3 -0
  42. data/lib/capistrano/all.rb +17 -0
  43. data/lib/capistrano/application.rb +153 -0
  44. data/lib/capistrano/configuration/empty_filter.rb +9 -0
  45. data/lib/capistrano/configuration/filter.rb +26 -0
  46. data/lib/capistrano/configuration/host_filter.rb +29 -0
  47. data/lib/capistrano/configuration/null_filter.rb +9 -0
  48. data/lib/capistrano/configuration/plugin_installer.rb +51 -0
  49. data/lib/capistrano/configuration/question.rb +76 -0
  50. data/lib/capistrano/configuration/role_filter.rb +29 -0
  51. data/lib/capistrano/configuration/scm_resolver.rb +149 -0
  52. data/lib/capistrano/configuration/server.rb +137 -0
  53. data/lib/capistrano/configuration/servers.rb +56 -96
  54. data/lib/capistrano/configuration/validated_variables.rb +110 -0
  55. data/lib/capistrano/configuration/variables.rb +79 -94
  56. data/lib/capistrano/configuration.rb +178 -33
  57. data/lib/capistrano/console.rb +1 -0
  58. data/lib/capistrano/defaults.rb +36 -0
  59. data/lib/capistrano/deploy.rb +3 -0
  60. data/lib/capistrano/doctor/environment_doctor.rb +19 -0
  61. data/lib/capistrano/doctor/gems_doctor.rb +45 -0
  62. data/lib/capistrano/doctor/output_helpers.rb +79 -0
  63. data/lib/capistrano/doctor/servers_doctor.rb +105 -0
  64. data/lib/capistrano/doctor/variables_doctor.rb +74 -0
  65. data/lib/capistrano/doctor.rb +6 -0
  66. data/lib/capistrano/dotfile.rb +2 -0
  67. data/lib/capistrano/dsl/env.rb +43 -0
  68. data/lib/capistrano/dsl/paths.rb +89 -0
  69. data/lib/capistrano/dsl/stages.rb +31 -0
  70. data/lib/capistrano/dsl/task_enhancements.rb +61 -0
  71. data/lib/capistrano/dsl.rb +95 -0
  72. data/lib/capistrano/framework.rb +2 -0
  73. data/lib/capistrano/i18n.rb +46 -0
  74. data/lib/capistrano/immutable_task.rb +30 -0
  75. data/lib/capistrano/install.rb +1 -0
  76. data/lib/capistrano/plugin.rb +95 -0
  77. data/lib/capistrano/proc_helpers.rb +13 -0
  78. data/lib/capistrano/scm/git.rb +105 -0
  79. data/lib/capistrano/scm/hg.rb +55 -0
  80. data/lib/capistrano/scm/plugin.rb +13 -0
  81. data/lib/capistrano/scm/svn.rb +56 -0
  82. data/lib/capistrano/scm/tasks/git.rake +84 -0
  83. data/lib/capistrano/scm/tasks/hg.rake +53 -0
  84. data/lib/capistrano/scm/tasks/svn.rake +53 -0
  85. data/lib/capistrano/scm.rb +115 -0
  86. data/lib/capistrano/setup.rb +36 -0
  87. data/lib/capistrano/tasks/console.rake +25 -0
  88. data/lib/capistrano/tasks/deploy.rake +280 -0
  89. data/lib/capistrano/tasks/doctor.rake +24 -0
  90. data/lib/capistrano/tasks/framework.rake +67 -0
  91. data/lib/capistrano/tasks/install.rake +41 -0
  92. data/lib/capistrano/templates/Capfile +38 -0
  93. data/lib/capistrano/templates/deploy.rb.erb +39 -0
  94. data/lib/capistrano/templates/stage.rb.erb +61 -0
  95. data/lib/capistrano/upload_task.rb +9 -0
  96. data/lib/capistrano/version.rb +1 -14
  97. data/lib/capistrano/version_validator.rb +32 -0
  98. data/lib/capistrano.rb +0 -3
  99. data/spec/integration/dsl_spec.rb +632 -0
  100. data/spec/integration_spec_helper.rb +5 -0
  101. data/spec/lib/capistrano/application_spec.rb +60 -0
  102. data/spec/lib/capistrano/configuration/empty_filter_spec.rb +17 -0
  103. data/spec/lib/capistrano/configuration/filter_spec.rb +109 -0
  104. data/spec/lib/capistrano/configuration/host_filter_spec.rb +71 -0
  105. data/spec/lib/capistrano/configuration/null_filter_spec.rb +17 -0
  106. data/spec/lib/capistrano/configuration/plugin_installer_spec.rb +98 -0
  107. data/spec/lib/capistrano/configuration/question_spec.rb +92 -0
  108. data/spec/lib/capistrano/configuration/role_filter_spec.rb +80 -0
  109. data/spec/lib/capistrano/configuration/scm_resolver_spec.rb +56 -0
  110. data/spec/lib/capistrano/configuration/server_spec.rb +309 -0
  111. data/spec/lib/capistrano/configuration/servers_spec.rb +331 -0
  112. data/spec/lib/capistrano/configuration_spec.rb +357 -0
  113. data/spec/lib/capistrano/doctor/environment_doctor_spec.rb +44 -0
  114. data/spec/lib/capistrano/doctor/gems_doctor_spec.rb +67 -0
  115. data/spec/lib/capistrano/doctor/output_helpers_spec.rb +47 -0
  116. data/spec/lib/capistrano/doctor/servers_doctor_spec.rb +86 -0
  117. data/spec/lib/capistrano/doctor/variables_doctor_spec.rb +89 -0
  118. data/spec/lib/capistrano/dsl/paths_spec.rb +228 -0
  119. data/spec/lib/capistrano/dsl/task_enhancements_spec.rb +108 -0
  120. data/spec/lib/capistrano/dsl_spec.rb +125 -0
  121. data/spec/lib/capistrano/immutable_task_spec.rb +31 -0
  122. data/spec/lib/capistrano/plugin_spec.rb +84 -0
  123. data/spec/lib/capistrano/scm/git_spec.rb +194 -0
  124. data/spec/lib/capistrano/scm/hg_spec.rb +109 -0
  125. data/spec/lib/capistrano/scm/svn_spec.rb +137 -0
  126. data/spec/lib/capistrano/scm_spec.rb +103 -0
  127. data/spec/lib/capistrano/upload_task_spec.rb +19 -0
  128. data/spec/lib/capistrano/version_validator_spec.rb +118 -0
  129. data/spec/lib/capistrano_spec.rb +7 -0
  130. data/spec/spec_helper.rb +29 -0
  131. data/spec/support/matchers.rb +5 -0
  132. data/spec/support/tasks/database.rake +11 -0
  133. data/spec/support/tasks/fail.rake +8 -0
  134. data/spec/support/tasks/failed.rake +5 -0
  135. data/spec/support/tasks/plugin.rake +6 -0
  136. data/spec/support/tasks/root.rake +11 -0
  137. data/spec/support/test_app.rb +205 -0
  138. metadata +234 -208
  139. data/.rvmrc +0 -1
  140. data/CHANGELOG +0 -954
  141. data/README.mdown +0 -76
  142. data/lib/capistrano/callback.rb +0 -45
  143. data/lib/capistrano/cli/execute.rb +0 -85
  144. data/lib/capistrano/cli/help.rb +0 -125
  145. data/lib/capistrano/cli/help.txt +0 -81
  146. data/lib/capistrano/cli/options.rb +0 -243
  147. data/lib/capistrano/cli/ui.rb +0 -40
  148. data/lib/capistrano/cli.rb +0 -47
  149. data/lib/capistrano/command.rb +0 -286
  150. data/lib/capistrano/configuration/actions/file_transfer.rb +0 -51
  151. data/lib/capistrano/configuration/actions/inspect.rb +0 -46
  152. data/lib/capistrano/configuration/actions/invocation.rb +0 -298
  153. data/lib/capistrano/configuration/callbacks.rb +0 -148
  154. data/lib/capistrano/configuration/connections.rb +0 -230
  155. data/lib/capistrano/configuration/execution.rb +0 -143
  156. data/lib/capistrano/configuration/loading.rb +0 -197
  157. data/lib/capistrano/configuration/namespaces.rb +0 -197
  158. data/lib/capistrano/configuration/roles.rb +0 -73
  159. data/lib/capistrano/errors.rb +0 -19
  160. data/lib/capistrano/ext/string.rb +0 -5
  161. data/lib/capistrano/extensions.rb +0 -57
  162. data/lib/capistrano/logger.rb +0 -59
  163. data/lib/capistrano/processable.rb +0 -53
  164. data/lib/capistrano/recipes/compat.rb +0 -32
  165. data/lib/capistrano/recipes/deploy/assets.rb +0 -57
  166. data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
  167. data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -54
  168. data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -111
  169. data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
  170. data/lib/capistrano/recipes/deploy/scm/base.rb +0 -196
  171. data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
  172. data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -153
  173. data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -96
  174. data/lib/capistrano/recipes/deploy/scm/git.rb +0 -282
  175. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -137
  176. data/lib/capistrano/recipes/deploy/scm/none.rb +0 -44
  177. data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -138
  178. data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -121
  179. data/lib/capistrano/recipes/deploy/scm.rb +0 -19
  180. data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -88
  181. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
  182. data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -224
  183. data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
  184. data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
  185. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -57
  186. data/lib/capistrano/recipes/deploy/strategy.rb +0 -19
  187. data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +0 -53
  188. data/lib/capistrano/recipes/deploy.rb +0 -568
  189. data/lib/capistrano/recipes/standard.rb +0 -37
  190. data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
  191. data/lib/capistrano/role.rb +0 -102
  192. data/lib/capistrano/server_definition.rb +0 -56
  193. data/lib/capistrano/shell.rb +0 -260
  194. data/lib/capistrano/ssh.rb +0 -101
  195. data/lib/capistrano/task_definition.rb +0 -75
  196. data/lib/capistrano/transfer.rb +0 -216
  197. data/rvmrc.sample +0 -1
  198. data/test/cli/execute_test.rb +0 -132
  199. data/test/cli/help_test.rb +0 -165
  200. data/test/cli/options_test.rb +0 -329
  201. data/test/cli/ui_test.rb +0 -28
  202. data/test/cli_test.rb +0 -17
  203. data/test/command_test.rb +0 -289
  204. data/test/configuration/actions/file_transfer_test.rb +0 -61
  205. data/test/configuration/actions/inspect_test.rb +0 -65
  206. data/test/configuration/actions/invocation_test.rb +0 -247
  207. data/test/configuration/callbacks_test.rb +0 -220
  208. data/test/configuration/connections_test.rb +0 -420
  209. data/test/configuration/execution_test.rb +0 -175
  210. data/test/configuration/loading_test.rb +0 -132
  211. data/test/configuration/namespace_dsl_test.rb +0 -311
  212. data/test/configuration/roles_test.rb +0 -144
  213. data/test/configuration/servers_test.rb +0 -183
  214. data/test/configuration/variables_test.rb +0 -190
  215. data/test/configuration_test.rb +0 -88
  216. data/test/deploy/local_dependency_test.rb +0 -76
  217. data/test/deploy/remote_dependency_test.rb +0 -135
  218. data/test/deploy/scm/accurev_test.rb +0 -23
  219. data/test/deploy/scm/base_test.rb +0 -55
  220. data/test/deploy/scm/bzr_test.rb +0 -51
  221. data/test/deploy/scm/darcs_test.rb +0 -37
  222. data/test/deploy/scm/git_test.rb +0 -184
  223. data/test/deploy/scm/mercurial_test.rb +0 -134
  224. data/test/deploy/scm/none_test.rb +0 -35
  225. data/test/deploy/scm/subversion_test.rb +0 -32
  226. data/test/deploy/strategy/copy_test.rb +0 -321
  227. data/test/extensions_test.rb +0 -69
  228. data/test/fixtures/cli_integration.rb +0 -5
  229. data/test/fixtures/config.rb +0 -5
  230. data/test/fixtures/custom.rb +0 -3
  231. data/test/logger_test.rb +0 -123
  232. data/test/recipes_test.rb +0 -25
  233. data/test/role_test.rb +0 -11
  234. data/test/server_definition_test.rb +0 -121
  235. data/test/shell_test.rb +0 -90
  236. data/test/ssh_test.rb +0 -113
  237. data/test/task_definition_test.rb +0 -116
  238. data/test/transfer_test.rb +0 -160
  239. data/test/utils.rb +0 -37
@@ -1,61 +0,0 @@
1
- require "utils"
2
- require 'capistrano/configuration/actions/file_transfer'
3
-
4
- class ConfigurationActionsFileTransferTest < Test::Unit::TestCase
5
- class MockConfig
6
- include Capistrano::Configuration::Actions::FileTransfer
7
- attr_accessor :sessions, :dry_run
8
- end
9
-
10
- def setup
11
- @config = MockConfig.new
12
- @config.stubs(:logger).returns(stub_everything)
13
- end
14
-
15
- def test_put_should_delegate_to_upload
16
- @config.expects(:upload).with { |from, to, opts|
17
- from.string == "some data" && to == "test.txt" && opts == { :mode => 0777 } }
18
- @config.expects(:run).never
19
- @config.put("some data", "test.txt", :mode => 0777)
20
- end
21
-
22
- def test_get_should_delegate_to_download_with_once
23
- @config.expects(:download).with("testr.txt", "testl.txt", :foo => "bar", :once => true)
24
- @config.get("testr.txt", "testl.txt", :foo => "bar")
25
- end
26
-
27
- def test_upload_should_delegate_to_transfer
28
- @config.expects(:transfer).with(:up, "testl.txt", "testr.txt", :foo => "bar")
29
- @config.upload("testl.txt", "testr.txt", :foo => "bar")
30
- end
31
-
32
- def test_upload_without_mode_should_not_try_to_chmod
33
- @config.expects(:transfer).with(:up, "testl.txt", "testr.txt", :foo => "bar")
34
- @config.expects(:run).never
35
- @config.upload("testl.txt", "testr.txt", :foo => "bar")
36
- end
37
-
38
- def test_upload_with_mode_should_try_to_chmod
39
- @config.expects(:transfer).with(:up, "testl.txt", "testr.txt", :foo => "bar")
40
- @config.expects(:run).with("chmod 775 testr.txt", {:foo => "bar"})
41
- @config.upload("testl.txt", "testr.txt", :mode => 0775, :foo => "bar")
42
- end
43
-
44
- def test_upload_with_symbolic_mode_should_try_to_chmod
45
- @config.expects(:transfer).with(:up, "testl.txt", "testr.txt", :foo => "bar")
46
- @config.expects(:run).with("chmod g+w testr.txt", {:foo => "bar"})
47
- @config.upload("testl.txt", "testr.txt", :mode => "g+w", :foo => "bar")
48
- end
49
-
50
- def test_download_should_delegate_to_transfer
51
- @config.expects(:transfer).with(:down, "testr.txt", "testl.txt", :foo => "bar")
52
- @config.download("testr.txt", "testl.txt", :foo => "bar")
53
- end
54
-
55
- def test_transfer_should_invoke_transfer_on_matching_servers
56
- @config.sessions = { :a => 1, :b => 2, :c => 3, :d => 4 }
57
- @config.expects(:execute_on_servers).with(:foo => "bar").yields([:a, :b, :c])
58
- Capistrano::Transfer.expects(:process).with(:up, "testl.txt", "testr.txt", [1,2,3], {:foo => "bar", :logger => @config.logger})
59
- @config.transfer(:up, "testl.txt", "testr.txt", :foo => "bar")
60
- end
61
- end
@@ -1,65 +0,0 @@
1
- require "utils"
2
- require 'capistrano/configuration/actions/inspect'
3
-
4
- class ConfigurationActionsInspectTest < Test::Unit::TestCase
5
- class MockConfig
6
- include Capistrano::Configuration::Actions::Inspect
7
- end
8
-
9
- def setup
10
- @config = MockConfig.new
11
- @config.stubs(:logger).returns(stub_everything)
12
- end
13
-
14
- def test_stream_should_pass_options_through_to_run
15
- @config.expects(:invoke_command).with("tail -f foo.log", :once => true)
16
- @config.stream("tail -f foo.log", :once => true)
17
- end
18
-
19
- def test_stream_should_emit_stdout_via_puts
20
- @config.expects(:invoke_command).yields(mock("channel"), :out, "something streamed")
21
- @config.expects(:puts).with("something streamed")
22
- @config.expects(:warn).never
23
- @config.stream("tail -f foo.log")
24
- end
25
-
26
- def test_stream_should_emit_stderr_via_warn
27
- ch = mock("channel")
28
- ch.expects(:[]).with(:server).returns(server("capistrano"))
29
- @config.expects(:invoke_command).yields(ch, :err, "something streamed")
30
- @config.expects(:puts).never
31
- @config.expects(:warn).with("[err :: capistrano] something streamed")
32
- @config.stream("tail -f foo.log")
33
- end
34
-
35
- def test_capture_should_pass_options_merged_with_once_to_run
36
- @config.expects(:invoke_command).with("hostname", :foo => "bar", :once => true)
37
- @config.capture("hostname", :foo => "bar")
38
- end
39
-
40
- def test_capture_with_stderr_should_emit_stderr_via_warn
41
- ch = mock("channel")
42
- ch.expects(:[]).with(:server).returns(server("capistrano"))
43
- @config.expects(:invoke_command).yields(ch, :err, "boom")
44
- @config.expects(:warn).with("[err :: capistrano] boom")
45
- @config.capture("hostname")
46
- end
47
-
48
- def test_capture_with_stdout_should_aggregate_and_return_stdout
49
- config_expects_invoke_command_to_loop_with(mock("channel"), "foo", "bar", "baz")
50
- assert_equal "foobarbaz", @config.capture("hostname")
51
- end
52
-
53
- private
54
-
55
- def config_expects_invoke_command_to_loop_with(channel, *output)
56
- class <<@config
57
- attr_accessor :script, :channel
58
- def invoke_command(*args)
59
- script.each { |item| yield channel, :out, item }
60
- end
61
- end
62
- @config.channel = channel
63
- @config.script = output
64
- end
65
- end
@@ -1,247 +0,0 @@
1
- require "utils"
2
- require 'capistrano/configuration/actions/invocation'
3
- require 'capistrano/configuration/actions/file_transfer'
4
-
5
- class ConfigurationActionsInvocationTest < Test::Unit::TestCase
6
- class MockConfig
7
- attr_reader :options
8
- attr_accessor :debug
9
- attr_accessor :dry_run
10
- attr_accessor :preserve_roles
11
- attr_accessor :servers
12
-
13
- def initialize
14
- @options = {}
15
- @servers = []
16
- end
17
-
18
- def [](*args)
19
- @options[*args]
20
- end
21
-
22
- def set(name, value)
23
- @options[name] = value
24
- end
25
-
26
- def fetch(*args)
27
- @options.fetch(*args)
28
- end
29
-
30
- def execute_on_servers(options = {})
31
- yield @servers
32
- end
33
-
34
- include Capistrano::Configuration::Actions::Invocation
35
- include Capistrano::Configuration::Actions::FileTransfer
36
- end
37
-
38
- def setup
39
- @config = make_config
40
- @original_io_proc = MockConfig.default_io_proc
41
- end
42
-
43
- def teardown
44
- MockConfig.default_io_proc = @original_io_proc
45
- end
46
-
47
- def test_run_options_should_be_passed_to_execute_on_servers
48
- @config.expects(:execute_on_servers).with(:foo => "bar")
49
- @config.run "ls", :foo => "bar"
50
- end
51
-
52
- def test_run_will_return_if_dry_run
53
- @config.expects(:dry_run).returns(true)
54
- @config.expects(:execute_on_servers).never
55
- @config.run "ls", :foo => "bar"
56
- end
57
-
58
- def test_put_wont_transfer_if_dry_run
59
- config = make_config
60
- config.dry_run = true
61
- config.servers = %w[ foo ]
62
- config.expects(:sessions).returns({ 'foo-server' => 'bar' })
63
- ::Capistrano::Transfer.expects(:process).never
64
- config.put "foo", "bar", :mode => 0644
65
- end
66
-
67
- def test_add_default_command_options_should_return_bare_options_if_there_is_no_env_or_shell_specified
68
- assert_equal({:foo => "bar"}, @config.add_default_command_options(:foo => "bar"))
69
- end
70
-
71
- def test_add_default_command_options_should_merge_default_environment_as_env
72
- @config[:default_environment][:bang] = "baz"
73
- assert_equal({:foo => "bar", :env => { :bang => "baz" }}, @config.add_default_command_options(:foo => "bar"))
74
- end
75
-
76
- def test_add_default_command_options_should_merge_env_with_default_environment
77
- @config[:default_environment][:bang] = "baz"
78
- @config[:default_environment][:bacon] = "crunchy"
79
- assert_equal({:foo => "bar", :env => { :bang => "baz", :bacon => "chunky", :flip => "flop" }}, @config.add_default_command_options(:foo => "bar", :env => {:bacon => "chunky", :flip => "flop"}))
80
- end
81
-
82
- def test_add_default_command_options_should_use_default_shell_if_present
83
- @config.set :default_shell, "/bin/bash"
84
- assert_equal({:foo => "bar", :shell => "/bin/bash"}, @config.add_default_command_options(:foo => "bar"))
85
- end
86
-
87
- def test_add_default_command_options_should_use_default_shell_of_false_if_present
88
- @config.set :default_shell, false
89
- assert_equal({:foo => "bar", :shell => false}, @config.add_default_command_options(:foo => "bar"))
90
- end
91
-
92
- def test_add_default_command_options_should_use_shell_in_preference_of_default_shell
93
- @config.set :default_shell, "/bin/bash"
94
- assert_equal({:foo => "bar", :shell => "/bin/sh"}, @config.add_default_command_options(:foo => "bar", :shell => "/bin/sh"))
95
- end
96
-
97
- def test_default_io_proc_should_log_stdout_arguments_as_info
98
- ch = { :host => "capistrano",
99
- :server => server("capistrano"),
100
- :options => { :logger => mock("logger") } }
101
- ch[:options][:logger].expects(:info).with("data stuff", "out :: capistrano")
102
- MockConfig.default_io_proc[ch, :out, "data stuff"]
103
- end
104
-
105
- def test_default_io_proc_should_log_stderr_arguments_as_important
106
- ch = { :host => "capistrano",
107
- :server => server("capistrano"),
108
- :options => { :logger => mock("logger") } }
109
- ch[:options][:logger].expects(:important).with("data stuff", "err :: capistrano")
110
- MockConfig.default_io_proc[ch, :err, "data stuff"]
111
- end
112
-
113
- def test_sudo_should_default_to_sudo
114
- @config.expects(:run).with("sudo -p 'sudo password: ' ls", {})
115
- @config.sudo "ls"
116
- end
117
-
118
- def test_sudo_should_use_sudo_variable_definition
119
- @config.expects(:run).with("/opt/local/bin/sudo -p 'sudo password: ' ls", {})
120
- @config.options[:sudo] = "/opt/local/bin/sudo"
121
- @config.sudo "ls"
122
- end
123
-
124
- def test_sudo_should_interpret_as_option_as_user
125
- @config.expects(:run).with("sudo -p 'sudo password: ' -u app ls", {})
126
- @config.sudo "ls", :as => "app"
127
- end
128
-
129
- def test_sudo_should_pass_options_through_to_run
130
- @config.expects(:run).with("sudo -p 'sudo password: ' ls", :foo => "bar")
131
- @config.sudo "ls", :foo => "bar"
132
- end
133
-
134
- def test_sudo_should_avoid_minus_p_when_sudo_prompt_is_empty
135
- @config.set :sudo_prompt, ""
136
- @config.expects(:run).with("sudo ls", {})
137
- @config.sudo "ls"
138
- end
139
-
140
- def test_sudo_should_interpret_sudo_prompt_variable_as_custom_prompt
141
- @config.set :sudo_prompt, "give it to me: "
142
- @config.expects(:run).with("sudo -p 'give it to me: ' ls", {})
143
- @config.sudo "ls"
144
- end
145
-
146
- def test_sudo_behavior_callback_should_send_password_when_prompted_with_default_sudo_prompt
147
- ch = mock("channel")
148
- ch.expects(:send_data).with("g00b3r\n")
149
- @config.options[:password] = "g00b3r"
150
- @config.sudo_behavior_callback(nil)[ch, nil, "sudo password: "]
151
- end
152
-
153
- def test_sudo_behavior_callback_should_send_password_when_prompted_with_custom_sudo_prompt
154
- ch = mock("channel")
155
- ch.expects(:send_data).with("g00b3r\n")
156
- @config.set :sudo_prompt, "give it to me: "
157
- @config.options[:password] = "g00b3r"
158
- @config.sudo_behavior_callback(nil)[ch, nil, "give it to me: "]
159
- end
160
-
161
- def test_sudo_behavior_callback_with_incorrect_password_on_first_prompt
162
- ch = mock("channel")
163
- ch.stubs(:[]).with(:host).returns("capistrano")
164
- ch.stubs(:[]).with(:server).returns(server("capistrano"))
165
- @config.expects(:reset!).with(:password)
166
- @config.sudo_behavior_callback(nil)[ch, nil, "Sorry, try again."]
167
- end
168
-
169
- def test_sudo_behavior_callback_with_incorrect_password_on_subsequent_prompts
170
- callback = @config.sudo_behavior_callback(nil)
171
-
172
- ch = mock("channel")
173
- ch.stubs(:[]).with(:host).returns("capistrano")
174
- ch.stubs(:[]).with(:server).returns(server("capistrano"))
175
- ch2 = mock("channel")
176
- ch2.stubs(:[]).with(:host).returns("cap2")
177
- ch2.stubs(:[]).with(:server).returns(server("cap2"))
178
-
179
- @config.expects(:reset!).with(:password).times(2)
180
-
181
- callback[ch, nil, "Sorry, try again."]
182
- callback[ch2, nil, "Sorry, try again."] # shouldn't call reset!
183
- callback[ch, nil, "Sorry, try again."]
184
- end
185
-
186
- def test_sudo_behavior_callback_should_reset_password_and_prompt_again_if_output_includes_both_cues
187
- ch = mock("channel")
188
- ch.stubs(:[]).with(:host).returns("capistrano")
189
- ch.stubs(:[]).with(:server).returns(server("capistrano"))
190
- ch.expects(:send_data, "password!\n").times(2)
191
-
192
- @config.set(:password, "password!")
193
- @config.expects(:reset!).with(:password)
194
-
195
- callback = @config.sudo_behavior_callback(nil)
196
- callback[ch, :out, "sudo password: "]
197
- callback[ch, :out, "Sorry, try again.\nsudo password: "]
198
- end
199
-
200
- def test_sudo_behavior_callback_should_defer_to_fallback_for_other_output
201
- callback = @config.sudo_behavior_callback(inspectable_proc)
202
-
203
- a = mock("channel", :called => true)
204
- b = mock("stream", :called => true)
205
- c = mock("data", :called => true)
206
-
207
- callback[a, b, c]
208
- end
209
-
210
- def test_invoke_command_should_default_to_run
211
- @config.expects(:run).with("ls", :once => true)
212
- @config.invoke_command("ls", :once => true)
213
- end
214
-
215
- def test_invoke_command_should_delegate_to_method_identified_by_via
216
- @config.expects(:foobar).with("ls", :once => true)
217
- @config.invoke_command("ls", :once => true, :via => :foobar)
218
- end
219
-
220
- private
221
-
222
- def make_config
223
- config = MockConfig.new
224
- config.stubs(:logger).returns(stub_everything)
225
- config
226
- end
227
-
228
- def inspectable_proc
229
- Proc.new do |ch, stream, data|
230
- ch.called
231
- stream.called
232
- data.called
233
- end
234
- end
235
-
236
- def prepare_command(command, sessions, options)
237
- a = mock("channel", :called => true)
238
- b = mock("stream", :called => true)
239
- c = mock("data", :called => true)
240
-
241
- compare_args = Proc.new do |tree, sess, opts|
242
- tree.fallback.command == command && sess == sessions && opts == options
243
- end
244
-
245
- Capistrano::Command.expects(:process).with(&compare_args)
246
- end
247
- end
@@ -1,220 +0,0 @@
1
- require "utils"
2
- require 'capistrano/configuration/callbacks'
3
-
4
- class ConfigurationCallbacksTest < Test::Unit::TestCase
5
- class MockConfig
6
- attr_reader :original_initialize_called
7
- attr_reader :called
8
-
9
- def initialize
10
- @original_initialize_called = true
11
- @called = []
12
- end
13
-
14
- def execute_task(task)
15
- invoke_task_directly(task)
16
- end
17
-
18
- protected
19
-
20
- def invoke_task_directly(task)
21
- @called << task
22
- end
23
-
24
- include Capistrano::Configuration::Callbacks
25
- end
26
-
27
- def setup
28
- @config = MockConfig.new
29
- @config.stubs(:logger).returns(stub_everything("logger"))
30
- end
31
-
32
- def test_initialize_should_initialize_callbacks_collection
33
- assert @config.original_initialize_called
34
- assert @config.callbacks.empty?
35
- end
36
-
37
- def test_before_should_delegate_to_on
38
- @config.expects(:on).with(:before, :foo, "bing:blang", {:only => :bar, :zip => :zing})
39
- @config.before :bar, :foo, "bing:blang", :zip => :zing
40
- end
41
-
42
- def test_after_should_delegate_to_on
43
- @config.expects(:on).with(:after, :foo, "bing:blang", {:only => :bar, :zip => :zing})
44
- @config.after :bar, :foo, "bing:blang", :zip => :zing
45
- end
46
-
47
- def test_on_with_single_reference_should_add_task_callback
48
- @config.on :before, :a_test
49
- assert_equal 1, @config.callbacks[:before].length
50
- assert_equal :a_test, @config.callbacks[:before][0].source
51
- @config.expects(:find_and_execute_task).with(:a_test)
52
- @config.callbacks[:before][0].call
53
- end
54
-
55
- def test_on_with_multi_reference_should_add_all_as_task_callback
56
- @config.on :before, :first, :second, :third
57
- assert_equal 3, @config.callbacks[:before].length
58
- assert_equal %w(first second third), @config.callbacks[:before].map { |c| c.source.to_s }
59
- end
60
-
61
- def test_on_with_block_should_add_block_as_proc_callback
62
- called = false
63
- @config.on(:before) { called = true }
64
- assert_equal 1, @config.callbacks[:before].length
65
- assert_instance_of Proc, @config.callbacks[:before][0].source
66
- @config.callbacks[:before][0].call
67
- assert called
68
- end
69
-
70
- def test_on_with_single_only_should_set_only_as_string_array_on_all_references
71
- @config.on :before, :first, "second:third", :only => :primary
72
- assert_equal 2, @config.callbacks[:before].length
73
- assert @config.callbacks[:before].all? { |c| c.only == %w(primary) }
74
- end
75
-
76
- def test_on_with_multi_only_should_set_only_as_string_array_on_all_references
77
- @config.on :before, :first, "second:third", :only => [:primary, "other:one"]
78
- assert_equal 2, @config.callbacks[:before].length
79
- assert @config.callbacks[:before].all? { |c| c.only == %w(primary other:one) }
80
- end
81
-
82
- def test_on_with_single_except_should_set_except_as_string_array_on_all_references
83
- @config.on :before, :first, "second:third", :except => :primary
84
- assert_equal 2, @config.callbacks[:before].length
85
- assert @config.callbacks[:before].all? { |c| c.except == %w(primary) }
86
- end
87
-
88
- def test_on_with_multi_except_should_set_except_as_string_array_on_all_references
89
- @config.on :before, :first, "second:third", :except => [:primary, "other:one"]
90
- assert_equal 2, @config.callbacks[:before].length
91
- assert @config.callbacks[:before].all? { |c| c.except == %w(primary other:one) }
92
- end
93
-
94
- def test_on_with_only_and_block_should_set_only_as_string_array
95
- @config.on(:before, :only => :primary) { blah }
96
- assert_equal 1, @config.callbacks[:before].length
97
- assert_equal %w(primary), @config.callbacks[:before].first.only
98
- end
99
-
100
- def test_on_with_except_and_block_should_set_except_as_string_array
101
- @config.on(:before, :except => :primary) { blah }
102
- assert_equal 1, @config.callbacks[:before].length
103
- assert_equal %w(primary), @config.callbacks[:before].first.except
104
- end
105
-
106
- def test_on_without_tasks_or_block_should_raise_error
107
- assert_raises(ArgumentError) { @config.on(:before) }
108
- end
109
-
110
- def test_on_with_both_tasks_and_block_should_raise_error
111
- assert_raises(ArgumentError) { @config.on(:before, :first) { blah } }
112
- end
113
-
114
- def test_trigger_without_constraints_should_invoke_all_callbacks
115
- task = stub(:fully_qualified_name => "any:old:thing")
116
- @config.on(:before, :first, "second:third")
117
- @config.on(:after, :another, "and:another")
118
- @config.expects(:find_and_execute_task).with(:first)
119
- @config.expects(:find_and_execute_task).with("second:third")
120
- @config.expects(:find_and_execute_task).with(:another).never
121
- @config.expects(:find_and_execute_task).with("and:another").never
122
- @config.trigger(:before, task)
123
- end
124
-
125
- def test_trigger_with_only_constraint_should_invoke_only_matching_callbacks
126
- task = stub(:fully_qualified_name => "any:old:thing")
127
- @config.on(:before, :first)
128
- @config.on(:before, "second:third", :only => "any:old:thing")
129
- @config.on(:before, "this:too", :only => "any:other:thing")
130
- @config.on(:after, :another, "and:another")
131
- @config.expects(:find_and_execute_task).with(:first)
132
- @config.expects(:find_and_execute_task).with("second:third")
133
- @config.expects(:find_and_execute_task).with("this:too").never
134
- @config.expects(:find_and_execute_task).with(:another).never
135
- @config.expects(:find_and_execute_task).with("and:another").never
136
- @config.trigger(:before, task)
137
- end
138
-
139
- def test_trigger_with_except_constraint_should_invoke_anything_but_matching_callbacks
140
- task = stub(:fully_qualified_name => "any:old:thing")
141
- @config.on(:before, :first)
142
- @config.on(:before, "second:third", :except => "any:old:thing")
143
- @config.on(:before, "this:too", :except => "any:other:thing")
144
- @config.on(:after, :another, "and:another")
145
- @config.expects(:find_and_execute_task).with(:first)
146
- @config.expects(:find_and_execute_task).with("second:third").never
147
- @config.expects(:find_and_execute_task).with("this:too")
148
- @config.expects(:find_and_execute_task).with(:another).never
149
- @config.expects(:find_and_execute_task).with("and:another").never
150
- @config.trigger(:before, task)
151
- end
152
-
153
- def test_trigger_without_task_should_invoke_all_callbacks_for_that_event
154
- task = stub(:fully_qualified_name => "any:old:thing")
155
- @config.on(:before, :first)
156
- @config.on(:before, "second:third", :except => "any:old:thing")
157
- @config.on(:before, "this:too", :except => "any:other:thing")
158
- @config.on(:after, :another, "and:another")
159
- @config.expects(:find_and_execute_task).with(:first)
160
- @config.expects(:find_and_execute_task).with("second:third")
161
- @config.expects(:find_and_execute_task).with("this:too")
162
- @config.expects(:find_and_execute_task).with(:another).never
163
- @config.expects(:find_and_execute_task).with("and:another").never
164
- @config.trigger(:before)
165
- end
166
-
167
- def test_execute_task_without_named_hooks_should_just_call_task
168
- ns = stub("namespace", :default_task => nil, :name => "old", :fully_qualified_name => "any:old")
169
- task = stub(:fully_qualified_name => "any:old:thing", :name => "thing", :namespace => ns)
170
-
171
- ns.stubs(:search_task).returns(nil)
172
-
173
- @config.execute_task(task)
174
- assert_equal [task], @config.called
175
- end
176
-
177
- def test_execute_task_with_named_before_hook_should_call_named_before_hook
178
- ns = stub("namespace", :default_task => nil, :name => "old", :fully_qualified_name => "any:old")
179
- task = stub(:fully_qualified_name => "any:old:thing", :name => "thing", :namespace => ns)
180
- before_task = stub(:fully_qualified_name => "any:old:before_thing", :name => "before_thing", :namespace => ns)
181
-
182
- ns.stubs(:search_task).returns(nil)
183
- ns.expects(:search_task).with("before_thing").returns(before_task)
184
-
185
- @config.execute_task(task)
186
- assert_equal [before_task, task], @config.called
187
- end
188
-
189
- def test_execute_task_with_named_after_hook_should_call_named_after_hook
190
- ns = stub("namespace", :default_task => nil, :name => "old", :fully_qualified_name => "any:old")
191
- task = stub(:fully_qualified_name => "any:old:thing", :name => "thing", :namespace => ns)
192
- after_task = stub(:fully_qualified_name => "any:old:after_thing", :name => "after_thing", :namespace => ns)
193
-
194
- ns.stubs(:search_task).returns(nil)
195
- ns.expects(:search_task).with("after_thing").returns(after_task)
196
-
197
- @config.execute_task(task)
198
- assert_equal [task, after_task], @config.called
199
- end
200
-
201
- def test_execute_task_with_on_hooks_should_trigger_hooks_around_task
202
- ns = stub("namespace", :default_task => nil, :name => "old", :fully_qualified_name => "any:old")
203
- task = stub(:fully_qualified_name => "any:old:thing", :name => "thing", :namespace => ns)
204
- before_task = stub(:fully_qualified_name => "any:old:before_thing", :name => "before_thing", :namespace => ns)
205
- after_task = stub(:fully_qualified_name => "any:old:after_thing", :name => "after_thing", :namespace => ns)
206
-
207
- ns.stubs(:search_task).returns(nil)
208
- ns.expects(:search_task).with("before_thing").returns(before_task)
209
- ns.expects(:search_task).with("after_thing").returns(after_task)
210
-
211
- @config.before("any:old:thing", :first_this, :then_this)
212
- @config.after("any:old:thing", :and_then_this, :lastly_this)
213
-
214
- [:first_this, :then_this, :and_then_this, :lastly_this].each do |t|
215
- @config.expects(:find_and_execute_task).with(t)
216
- end
217
-
218
- @config.execute_task(task)
219
- end
220
- end