capistrano 2.15.11 → 3.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +17 -8
  3. data/Gemfile +1 -12
  4. data/LICENSE.txt +18 -0
  5. data/README.md +65 -68
  6. data/Rakefile +4 -10
  7. data/bin/cap +2 -3
  8. data/bin/capify +7 -91
  9. data/capistrano.gemspec +20 -34
  10. data/lib/Capfile +2 -0
  11. data/lib/capistrano/application.rb +28 -0
  12. data/lib/capistrano/bundler.rb +1 -0
  13. data/lib/capistrano/configuration/question.rb +42 -0
  14. data/lib/capistrano/configuration/server.rb +24 -0
  15. data/lib/capistrano/configuration/servers.rb +43 -95
  16. data/lib/capistrano/configuration.rb +81 -44
  17. data/lib/capistrano/console.rb +1 -0
  18. data/lib/capistrano/defaults.rb +11 -0
  19. data/lib/capistrano/deploy.rb +3 -0
  20. data/lib/capistrano/dotfile.rb +3 -0
  21. data/lib/capistrano/dsl/env.rb +57 -0
  22. data/lib/capistrano/dsl/paths.rb +74 -0
  23. data/lib/capistrano/dsl/stages.rb +15 -0
  24. data/lib/capistrano/dsl/task_enhancements.rb +15 -0
  25. data/lib/capistrano/dsl.rb +38 -0
  26. data/lib/capistrano/git.rb +1 -0
  27. data/lib/capistrano/i18n.rb +33 -0
  28. data/lib/capistrano/install.rb +1 -0
  29. data/lib/capistrano/setup.rb +17 -0
  30. data/lib/capistrano/tasks/bundler.rake +13 -0
  31. data/lib/capistrano/tasks/console.rake +21 -0
  32. data/lib/capistrano/tasks/deploy.rake +153 -0
  33. data/lib/capistrano/tasks/framework.rake +45 -0
  34. data/lib/capistrano/tasks/git.rake +65 -0
  35. data/lib/capistrano/tasks/install.rake +39 -0
  36. data/lib/capistrano/templates/Capfile +43 -0
  37. data/lib/capistrano/templates/deploy.rb.erb +17 -0
  38. data/lib/capistrano/templates/stage.rb.erb +20 -0
  39. data/lib/capistrano/version.rb +1 -11
  40. data/lib/capistrano.rb +9 -3
  41. data/spec/lib/capistrano/configuration/question_spec.rb +54 -0
  42. data/spec/lib/capistrano/configuration/server_spec.rb +48 -0
  43. data/spec/lib/capistrano/configuration/servers_spec.rb +79 -0
  44. data/spec/lib/capistrano/configuration_spec.rb +80 -0
  45. data/spec/lib/capistrano/dsl/env_spec.rb +83 -0
  46. data/spec/lib/capistrano/dsl/paths_spec.rb +69 -0
  47. data/spec/lib/capistrano/dsl_spec.rb +51 -0
  48. data/spec/lib/capistrano_spec.rb +8 -0
  49. data/spec/spec_helper.rb +14 -0
  50. metadata +89 -215
  51. data/.travis.yml +0 -9
  52. data/CHANGELOG +0 -1203
  53. data/lib/capistrano/callback.rb +0 -45
  54. data/lib/capistrano/cli/execute.rb +0 -85
  55. data/lib/capistrano/cli/help.rb +0 -125
  56. data/lib/capistrano/cli/help.txt +0 -81
  57. data/lib/capistrano/cli/options.rb +0 -243
  58. data/lib/capistrano/cli/ui.rb +0 -40
  59. data/lib/capistrano/cli.rb +0 -47
  60. data/lib/capistrano/command.rb +0 -303
  61. data/lib/capistrano/configuration/actions/file_transfer.rb +0 -50
  62. data/lib/capistrano/configuration/actions/inspect.rb +0 -46
  63. data/lib/capistrano/configuration/actions/invocation.rb +0 -329
  64. data/lib/capistrano/configuration/alias_task.rb +0 -26
  65. data/lib/capistrano/configuration/callbacks.rb +0 -147
  66. data/lib/capistrano/configuration/connections.rb +0 -237
  67. data/lib/capistrano/configuration/execution.rb +0 -142
  68. data/lib/capistrano/configuration/loading.rb +0 -205
  69. data/lib/capistrano/configuration/log_formatters.rb +0 -75
  70. data/lib/capistrano/configuration/namespaces.rb +0 -223
  71. data/lib/capistrano/configuration/roles.rb +0 -83
  72. data/lib/capistrano/configuration/variables.rb +0 -127
  73. data/lib/capistrano/errors.rb +0 -19
  74. data/lib/capistrano/ext/multistage.rb +0 -67
  75. data/lib/capistrano/ext/string.rb +0 -5
  76. data/lib/capistrano/extensions.rb +0 -57
  77. data/lib/capistrano/fix_rake_deprecated_dsl.rb +0 -8
  78. data/lib/capistrano/logger.rb +0 -166
  79. data/lib/capistrano/processable.rb +0 -55
  80. data/lib/capistrano/recipes/compat.rb +0 -32
  81. data/lib/capistrano/recipes/deploy/assets.rb +0 -202
  82. data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
  83. data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -54
  84. data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -117
  85. data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
  86. data/lib/capistrano/recipes/deploy/scm/base.rb +0 -200
  87. data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
  88. data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -153
  89. data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -96
  90. data/lib/capistrano/recipes/deploy/scm/git.rb +0 -299
  91. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -137
  92. data/lib/capistrano/recipes/deploy/scm/none.rb +0 -55
  93. data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -152
  94. data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -121
  95. data/lib/capistrano/recipes/deploy/scm.rb +0 -19
  96. data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -92
  97. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
  98. data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -338
  99. data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
  100. data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
  101. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -57
  102. data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +0 -21
  103. data/lib/capistrano/recipes/deploy/strategy.rb +0 -20
  104. data/lib/capistrano/recipes/deploy.rb +0 -625
  105. data/lib/capistrano/recipes/standard.rb +0 -37
  106. data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
  107. data/lib/capistrano/role.rb +0 -102
  108. data/lib/capistrano/server_definition.rb +0 -56
  109. data/lib/capistrano/shell.rb +0 -265
  110. data/lib/capistrano/ssh.rb +0 -95
  111. data/lib/capistrano/task_definition.rb +0 -77
  112. data/lib/capistrano/transfer.rb +0 -218
  113. data/test/cli/execute_test.rb +0 -132
  114. data/test/cli/help_test.rb +0 -165
  115. data/test/cli/options_test.rb +0 -329
  116. data/test/cli/ui_test.rb +0 -28
  117. data/test/cli_test.rb +0 -17
  118. data/test/command_test.rb +0 -322
  119. data/test/configuration/actions/file_transfer_test.rb +0 -61
  120. data/test/configuration/actions/inspect_test.rb +0 -76
  121. data/test/configuration/actions/invocation_test.rb +0 -306
  122. data/test/configuration/alias_task_test.rb +0 -118
  123. data/test/configuration/callbacks_test.rb +0 -201
  124. data/test/configuration/connections_test.rb +0 -439
  125. data/test/configuration/execution_test.rb +0 -175
  126. data/test/configuration/loading_test.rb +0 -148
  127. data/test/configuration/namespace_dsl_test.rb +0 -332
  128. data/test/configuration/roles_test.rb +0 -157
  129. data/test/configuration/servers_test.rb +0 -183
  130. data/test/configuration/variables_test.rb +0 -190
  131. data/test/configuration_test.rb +0 -77
  132. data/test/deploy/local_dependency_test.rb +0 -76
  133. data/test/deploy/remote_dependency_test.rb +0 -146
  134. data/test/deploy/scm/accurev_test.rb +0 -23
  135. data/test/deploy/scm/base_test.rb +0 -55
  136. data/test/deploy/scm/bzr_test.rb +0 -51
  137. data/test/deploy/scm/darcs_test.rb +0 -37
  138. data/test/deploy/scm/git_test.rb +0 -274
  139. data/test/deploy/scm/mercurial_test.rb +0 -134
  140. data/test/deploy/scm/none_test.rb +0 -35
  141. data/test/deploy/scm/perforce_test.rb +0 -23
  142. data/test/deploy/scm/subversion_test.rb +0 -68
  143. data/test/deploy/strategy/copy_test.rb +0 -360
  144. data/test/extensions_test.rb +0 -69
  145. data/test/fixtures/cli_integration.rb +0 -5
  146. data/test/fixtures/config.rb +0 -5
  147. data/test/fixtures/custom.rb +0 -3
  148. data/test/logger_formatting_test.rb +0 -149
  149. data/test/logger_test.rb +0 -134
  150. data/test/recipes_test.rb +0 -25
  151. data/test/role_test.rb +0 -11
  152. data/test/server_definition_test.rb +0 -121
  153. data/test/shell_test.rb +0 -96
  154. data/test/ssh_test.rb +0 -113
  155. data/test/task_definition_test.rb +0 -117
  156. data/test/transfer_test.rb +0 -168
  157. data/test/utils.rb +0 -37
  158. data/test/version_test.rb +0 -11
@@ -1,329 +0,0 @@
1
- require "utils"
2
- require 'capistrano/cli/options'
3
-
4
- class CLIOptionsTest < Test::Unit::TestCase
5
- class ExitException < Exception; end
6
-
7
- class MockCLI
8
- def initialize
9
- @args = []
10
- end
11
-
12
- attr_reader :args
13
-
14
- include Capistrano::CLI::Options
15
- end
16
-
17
- def setup
18
- @cli = MockCLI.new
19
- end
20
-
21
- def test_parse_options_should_require_non_empty_args_list
22
- @cli.stubs(:warn)
23
- @cli.expects(:exit).raises(ExitException)
24
- assert_raises(ExitException) { @cli.parse_options! }
25
- end
26
-
27
- def test_parse_options_with_d_should_set_debug_option
28
- @cli.args << "-d"
29
- @cli.parse_options!
30
- assert @cli.options[:debug]
31
- end
32
-
33
- def test_parse_options_with_n_should_set_dry_run_option
34
- @cli.args << "-n"
35
- @cli.parse_options!
36
- assert @cli.options[:dry_run]
37
- end
38
-
39
- def test_parse_options_with_dry_run_should_set_dry_run_option
40
- @cli.args << "--dry-run"
41
- @cli.parse_options!
42
- assert @cli.options[:dry_run]
43
- end
44
-
45
- def test_parse_options_with_e_should_set_explain_option
46
- @cli.args << "-e" << "sample"
47
- @cli.parse_options!
48
- assert_equal "sample", @cli.options[:explain]
49
- end
50
-
51
- def test_parse_options_with_f_should_add_recipe_file
52
- @cli.args << "-f" << "deploy"
53
- @cli.parse_options!
54
- assert_equal %w(deploy), @cli.options[:recipes]
55
- end
56
-
57
- def test_parse_options_with_multiple_f_should_add_each_as_recipe_file
58
- @cli.args << "-f" << "deploy" << "-f" << "monitor"
59
- @cli.parse_options!
60
- assert_equal %w(deploy monitor), @cli.options[:recipes]
61
- end
62
-
63
- def test_parse_options_with_H_should_show_verbose_help_and_exit
64
- @cli.expects(:exit).raises(ExitException)
65
- @cli.expects(:long_help)
66
- @cli.args << "-H"
67
- assert_raises(ExitException) { @cli.parse_options! }
68
- end
69
-
70
- def test_parse_options_with_h_should_show_options_and_exit
71
- @cli.expects(:puts).with(@cli.option_parser)
72
- @cli.expects(:exit).raises(ExitException)
73
- @cli.args << "-h"
74
- assert_raises(ExitException) { @cli.parse_options! }
75
- end
76
-
77
- def test_parse_options_with_p_should_prompt_for_password
78
- MockCLI.expects(:password_prompt).returns(:the_password)
79
- @cli.args << "-p"
80
- @cli.parse_options!
81
- assert_equal :the_password, @cli.options[:password]
82
- end
83
-
84
- def test_parse_options_without_p_should_set_proc_for_password
85
- @cli.args << "-e" << "sample"
86
- @cli.parse_options!
87
- assert_instance_of Proc, @cli.options[:password]
88
- end
89
-
90
- def test_parse_options_with_q_should_set_verbose_to_0
91
- @cli.args << "-q"
92
- @cli.parse_options!
93
- assert_equal 0, @cli.options[:verbose]
94
- end
95
-
96
- def test_parse_options_with_r_should_set_preserve_roles_option
97
- @cli.args << "-r"
98
- @cli.parse_options!
99
- assert @cli.options[:preserve_roles]
100
- end
101
-
102
- def test_parse_options_with_preserve_roles_should_set_preserve_roles_option
103
- @cli.args << "--preserve-roles"
104
- @cli.parse_options!
105
- assert @cli.options[:preserve_roles]
106
- end
107
-
108
- def test_parse_options_with_S_should_set_pre_vars
109
- @cli.args << "-S" << "foo=bar"
110
- @cli.parse_options!
111
- assert_equal "bar", @cli.options[:pre_vars][:foo]
112
- end
113
-
114
- def test_S_should_coerce_digits_to_integers
115
- @cli.args << "-S" << "foo=1234"
116
- @cli.parse_options!
117
- assert_equal 1234, @cli.options[:pre_vars][:foo]
118
- end
119
-
120
- def test_S_should_treat_quoted_integers_as_string
121
- @cli.args << "-S" << "foo=\"1234\""
122
- @cli.parse_options!
123
- assert_equal "1234", @cli.options[:pre_vars][:foo]
124
- end
125
-
126
- def test_S_should_treat_digits_with_dot_as_floating_point
127
- @cli.args << "-S" << "foo=3.1415"
128
- @cli.parse_options!
129
- assert_equal 3.1415, @cli.options[:pre_vars][:foo]
130
- end
131
-
132
- def test_S_should_treat_true_as_boolean_true
133
- @cli.args << "-S" << "foo=true"
134
- @cli.parse_options!
135
- assert_equal true, @cli.options[:pre_vars][:foo]
136
- end
137
-
138
- def test_S_should_treat_false_as_boolean_false
139
- @cli.args << "-S" << "foo=false"
140
- @cli.parse_options!
141
- assert_equal false, @cli.options[:pre_vars][:foo]
142
- end
143
-
144
- def test_S_should_treat_nil_as_nil
145
- @cli.args << "-S" << "foo=nil"
146
- @cli.parse_options!
147
- assert_equal nil, @cli.options[:pre_vars][:foo]
148
- end
149
-
150
- def test_parse_options_with_s_should_set_vars
151
- @cli.args << "-s" << "foo=bar"
152
- @cli.parse_options!
153
- assert_equal "bar", @cli.options[:vars][:foo]
154
- end
155
-
156
- def test_s_should_coerce_digits_to_integers
157
- @cli.args << "-s" << "foo=1234"
158
- @cli.parse_options!
159
- assert_equal 1234, @cli.options[:vars][:foo]
160
- end
161
-
162
- def test_s_should_treat_quoted_integers_as_string
163
- @cli.args << "-s" << "foo=\"1234\""
164
- @cli.parse_options!
165
- assert_equal "1234", @cli.options[:vars][:foo]
166
- end
167
-
168
- def test_s_should_treat_digits_with_dot_as_floating_point
169
- @cli.args << "-s" << "foo=3.1415"
170
- @cli.parse_options!
171
- assert_equal 3.1415, @cli.options[:vars][:foo]
172
- end
173
-
174
- def test_s_should_treat_true_as_boolean_true
175
- @cli.args << "-s" << "foo=true"
176
- @cli.parse_options!
177
- assert_equal true, @cli.options[:vars][:foo]
178
- end
179
-
180
- def test_s_should_treat_false_as_boolean_false
181
- @cli.args << "-s" << "foo=false"
182
- @cli.parse_options!
183
- assert_equal false, @cli.options[:vars][:foo]
184
- end
185
-
186
- def test_s_should_treat_nil_as_nil
187
- @cli.args << "-s" << "foo=nil"
188
- @cli.parse_options!
189
- assert_equal nil, @cli.options[:vars][:foo]
190
- end
191
-
192
- def test_parse_options_with_T_should_set_tasks_option_and_set_verbose_off
193
- @cli.args << "-T"
194
- @cli.parse_options!
195
- assert @cli.options[:tasks]
196
- assert_equal 0, @cli.options[:verbose]
197
- end
198
-
199
- def test_parse_options_with_V_should_show_version_and_exit
200
- @cli.args << "-V"
201
- @cli.expects(:puts).with { |s| s.include?(Capistrano::Version.to_s) }
202
- @cli.expects(:exit).raises(ExitException)
203
- assert_raises(ExitException) { @cli.parse_options! }
204
- end
205
-
206
- def test_parse_options_with_v_should_set_verbose_to_1
207
- @cli.args << "-v"
208
- @cli.parse_options!
209
- assert_equal 1, @cli.options[:verbose]
210
- end
211
-
212
- def test_parse_options_with_multiple_v_should_set_verbose_accordingly
213
- @cli.args << "-vvvvvvv"
214
- @cli.parse_options!
215
- assert_equal 7, @cli.options[:verbose]
216
- end
217
-
218
- def test_parse_options_without_X_should_set_sysconf
219
- @cli.args << "-v"
220
- @cli.parse_options!
221
- assert @cli.options.key?(:sysconf)
222
- end
223
-
224
- def test_parse_options_with_X_should_unset_sysconf
225
- @cli.args << "-X"
226
- @cli.parse_options!
227
- assert !@cli.options.key?(:sysconf)
228
- end
229
-
230
- def test_parse_options_without_x_should_set_dotfile
231
- @cli.args << "-v"
232
- @cli.parse_options!
233
- assert @cli.options.key?(:dotfile)
234
- end
235
-
236
- def test_parse_options_with_x_should_unset_dotfile
237
- @cli.args << "-x"
238
- @cli.parse_options!
239
- assert !@cli.options.key?(:dotfile)
240
- end
241
-
242
- def test_parse_options_without_q_or_v_should_set_verbose_to_3
243
- @cli.args << "-x"
244
- @cli.parse_options!
245
- assert_equal 3, @cli.options[:verbose]
246
- end
247
-
248
- def test_should_search_for_default_recipes_if_f_not_given
249
- @cli.expects(:look_for_default_recipe_file!)
250
- @cli.args << "-v"
251
- @cli.parse_options!
252
- end
253
-
254
- def test_should_not_search_for_default_recipes_if_f_given
255
- @cli.expects(:look_for_default_recipe_file!).never
256
- @cli.args << "-f" << "hello"
257
- @cli.parse_options!
258
- end
259
-
260
- def test_F_should_search_for_default_recipes_even_if_f_is_given
261
- @cli.expects(:look_for_default_recipe_file!)
262
- @cli.args << "-Ff" << "hello"
263
- @cli.parse_options!
264
- end
265
-
266
- def test_should_extract_env_vars_from_command_line
267
- assert_nil ENV["HELLO"]
268
- assert_nil ENV["ANOTHER"]
269
-
270
- @cli.args << "HELLO=world" << "hello" << "ANOTHER=value"
271
- @cli.parse_options!
272
-
273
- assert_equal "world", ENV["HELLO"]
274
- assert_equal "value", ENV["ANOTHER"]
275
- ensure
276
- ENV.delete("HELLO")
277
- ENV.delete("ANOTHER")
278
- end
279
-
280
- def test_remaining_args_should_be_added_to_actions_list
281
- @cli.args << "-v" << "HELLO=world" << "-f" << "foo" << "something" << "else"
282
- @cli.parse_options!
283
- assert_equal %w(something else), @cli.args
284
- ensure
285
- ENV.delete("HELLO")
286
- end
287
-
288
- def test_search_for_default_recipe_file_should_look_for_Capfile
289
- File.stubs(:file?).returns(false)
290
- File.expects(:file?).with("Capfile").returns(true)
291
- @cli.args << "-v"
292
- @cli.parse_options!
293
- assert_equal %w(Capfile), @cli.options[:recipes]
294
- end
295
-
296
- def test_search_for_default_recipe_file_should_look_for_capfile
297
- File.stubs(:file?).returns(false)
298
- File.expects(:file?).with("capfile").returns(true)
299
- @cli.args << "-v"
300
- @cli.parse_options!
301
- assert_equal %w(capfile), @cli.options[:recipes]
302
- end
303
-
304
- def test_search_for_default_recipe_should_hike_up_the_directory_tree_until_it_finds_default_recipe
305
- File.stubs(:file?).returns(false)
306
- File.expects(:file?).with("capfile").times(2).returns(false,true)
307
- Dir.expects(:pwd).times(3).returns(*%w(/bar/baz /bar/baz /bar))
308
- Dir.expects(:chdir).with("..")
309
- @cli.args << "-v"
310
- @cli.parse_options!
311
- assert_equal %w(capfile), @cli.options[:recipes]
312
- end
313
-
314
- def test_search_for_default_recipe_should_halt_at_root_directory
315
- File.stubs(:file?).returns(false)
316
- Dir.expects(:pwd).times(7).returns(*%w(/bar/baz /bar/baz /bar /bar / / /))
317
- Dir.expects(:chdir).with("..").times(3)
318
- Dir.expects(:chdir).with("/bar/baz")
319
- @cli.args << "-v"
320
- @cli.parse_options!
321
- assert @cli.options[:recipes].empty?
322
- end
323
-
324
- def test_parse_should_instantiate_new_cli_and_call_parse_options
325
- cli = mock("cli", :parse_options! => nil)
326
- MockCLI.expects(:new).with(%w(a b c)).returns(cli)
327
- assert_equal cli, MockCLI.parse(%w(a b c))
328
- end
329
- end
data/test/cli/ui_test.rb DELETED
@@ -1,28 +0,0 @@
1
- require "utils"
2
- require 'capistrano/cli/ui'
3
-
4
- class CLIUITest < Test::Unit::TestCase
5
- class MockCLI
6
- include Capistrano::CLI::UI
7
- end
8
-
9
- def test_ui_should_return_highline_instance
10
- assert_instance_of HighLine, MockCLI.ui
11
- end
12
-
13
- def test_password_prompt_should_have_default_prompt_and_set_echo_false
14
- q = mock("question")
15
- q.expects(:echo=).with(false)
16
- ui = mock("ui")
17
- ui.expects(:ask).with("Password: ").yields(q).returns("sayuncle")
18
- MockCLI.expects(:ui).returns(ui)
19
- assert_equal "sayuncle", MockCLI.password_prompt
20
- end
21
-
22
- def test_password_prompt_with_custom_prompt_should_use_custom_prompt
23
- ui = mock("ui")
24
- ui.expects(:ask).with("Give the passphrase: ").returns("sayuncle")
25
- MockCLI.expects(:ui).returns(ui)
26
- assert_equal "sayuncle", MockCLI.password_prompt("Give the passphrase: ")
27
- end
28
- end
data/test/cli_test.rb DELETED
@@ -1,17 +0,0 @@
1
- require "utils"
2
- require 'capistrano/cli'
3
-
4
- class CLI_Test < Test::Unit::TestCase
5
- def test_options_ui_and_help_modules_should_integrate_successfully_with_configuration
6
- cli = Capistrano::CLI.parse(%w(-T -x -X))
7
- cli.expects(:puts).at_least_once
8
- cli.execute!
9
- end
10
-
11
- def test_options_and_execute_modules_should_integrate_successfully_with_configuration
12
- path = "#{File.dirname(__FILE__)}/fixtures/cli_integration.rb"
13
- cli = Capistrano::CLI.parse(%W(-x -X -q -f #{path} testing))
14
- config = cli.execute!
15
- assert config[:testing_occurred]
16
- end
17
- end
data/test/command_test.rb DELETED
@@ -1,322 +0,0 @@
1
- require "utils"
2
- require 'capistrano/command'
3
- require 'capistrano/configuration'
4
-
5
- class CommandTest < Test::Unit::TestCase
6
- def test_command_should_open_channels_on_all_sessions
7
- s1, s2, s3 = mock_session, mock_session, mock_session
8
- assert_equal "ls", Capistrano::Command.new("ls", [s1, s2, s3]).tree.fallback.command
9
- end
10
-
11
- def test_command_with_newlines_should_be_properly_escaped
12
- cmd = Capistrano::Command.new("ls\necho", [mock_session])
13
- assert_equal "ls\\\necho", cmd.tree.fallback.command
14
- end
15
-
16
- def test_command_with_windows_newlines_should_be_properly_escaped
17
- cmd = Capistrano::Command.new("ls\r\necho", [mock_session])
18
- assert_equal "ls\\\necho", cmd.tree.fallback.command
19
- end
20
-
21
- def test_command_with_pty_should_request_pty_and_register_success_callback
22
- session = setup_for_extracting_channel_action(:request_pty, true) do |ch|
23
- ch.expects(:exec).with(%(sh -c 'ls'))
24
- end
25
- Capistrano::Command.new("ls", [session], :pty => true)
26
- end
27
-
28
- def test_command_with_env_key_should_have_environment_constructed_and_prepended
29
- session = setup_for_extracting_channel_action do |ch|
30
- ch.expects(:request_pty).never
31
- ch.expects(:exec).with(%(env FOO=bar sh -c 'ls'))
32
- end
33
- Capistrano::Command.new("ls", [session], :env => { "FOO" => "bar" })
34
- end
35
-
36
- def test_env_with_symbolic_key_should_be_accepted_as_a_string
37
- session = setup_for_extracting_channel_action do |ch|
38
- ch.expects(:exec).with(%(env FOO=bar sh -c 'ls'))
39
- end
40
- Capistrano::Command.new("ls", [session], :env => { :FOO => "bar" })
41
- end
42
-
43
- def test_env_as_string_should_be_substituted_in_directly
44
- session = setup_for_extracting_channel_action do |ch|
45
- ch.expects(:exec).with(%(env HOWDY=there sh -c 'ls'))
46
- end
47
- Capistrano::Command.new("ls", [session], :env => "HOWDY=there")
48
- end
49
-
50
- def test_env_with_symbolic_value_should_be_accepted_as_string
51
- session = setup_for_extracting_channel_action do |ch|
52
- ch.expects(:exec).with(%(env FOO=bar sh -c 'ls'))
53
- end
54
- Capistrano::Command.new("ls", [session], :env => { "FOO" => :bar })
55
- end
56
-
57
- def test_env_value_should_be_escaped
58
- session = setup_for_extracting_channel_action do |ch|
59
- ch.expects(:exec).with(%(env FOO=(\\ \\\"bar\\\"\\ ) sh -c 'ls'))
60
- end
61
- Capistrano::Command.new("ls", [session], :env => { "FOO" => '( "bar" )' })
62
- end
63
-
64
- def test_env_with_multiple_keys_should_chain_the_entries_together
65
- session = setup_for_extracting_channel_action do |ch|
66
- ch.expects(:exec).with do |command|
67
- command =~ /^env / &&
68
- command =~ /\ba=b\b/ &&
69
- command =~ /\bc=d\b/ &&
70
- command =~ /\be=f\b/ &&
71
- command =~ / sh -c 'ls'$/
72
- end
73
- end
74
- Capistrano::Command.new("ls", [session], :env => { :a => :b, :c => :d, :e => :f })
75
- end
76
-
77
- def test_open_channel_should_set_host_key_on_channel
78
- channel = nil
79
- session = setup_for_extracting_channel_action { |ch| channel = ch }
80
- Capistrano::Command.new("ls", [session])
81
- assert_equal "capistrano", channel[:host]
82
- end
83
-
84
- def test_open_channel_should_set_options_key_on_channel
85
- channel = nil
86
- session = setup_for_extracting_channel_action { |ch| channel = ch }
87
- Capistrano::Command.new("ls", [session], :data => "here we go")
88
- assert_equal({ :data => 'here we go' }, channel[:options])
89
- end
90
-
91
- def test_successful_channel_should_send_command
92
- session = setup_for_extracting_channel_action do |ch|
93
- ch.expects(:exec).with(%(sh -c 'ls'))
94
- end
95
- Capistrano::Command.new("ls", [session])
96
- end
97
-
98
- def test_successful_channel_with_shell_option_should_send_command_via_specified_shell
99
- session = setup_for_extracting_channel_action do |ch|
100
- ch.expects(:exec).with(%(/bin/bash -c 'ls'))
101
- end
102
- Capistrano::Command.new("ls", [session], :shell => "/bin/bash")
103
- end
104
-
105
- def test_successful_channel_with_shell_false_should_send_command_without_shell
106
- session = setup_for_extracting_channel_action do |ch|
107
- ch.expects(:exec).with(%(echo `hostname`))
108
- end
109
- Capistrano::Command.new("echo `hostname`", [session], :shell => false)
110
- end
111
-
112
- def test_successful_channel_should_send_data_if_data_key_is_present
113
- session = setup_for_extracting_channel_action do |ch|
114
- ch.expects(:exec).with(%(sh -c 'ls'))
115
- ch.expects(:send_data).with("here we go")
116
- end
117
- Capistrano::Command.new("ls", [session], :data => "here we go")
118
- end
119
-
120
- def test_unsuccessful_pty_request_should_close_channel
121
- session = setup_for_extracting_channel_action(:request_pty, false) do |ch|
122
- ch.expects(:close)
123
- end
124
- Capistrano::Command.new("ls", [session], :pty => true)
125
- end
126
-
127
- def test_on_data_should_invoke_callback_as_stdout
128
- session = setup_for_extracting_channel_action(:on_data, "hello")
129
- called = false
130
- Capistrano::Command.new("ls", [session]) do |ch, stream, data|
131
- called = true
132
- assert_equal :out, stream
133
- assert_equal "hello", data
134
- end
135
- assert called
136
- end
137
-
138
- def test_on_extended_data_should_invoke_callback_as_stderr
139
- session = setup_for_extracting_channel_action(:on_extended_data, 2, "hello")
140
- called = false
141
- Capistrano::Command.new("ls", [session]) do |ch, stream, data|
142
- called = true
143
- assert_equal :err, stream
144
- assert_equal "hello", data
145
- end
146
- assert called
147
- end
148
-
149
- def test_on_request_should_record_exit_status
150
- data = mock(:read_long => 5)
151
- channel = nil
152
- session = setup_for_extracting_channel_action([:on_request, "exit-status"], data) { |ch| channel = ch }
153
- Capistrano::Command.new("ls", [session])
154
- assert_equal 5, channel[:status]
155
- end
156
-
157
- def test_on_request_should_log_exit_signal_if_logger_present
158
- data = mock(:read_string => "TERM")
159
- logger = stub_everything
160
-
161
- session = setup_for_extracting_channel_action([:on_request, "exit-signal"], data)
162
- logger.expects(:important).with("command received signal TERM", server("capistrano"))
163
-
164
- Capistrano::Command.new("puppet", [session], :logger => logger)
165
- end
166
-
167
- def test_on_close_should_set_channel_closed
168
- channel = nil
169
- session = setup_for_extracting_channel_action(:on_close) { |ch| channel = ch }
170
- Capistrano::Command.new("ls", [session])
171
- assert channel[:closed]
172
- end
173
-
174
- def test_stop_should_close_all_open_channels
175
- sessions = [mock_session(new_channel(false)),
176
- mock_session(new_channel(true)),
177
- mock_session(new_channel(false))]
178
-
179
- cmd = Capistrano::Command.new("ls", sessions)
180
- cmd.stop!
181
- end
182
-
183
- def test_process_should_return_cleanly_if_all_channels_have_zero_exit_status
184
- sessions = [mock_session(new_channel(true, 0)),
185
- mock_session(new_channel(true, 0)),
186
- mock_session(new_channel(true, 0))]
187
- cmd = Capistrano::Command.new("ls", sessions)
188
- assert_nothing_raised { cmd.process! }
189
- end
190
-
191
- def test_process_should_raise_error_if_any_channel_has_non_zero_exit_status
192
- sessions = [mock_session(new_channel(true, 0)),
193
- mock_session(new_channel(true, 0)),
194
- mock_session(new_channel(true, 1))]
195
- cmd = Capistrano::Command.new("ls", sessions)
196
- assert_raises(Capistrano::CommandError) { cmd.process! }
197
- end
198
-
199
- def test_command_error_should_include_accessor_with_host_array
200
- sessions = [mock_session(new_channel(true, 0)),
201
- mock_session(new_channel(true, 0)),
202
- mock_session(new_channel(true, 1))]
203
- cmd = Capistrano::Command.new("ls", sessions)
204
-
205
- begin
206
- cmd.process!
207
- flunk "expected an exception to be raised"
208
- rescue Capistrano::CommandError => e
209
- assert e.respond_to?(:hosts)
210
- assert_equal %w(capistrano), e.hosts.map { |h| h.to_s }
211
- end
212
- end
213
-
214
- def test_process_should_loop_until_all_channels_are_closed
215
- new_channel = Proc.new do |times|
216
- ch = mock("channel")
217
- returns = [false] * (times-1)
218
- ch.stubs(:to_ary)
219
- ch.stubs(:[]).with(:closed).returns(*(returns + [true]))
220
- ch.expects(:[]).with(:status).returns(0)
221
- ch
222
- end
223
-
224
- sessions = [mock_session(new_channel[5]),
225
- mock_session(new_channel[10]),
226
- mock_session(new_channel[7])]
227
- cmd = Capistrano::Command.new("ls", sessions)
228
- assert_nothing_raised do
229
- cmd.process!
230
- end
231
- end
232
-
233
- def test_process_should_instantiate_command_and_process!
234
- cmd = mock("command", :process! => nil)
235
- Capistrano::Command.expects(:new).with("ls -l", %w(a b c), {:foo => "bar"}).returns(cmd)
236
- Capistrano::Command.process("ls -l", %w(a b c), :foo => "bar")
237
- end
238
-
239
- def test_process_with_host_placeholder_should_substitute_host_placeholder_with_each_host
240
- session = setup_for_extracting_channel_action do |ch|
241
- ch.expects(:exec).with(%(sh -c 'echo capistrano'))
242
- end
243
- Capistrano::Command.new("echo $CAPISTRANO:HOST$", [session])
244
- end
245
-
246
- class MockConfig
247
- include Capistrano::Configuration::Roles
248
- end
249
-
250
- def test_hostroles_substitution
251
- @config = MockConfig.new
252
- @config.server "capistrano", :db, :worker
253
- server = @config.roles[:db].servers.first
254
- channel = {:server => server, :host => 'capistrano'}
255
- tree = Capistrano::Command::Tree.new(@config) { |t| t.else("echo $CAPISTRANO:HOSTROLES$") }
256
- result = Capistrano::Command.new(tree, []).send(:replace_placeholders, "echo $CAPISTRANO:HOSTROLES$", channel)
257
- assert result == "echo db,worker" || result == "echo worker,db"
258
- end
259
-
260
- def test_process_with_unknown_placeholder_should_not_replace_placeholder
261
- session = setup_for_extracting_channel_action do |ch|
262
- ch.expects(:exec).with(%(sh -c 'echo $CAPISTRANO:OTHER$'))
263
- end
264
- Capistrano::Command.new("echo $CAPISTRANO:OTHER$", [session])
265
- end
266
-
267
- def test_input_stream_closed_when_eof_option_is_true
268
- channel = nil
269
- session = setup_for_extracting_channel_action { |ch| channel = ch }
270
- channel.expects(:eof!)
271
- Capistrano::Command.new("cat", [session], :data => "here we go", :eof => true)
272
- assert_equal({ :data => 'here we go', :eof => true }, channel[:options])
273
- end
274
-
275
- private
276
-
277
- def mock_session(channel=nil)
278
- stub('session',
279
- :open_channel => channel,
280
- :preprocess => true,
281
- :postprocess => true,
282
- :listeners => {},
283
- :xserver => server("capistrano"))
284
- end
285
-
286
- class MockChannel < Hash
287
- def close
288
- end
289
- end
290
-
291
- def new_channel(closed, status=nil)
292
- ch = MockChannel.new
293
- ch.update({ :closed => closed, :host => "capistrano", :server => server("capistrano") })
294
- ch[:status] = status if status
295
- ch.expects(:close) unless closed
296
- ch
297
- end
298
-
299
- def setup_for_extracting_channel_action(action=nil, *args)
300
- s = server("capistrano")
301
- session = mock("session", :xserver => s)
302
-
303
- channel = {}
304
- session.expects(:open_channel).yields(channel)
305
-
306
- channel.stubs(:on_data)
307
- channel.stubs(:on_extended_data)
308
- channel.stubs(:on_request)
309
- channel.stubs(:on_close)
310
- channel.stubs(:exec)
311
- channel.stubs(:send_data)
312
-
313
- if action
314
- action = Array(action)
315
- channel.expects(action.first).with(*action[1..-1]).yields(channel, *args)
316
- end
317
-
318
- yield channel if block_given?
319
-
320
- session
321
- end
322
- end