capistrano 2.8.0 → 3.19.0

Sign up to get free protection for your applications and to get access to all the features.
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,121 +0,0 @@
1
- require "utils"
2
- require 'capistrano/server_definition'
3
-
4
- class ServerDefinitionTest < Test::Unit::TestCase
5
- def test_new_without_credentials_or_port_should_set_values_to_defaults
6
- server = Capistrano::ServerDefinition.new("www.capistrano.test")
7
- assert_equal "www.capistrano.test", server.host
8
- assert_nil server.user
9
- assert_nil server.port
10
- end
11
-
12
- def test_new_with_encoded_user_should_extract_user_and_use_default_port
13
- server = Capistrano::ServerDefinition.new("jamis@www.capistrano.test")
14
- assert_equal "www.capistrano.test", server.host
15
- assert_equal "jamis", server.user
16
- assert_nil server.port
17
- end
18
-
19
- def test_new_with_encoded_port_should_extract_port_and_use_default_user
20
- server = Capistrano::ServerDefinition.new("www.capistrano.test:8080")
21
- assert_equal "www.capistrano.test", server.host
22
- assert_nil server.user
23
- assert_equal 8080, server.port
24
- end
25
-
26
- def test_new_with_encoded_user_and_port_should_extract_user_and_port
27
- server = Capistrano::ServerDefinition.new("jamis@www.capistrano.test:8080")
28
- assert_equal "www.capistrano.test", server.host
29
- assert_equal "jamis", server.user
30
- assert_equal 8080, server.port
31
- end
32
-
33
- def test_new_with_user_as_option_should_use_given_user
34
- server = Capistrano::ServerDefinition.new("www.capistrano.test", :user => "jamis")
35
- assert_equal "www.capistrano.test", server.host
36
- assert_equal "jamis", server.user
37
- assert_nil server.port
38
- end
39
-
40
- def test_new_with_port_as_option_should_use_given_user
41
- server = Capistrano::ServerDefinition.new("www.capistrano.test", :port => 8080)
42
- assert_equal "www.capistrano.test", server.host
43
- assert_nil server.user
44
- assert_equal 8080, server.port
45
- end
46
-
47
- def test_encoded_value_should_override_hash_option
48
- server = Capistrano::ServerDefinition.new("jamis@www.capistrano.test:8080", :user => "david", :port => 8081)
49
- assert_equal "www.capistrano.test", server.host
50
- assert_equal "jamis", server.user
51
- assert_equal 8080, server.port
52
- assert server.options.empty?
53
- end
54
-
55
- def test_new_with_option_should_dup_option_hash
56
- options = {}
57
- server = Capistrano::ServerDefinition.new("www.capistrano.test", options)
58
- assert_not_equal options.object_id, server.options.object_id
59
- end
60
-
61
- def test_new_with_options_should_keep_options
62
- server = Capistrano::ServerDefinition.new("www.capistrano.test", :primary => true)
63
- assert_equal true, server.options[:primary]
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
78
-
79
- def test_comparison_should_match_when_host_user_port_are_same
80
- s1 = server("jamis@www.capistrano.test:8080")
81
- s2 = server("www.capistrano.test", :user => "jamis", :port => 8080)
82
- assert_equal s1, s2
83
- assert_equal s1.hash, s2.hash
84
- assert s1.eql?(s2)
85
- end
86
-
87
- def test_servers_should_be_comparable
88
- s1 = server("jamis@www.capistrano.test:8080")
89
- s2 = server("www.alphabet.test:1234")
90
- s3 = server("jamis@www.capistrano.test:8075")
91
- s4 = server("billy@www.capistrano.test:8080")
92
-
93
- assert s2 < s1
94
- assert s3 < s1
95
- assert s4 < s1
96
- assert s2 < s3
97
- assert s2 < s4
98
- assert s3 < s4
99
- end
100
-
101
- def test_comparison_should_not_match_when_any_of_host_user_port_differ
102
- s1 = server("jamis@www.capistrano.test:8080")
103
- s2 = server("bob@www.capistrano.test:8080")
104
- s3 = server("jamis@www.capistrano.test:8081")
105
- s4 = server("jamis@app.capistrano.test:8080")
106
- assert_not_equal s1, s2
107
- assert_not_equal s1, s3
108
- assert_not_equal s1, s4
109
- assert_not_equal s2, s3
110
- assert_not_equal s2, s4
111
- assert_not_equal s3, s4
112
- end
113
-
114
- def test_to_s
115
- assert_equal "www.capistrano.test", server("www.capistrano.test").to_s
116
- assert_equal "www.capistrano.test", server("www.capistrano.test:22").to_s
117
- assert_equal "www.capistrano.test:1234", server("www.capistrano.test:1234").to_s
118
- assert_equal "jamis@www.capistrano.test", server("jamis@www.capistrano.test").to_s
119
- assert_equal "jamis@www.capistrano.test:1234", server("jamis@www.capistrano.test:1234").to_s
120
- end
121
- end
data/test/shell_test.rb DELETED
@@ -1,90 +0,0 @@
1
- require "utils"
2
- require 'capistrano/configuration'
3
- require 'capistrano/shell'
4
-
5
- class ShellTest < Test::Unit::TestCase
6
- def setup
7
- @config = Capistrano::Configuration.new
8
- @shell = Capistrano::Shell.new(@config)
9
- @shell.stubs(:puts)
10
- end
11
-
12
- def test_readline_fallback_prompt_should_write_to_stdout_and_read_from_stdin
13
- STDOUT.expects(:print).with("prompt> ")
14
- STDOUT.expects(:flush)
15
- STDIN.expects(:gets).returns("hi\n")
16
- assert_equal "hi\n", Capistrano::Shell::ReadlineFallback.readline("prompt> ")
17
- end
18
-
19
- def test_question_mark_as_input_should_trigger_help
20
- @shell.expects(:read_line).returns("?")
21
- @shell.expects(:help)
22
- assert @shell.read_and_execute
23
- end
24
-
25
- def test_help_as_input_should_trigger_help
26
- @shell.expects(:read_line).returns("help")
27
- @shell.expects(:help)
28
- assert @shell.read_and_execute
29
- end
30
-
31
- def test_quit_as_input_should_cause_read_and_execute_to_return_false
32
- @shell.expects(:read_line).returns("quit")
33
- assert !@shell.read_and_execute
34
- end
35
-
36
- def test_exit_as_input_should_cause_read_and_execute_to_return_false
37
- @shell.expects(:read_line).returns("exit")
38
- assert !@shell.read_and_execute
39
- end
40
-
41
- def test_set_should_parse_flag_and_value_and_call_set_option
42
- @shell.expects(:read_line).returns("set -v 5")
43
- @shell.expects(:set_option).with("v", "5")
44
- assert @shell.read_and_execute
45
- end
46
-
47
- def test_text_without_with_or_on_gets_processed_verbatim
48
- @shell.expects(:read_line).returns("hello world")
49
- @shell.expects(:process_command).with(nil, nil, "hello world")
50
- assert @shell.read_and_execute
51
- end
52
-
53
- def test_text_with_with_gets_processed_with_with # lol
54
- @shell.expects(:read_line).returns("with app,db hello world")
55
- @shell.expects(:process_command).with("with", "app,db", "hello world")
56
- assert @shell.read_and_execute
57
- end
58
-
59
- def test_text_with_on_gets_processed_with_on
60
- @shell.expects(:read_line).returns("on app,db hello world")
61
- @shell.expects(:process_command).with("on", "app,db", "hello world")
62
- assert @shell.read_and_execute
63
- end
64
-
65
- def test_task_command_with_bang_gets_processed_by_exec_tasks
66
- while_testing_post_exec_commands do
67
- @shell.expects(:read_line).returns("!deploy")
68
- @shell.expects(:exec_tasks).with(["deploy"])
69
- assert @shell.read_and_execute
70
- end
71
- end
72
-
73
- def test_normal_command_gets_processed_by_exec_command
74
- while_testing_post_exec_commands do
75
- @shell.expects(:read_line).returns("uptime")
76
- @shell.expects(:exec_command).with("uptime",nil)
77
- @shell.expects(:connect)
78
- assert @shell.read_and_execute
79
- end
80
- end
81
-
82
-
83
- private
84
-
85
- def while_testing_post_exec_commands(&block)
86
- @shell.instance_variable_set(:@mutex,Mutex.new)
87
- yield
88
- end
89
-
90
- end
data/test/ssh_test.rb DELETED
@@ -1,113 +0,0 @@
1
- require "utils"
2
- require 'capistrano/ssh'
3
-
4
- class SSHTest < Test::Unit::TestCase
5
- def setup
6
- Capistrano::ServerDefinition.stubs(:default_user).returns("default-user")
7
- @options = { :password => nil,
8
- :auth_methods => %w(publickey hostbased),
9
- :config => false }
10
- @server = server("capistrano")
11
- Net::SSH.stubs(:configuration_for).returns({})
12
- end
13
-
14
- def test_connect_with_bare_server_without_options_or_config_with_public_key_succeeding_should_only_loop_once
15
- Net::SSH.expects(:start).with(@server.host, "default-user", @options).returns(success = Object.new)
16
- assert_equal success, Capistrano::SSH.connect(@server)
17
- end
18
-
19
- def test_connect_with_bare_server_without_options_with_public_key_failing_should_try_password
20
- Net::SSH.expects(:start).with(@server.host, "default-user", @options).raises(Net::SSH::AuthenticationFailed)
21
- Net::SSH.expects(:start).with(@server.host, "default-user", @options.merge(:password => "f4b13n", :auth_methods => %w(password keyboard-interactive))).returns(success = Object.new)
22
- assert_equal success, Capistrano::SSH.connect(@server, :password => "f4b13n")
23
- end
24
-
25
- def test_connect_with_bare_server_without_options_public_key_and_password_failing_should_raise_error
26
- Net::SSH.expects(:start).with(@server.host, "default-user", @options).raises(Net::SSH::AuthenticationFailed)
27
- Net::SSH.expects(:start).with(@server.host, "default-user", @options.merge(:password => "f4b13n", :auth_methods => %w(password keyboard-interactive))).raises(Net::SSH::AuthenticationFailed)
28
- assert_raises(Net::SSH::AuthenticationFailed) do
29
- Capistrano::SSH.connect(@server, :password => "f4b13n")
30
- end
31
- end
32
-
33
- def test_connect_with_bare_server_and_user_via_public_key_should_pass_user_to_net_ssh
34
- Net::SSH.expects(:start).with(@server.host, "jamis", @options).returns(success = Object.new)
35
- assert_equal success, Capistrano::SSH.connect(@server, :user => "jamis")
36
- end
37
-
38
- def test_connect_with_bare_server_and_user_via_password_should_pass_user_to_net_ssh
39
- Net::SSH.expects(:start).with(@server.host, "jamis", @options).raises(Net::SSH::AuthenticationFailed)
40
- Net::SSH.expects(:start).with(@server.host, "jamis", @options.merge(:password => "f4b13n", :auth_methods => %w(password keyboard-interactive))).returns(success = Object.new)
41
- assert_equal success, Capistrano::SSH.connect(@server, :user => "jamis", :password => "f4b13n")
42
- end
43
-
44
- def test_connect_with_bare_server_with_explicit_port_should_pass_port_to_net_ssh
45
- Net::SSH.expects(:start).with(@server.host, "default-user", @options.merge(:port => 1234)).returns(success = Object.new)
46
- assert_equal success, Capistrano::SSH.connect(@server, :port => 1234)
47
- end
48
-
49
- def test_connect_with_server_with_user_should_pass_user_to_net_ssh
50
- server = server("jamis@capistrano")
51
- Net::SSH.expects(:start).with(server.host, "jamis", @options).returns(success = Object.new)
52
- assert_equal success, Capistrano::SSH.connect(server)
53
- end
54
-
55
- def test_connect_with_server_with_port_should_pass_port_to_net_ssh
56
- server = server("capistrano:1235")
57
- Net::SSH.expects(:start).with(server.host, "default-user", @options.merge(:port => 1235)).returns(success = Object.new)
58
- assert_equal success, Capistrano::SSH.connect(server)
59
- end
60
-
61
- def test_connect_with_server_with_user_and_port_should_pass_user_and_port_to_net_ssh
62
- server = server("jamis@capistrano:1235")
63
- Net::SSH.expects(:start).with(server.host, "jamis", @options.merge(:port => 1235)).returns(success = Object.new)
64
- assert_equal success, Capistrano::SSH.connect(server)
65
- end
66
-
67
- def test_connect_with_server_with_other_ssh_options_should_pass_ssh_options_to_net_ssh
68
- server = server("jamis@capistrano:1235", :ssh_options => { :keys => %w(some_valid_key), :auth_methods => %w(a_method), :hmac => 'none' })
69
- Net::SSH.expects(:start).with(server.host, "jamis", @options.merge(:port => 1235, :keys => %w(some_valid_key), :auth_methods => %w(a_method), :hmac => 'none' )).returns(success = Object.new)
70
- assert_equal success, Capistrano::SSH.connect(server)
71
- end
72
-
73
- def test_connect_with_ssh_options_should_use_ssh_options
74
- ssh_options = { :username => "JamisMan", :port => 8125, :config => false }
75
- Net::SSH.expects(:start).with(@server.host, "JamisMan", @options.merge(:port => 8125, :config => false)).returns(success = Object.new)
76
- assert_equal success, Capistrano::SSH.connect(@server, {:ssh_options => ssh_options})
77
- end
78
-
79
- def test_connect_with_options_and_ssh_options_should_see_options_override_ssh_options
80
- ssh_options = { :username => "JamisMan", :port => 8125, :forward_agent => true }
81
- Net::SSH.expects(:start).with(@server.host, "jamis", @options.merge(:port => 1235, :forward_agent => true)).returns(success = Object.new)
82
- assert_equal success, Capistrano::SSH.connect(@server, :ssh_options => ssh_options, :user => "jamis", :port => 1235)
83
- end
84
-
85
- def test_connect_with_verbose_option_should_set_verbose_option_on_ssh
86
- Net::SSH.expects(:start).with(@server.host, "default-user", @options).returns(success = Object.new)
87
- assert_equal success, Capistrano::SSH.connect(@server, :verbose => 0)
88
- Net::SSH.expects(:start).with(@server.host, "default-user", @options.merge(:verbose => :debug)).returns(success = Object.new)
89
- assert_equal success, Capistrano::SSH.connect(@server, :verbose => 1)
90
- Net::SSH.expects(:start).with(@server.host, "default-user", @options.merge(:verbose => :debug)).returns(success = Object.new)
91
- assert_equal success, Capistrano::SSH.connect(@server, :verbose => 2)
92
- end
93
-
94
- def test_connect_with_ssh_options_should_see_server_options_override_ssh_options
95
- ssh_options = { :username => "JamisMan", :port => 8125, :forward_agent => true }
96
- server = server("jamis@capistrano:1235")
97
- Net::SSH.expects(:start).with(server.host, "jamis", @options.merge(:port => 1235, :forward_agent => true, :config => false)).returns(success = Object.new)
98
- assert_equal success, Capistrano::SSH.connect(server, {:ssh_options => ssh_options})
99
- end
100
-
101
- def test_connect_should_add_xserver_accessor_to_connection
102
- Net::SSH.expects(:start).with(@server.host, "default-user", @options).returns(success = Object.new)
103
- assert_equal success, Capistrano::SSH.connect(@server)
104
- assert success.respond_to?(:xserver)
105
- assert success.respond_to?(:xserver)
106
- assert_equal success.xserver, @server
107
- end
108
-
109
- def test_connect_should_not_retry_if_custom_auth_methods_are_given
110
- Net::SSH.expects(:start).with(@server.host, "default-user", @options.merge(:auth_methods => %w(publickey))).raises(Net::SSH::AuthenticationFailed)
111
- assert_raises(Net::SSH::AuthenticationFailed) { Capistrano::SSH.connect(@server, :ssh_options => { :auth_methods => %w(publickey) }) }
112
- end
113
- end
@@ -1,116 +0,0 @@
1
- require "utils"
2
- require 'capistrano/task_definition'
3
-
4
- # Silences the wanrnings raised in the two deprecation tests
5
- $VERBOSE = nil
6
-
7
- class TaskDefinitionTest < Test::Unit::TestCase
8
- def setup
9
- @namespace = namespace
10
- end
11
-
12
- def test_fqn_at_top_level_should_be_task_name
13
- task = new_task(:testing)
14
- assert_equal "testing", task.fully_qualified_name
15
- end
16
-
17
- def test_fqn_in_namespace_should_include_namespace_fqn
18
- ns = namespace("outer:inner")
19
- task = new_task(:testing, ns)
20
- assert_equal "outer:inner:testing", task.fully_qualified_name
21
- end
22
-
23
- def test_fqn_at_top_level_when_default_should_be_default
24
- task = new_task(:default)
25
- assert_equal "default", task.fully_qualified_name
26
- end
27
-
28
- def test_deprecation_warning_on_method_name_beginning_with_before_underscore
29
- name = "before_test"
30
- Kernel.expects(:warn).with("[Deprecation Warning] Naming tasks with before_ and after_ is deprecated, please see the new before() and after() methods. (Offending task name was #{name})")
31
- new_task(name)
32
- end
33
-
34
- def test_deprecation_warning_on_method_name_beginning_with_after_underscore
35
- name = "after_test"
36
- Kernel.expects(:warn).with("[Deprecation Warning] Naming tasks with before_ and after_ is deprecated, please see the new before() and after() methods. (Offending task name was #{name})")
37
- new_task(name)
38
- end
39
-
40
- def test_fqn_in_namespace_when_default_should_be_namespace_fqn
41
- ns = namespace("outer:inner")
42
- task = new_task(:default, ns)
43
- ns.stubs(:default_task => task)
44
- assert_equal "outer:inner", task.fully_qualified_name
45
- end
46
-
47
- def test_task_should_require_block
48
- assert_raises(ArgumentError) do
49
- Capistrano::TaskDefinition.new(:testing, @namespace)
50
- end
51
- end
52
-
53
- def test_description_should_return_empty_string_if_not_given
54
- assert_equal "", new_task(:testing).description
55
- end
56
-
57
- def test_description_should_return_desc_attribute
58
- assert_equal "something", new_task(:testing, @namespace, :desc => "something").description
59
- end
60
-
61
- def test_description_should_strip_leading_and_trailing_whitespace
62
- assert_equal "something", new_task(:testing, @namespace, :desc => " something ").description
63
- end
64
-
65
- def test_description_should_normalize_newlines
66
- assert_equal "a\nb\nc", new_task(:testing, @namespace, :desc => "a\nb\r\nc").description
67
- end
68
-
69
- def test_description_should_detect_and_remove_indentation
70
- desc = <<-DESC
71
- Here is some indented text \
72
- and I want all of this to \
73
- run together on a single line, \
74
- without any extraneous spaces.
75
-
76
- additional indentation will
77
- be preserved.
78
- DESC
79
-
80
- task = new_task(:testing, @namespace, :desc => desc)
81
- assert_equal "Here is some indented text and I want all of this to run together on a single line, without any extraneous spaces.\n\n additional indentation will\n be preserved.", task.description
82
- end
83
-
84
- def test_description_munging_should_be_sensitive_to_code_blocks
85
- desc = <<-DESC
86
- Here is a line \
87
- wrapped with spacing in it.
88
-
89
- foo bar
90
- baz bang
91
- DESC
92
-
93
- task = new_task(:testing, @namespace, :desc => desc)
94
- assert_equal "Here is a line wrapped with spacing in it.\n\n foo bar\n baz bang", task.description
95
- end
96
-
97
- def test_brief_description_should_return_first_sentence_in_description
98
- desc = "This is the task. It does all kinds of things."
99
- task = new_task(:testing, @namespace, :desc => desc)
100
- assert_equal "This is the task.", task.brief_description
101
- end
102
-
103
- def test_brief_description_should_truncate_if_length_given
104
- desc = "This is the task that does all kinds of things. And then some."
105
- task = new_task(:testing, @namespace, :desc => desc)
106
- assert_equal "This is the task ...", task.brief_description(20)
107
- end
108
-
109
- def test_brief_description_should_not_break_at_period_in_middle_of_sentence
110
- task = new_task(:testing, @namespace, :desc => "Take file.txt and copy it.")
111
- assert_equal "Take file.txt and copy it.", task.brief_description
112
-
113
- task = new_task(:testing, @namespace, :desc => "Take file.txt and copy it. Then do something else.")
114
- assert_equal "Take file.txt and copy it.", task.brief_description
115
- end
116
- end
@@ -1,160 +0,0 @@
1
- require 'utils'
2
- require 'capistrano/transfer'
3
-
4
- class TransferTest < Test::Unit::TestCase
5
- def test_class_process_should_delegate_to_instance_process
6
- Capistrano::Transfer.expects(:new).with(:up, "from", "to", %w(a b c), {}).returns(mock('transfer', :process! => nil)).yields
7
- yielded = false
8
- Capistrano::Transfer.process(:up, "from", "to", %w(a b c), {}) { yielded = true }
9
- assert yielded
10
- end
11
-
12
- def test_default_transport_is_sftp
13
- transfer = Capistrano::Transfer.new(:up, "from", "to", [])
14
- assert_equal :sftp, transfer.transport
15
- end
16
-
17
- def test_active_is_true_when_any_sftp_transfers_are_active
18
- returns = [false, false, true]
19
- sessions = [session('app1', :sftp), session('app2', :sftp), session('app3', :sftp)].each { |s| s.xsftp.expects(:upload).returns(stub('operation', :active? => returns.shift)) }
20
- transfer = Capistrano::Transfer.new(:up, "from", "to", sessions, :via => :sftp)
21
- assert_equal true, transfer.active?
22
- end
23
-
24
- def test_active_is_false_when_all_sftp_transfers_are_not_active
25
- sessions = [session('app1', :sftp), session('app2', :sftp)].each { |s| s.xsftp.expects(:upload).returns(stub('operation', :active? => false)) }
26
- transfer = Capistrano::Transfer.new(:up, "from", "to", sessions, :via => :sftp)
27
- assert_equal false, transfer.active?
28
- end
29
-
30
- def test_active_is_true_when_any_scp_transfers_are_active
31
- returns = [false, false, true]
32
- sessions = [session('app1', :scp), session('app2', :scp), session('app3', :scp)].each do |s|
33
- channel = stub('channel', :[]= => nil, :active? => returns.shift)
34
- s.scp.expects(:upload).returns(channel)
35
- end
36
- transfer = Capistrano::Transfer.new(:up, "from", "to", sessions, :via => :scp)
37
- assert_equal true, transfer.active?
38
- end
39
-
40
- def test_active_is_false_when_all_scp_transfers_are_not_active
41
- sessions = [session('app1', :scp), session('app2', :scp), session('app3', :scp)].each do |s|
42
- channel = stub('channel', :[]= => nil, :active? => false)
43
- s.scp.expects(:upload).returns(channel)
44
- end
45
- transfer = Capistrano::Transfer.new(:up, "from", "to", sessions, :via => :scp)
46
- assert_equal false, transfer.active?
47
- end
48
-
49
- [:up, :down].each do |direction|
50
- define_method("test_sftp_#{direction}load_from_file_to_file_should_normalize_from_and_to") do
51
- sessions = [session('app1', :sftp), session('app2', :sftp)]
52
-
53
- sessions.each do |session|
54
- session.xsftp.expects("#{direction}load".to_sym).with("from-#{session.xserver.host}", "to-#{session.xserver.host}",
55
- :properties => { :server => session.xserver, :host => session.xserver.host })
56
- end
57
-
58
- transfer = Capistrano::Transfer.new(direction, "from-$CAPISTRANO:HOST$", "to-$CAPISTRANO:HOST$", sessions)
59
- end
60
-
61
- define_method("test_scp_#{direction}load_from_file_to_file_should_normalize_from_and_to") do
62
- sessions = [session('app1', :scp), session('app2', :scp)]
63
-
64
- sessions.each do |session|
65
- session.scp.expects("#{direction}load".to_sym).returns({}).with("from-#{session.xserver.host}", "to-#{session.xserver.host}", :via => :scp)
66
- end
67
-
68
- transfer = Capistrano::Transfer.new(direction, "from-$CAPISTRANO:HOST$", "to-$CAPISTRANO:HOST$", sessions, :via => :scp)
69
- end
70
- end
71
-
72
- def test_sftp_upload_from_IO_to_file_should_clone_the_IO_for_each_connection
73
- sessions = [session('app1', :sftp), session('app2', :sftp)]
74
- io = StringIO.new("from here")
75
-
76
- sessions.each do |session|
77
- session.xsftp.expects(:upload).with do |from, to, opts|
78
- from != io && from.is_a?(StringIO) && from.string == io.string &&
79
- to == "/to/here-#{session.xserver.host}" &&
80
- opts[:properties][:server] == session.xserver &&
81
- opts[:properties][:host] == session.xserver.host
82
- end
83
- end
84
-
85
- transfer = Capistrano::Transfer.new(:up, StringIO.new("from here"), "/to/here-$CAPISTRANO:HOST$", sessions)
86
- end
87
-
88
- def test_scp_upload_from_IO_to_file_should_clone_the_IO_for_each_connection
89
- sessions = [session('app1', :scp), session('app2', :scp)]
90
- io = StringIO.new("from here")
91
-
92
- sessions.each do |session|
93
- channel = mock('channel')
94
- channel.expects(:[]=).with(:server, session.xserver)
95
- channel.expects(:[]=).with(:host, session.xserver.host)
96
- session.scp.expects(:upload).returns(channel).with do |from, to, opts|
97
- from != io && from.is_a?(StringIO) && from.string == io.string &&
98
- to == "/to/here-#{session.xserver.host}"
99
- end
100
- end
101
-
102
- transfer = Capistrano::Transfer.new(:up, StringIO.new("from here"), "/to/here-$CAPISTRANO:HOST$", sessions, :via => :scp)
103
- end
104
-
105
- def test_process_should_block_until_transfer_is_no_longer_active
106
- transfer = Capistrano::Transfer.new(:up, "from", "to", [])
107
- transfer.expects(:process_iteration).times(4).yields.returns(true,true,true,false)
108
- transfer.expects(:active?).times(4)
109
- transfer.process!
110
- end
111
-
112
- def test_errors_raised_for_a_sftp_session_should_abort_session_and_continue_with_remaining_sessions
113
- s = session('app1')
114
- error = ExceptionWithSession.new(s)
115
- transfer = Capistrano::Transfer.new(:up, "from", "to", [])
116
- transfer.expects(:process_iteration).raises(error).times(3).returns(true, false)
117
- txfr = mock('transfer', :abort! => true)
118
- txfr.expects(:[]=).with(:failed, true)
119
- txfr.expects(:[]=).with(:error, error)
120
- transfer.expects(:session_map).returns(s => txfr)
121
- transfer.process!
122
- end
123
-
124
- def test_errors_raised_for_a_scp_session_should_abort_session_and_continue_with_remaining_sessions
125
- s = session('app1')
126
- error = ExceptionWithSession.new(s)
127
- transfer = Capistrano::Transfer.new(:up, "from", "to", [], :via => :scp)
128
- transfer.expects(:process_iteration).raises(error).times(3).returns(true, false)
129
- txfr = mock('channel', :close => true)
130
- txfr.expects(:[]=).with(:failed, true)
131
- txfr.expects(:[]=).with(:error, error)
132
- transfer.expects(:session_map).returns(s => txfr)
133
- transfer.process!
134
- end
135
-
136
- private
137
-
138
- class ExceptionWithSession < ::Exception
139
- attr_reader :session
140
-
141
- def initialize(session)
142
- @session = session
143
- super()
144
- end
145
- end
146
-
147
- def session(host, mode=nil)
148
- session = stub('session', :xserver => stub('server', :host => host))
149
- case mode
150
- when :sftp
151
- sftp = stub('sftp')
152
- session.expects(:sftp).with(false).returns(sftp)
153
- sftp.expects(:connect).yields(sftp).returns(sftp)
154
- session.stubs(:xsftp).returns(sftp)
155
- when :scp
156
- session.stubs(:scp).returns(stub('scp'))
157
- end
158
- session
159
- end
160
- end
data/test/utils.rb DELETED
@@ -1,37 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
-
4
- require 'ruby-debug'
5
- require 'test/unit'
6
- require 'mocha'
7
-
8
- require 'capistrano/server_definition'
9
-
10
- module TestExtensions
11
- def server(host, options={})
12
- Capistrano::ServerDefinition.new(host, options)
13
- end
14
-
15
- def namespace(fqn=nil)
16
- space = stub(:roles => {}, :fully_qualified_name => fqn, :default_task => nil)
17
- yield(space) if block_given?
18
- space
19
- end
20
-
21
- def role(space, name, *args)
22
- opts = args.last.is_a?(Hash) ? args.pop : {}
23
- space.roles[name] ||= []
24
- space.roles[name].concat(args.map { |h| Capistrano::ServerDefinition.new(h, opts) })
25
- end
26
-
27
- def new_task(name, namespace=@namespace, options={}, &block)
28
- block ||= Proc.new {}
29
- task = Capistrano::TaskDefinition.new(name, namespace, options, &block)
30
- assert_equal block, task.body
31
- return task
32
- end
33
- end
34
-
35
- class Test::Unit::TestCase
36
- include TestExtensions
37
- end