capistrano 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +7 -0
  4. data/CHANGELOG.md +89 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +674 -0
  7. data/README.md +226 -0
  8. data/Rakefile +5 -0
  9. data/bin/cap +2 -3
  10. data/bin/capify +7 -77
  11. data/capistrano-public_cert.pem +22 -0
  12. data/capistrano.gemspec +35 -0
  13. data/features/deploy.feature +52 -0
  14. data/features/installation.feature +16 -0
  15. data/features/remote_file_task.feature +14 -0
  16. data/features/step_definitions/assertions.rb +90 -0
  17. data/features/step_definitions/cap_commands.rb +8 -0
  18. data/features/step_definitions/setup.rb +25 -0
  19. data/features/support/env.rb +12 -0
  20. data/features/support/remote_command_helpers.rb +20 -0
  21. data/lib/Capfile +3 -0
  22. data/lib/capistrano/all.rb +16 -0
  23. data/lib/capistrano/application.rb +60 -0
  24. data/lib/capistrano/configuration/question.rb +42 -0
  25. data/lib/capistrano/configuration/server.rb +133 -0
  26. data/lib/capistrano/configuration/servers/role_filter.rb +86 -0
  27. data/lib/capistrano/configuration/servers.rb +53 -58
  28. data/lib/capistrano/configuration.rb +84 -30
  29. data/lib/capistrano/console.rb +1 -0
  30. data/lib/capistrano/defaults.rb +13 -0
  31. data/lib/capistrano/deploy.rb +3 -0
  32. data/lib/capistrano/dotfile.rb +3 -0
  33. data/lib/capistrano/dsl/env.rb +64 -0
  34. data/lib/capistrano/dsl/paths.rb +94 -0
  35. data/lib/capistrano/dsl/stages.rb +15 -0
  36. data/lib/capistrano/dsl/task_enhancements.rb +53 -0
  37. data/lib/capistrano/dsl.rb +48 -0
  38. data/lib/capistrano/git.rb +1 -0
  39. data/lib/capistrano/hg.rb +1 -0
  40. data/lib/capistrano/i18n.rb +34 -0
  41. data/lib/capistrano/install.rb +1 -0
  42. data/lib/capistrano/setup.rb +21 -0
  43. data/lib/capistrano/tasks/console.rake +21 -0
  44. data/lib/capistrano/tasks/deploy.rake +204 -0
  45. data/lib/capistrano/tasks/framework.rake +67 -0
  46. data/lib/capistrano/tasks/git.rake +62 -0
  47. data/lib/capistrano/tasks/hg.rake +39 -0
  48. data/lib/capistrano/tasks/install.rake +39 -0
  49. data/lib/capistrano/templates/Capfile +26 -0
  50. data/lib/capistrano/templates/deploy.rb.erb +40 -0
  51. data/lib/capistrano/templates/stage.rb.erb +42 -0
  52. data/lib/capistrano/version.rb +1 -20
  53. data/lib/capistrano/version_validator.rb +37 -0
  54. data/lib/capistrano.rb +0 -2
  55. data/spec/integration/dsl_spec.rb +344 -0
  56. data/spec/integration_spec_helper.rb +7 -0
  57. data/spec/lib/capistrano/application_spec.rb +61 -0
  58. data/spec/lib/capistrano/configuration/question_spec.rb +54 -0
  59. data/spec/lib/capistrano/configuration/server_spec.rb +249 -0
  60. data/spec/lib/capistrano/configuration/servers/role_filter_spec.rb +140 -0
  61. data/spec/lib/capistrano/configuration/servers_spec.rb +184 -0
  62. data/spec/lib/capistrano/configuration_spec.rb +101 -0
  63. data/spec/lib/capistrano/dsl/env_spec.rb +10 -0
  64. data/spec/lib/capistrano/dsl/paths_spec.rb +69 -0
  65. data/spec/lib/capistrano/dsl_spec.rb +63 -0
  66. data/spec/lib/capistrano/version_validator_spec.rb +103 -0
  67. data/spec/lib/capistrano_spec.rb +8 -0
  68. data/spec/spec_helper.rb +15 -0
  69. data/spec/support/.gitignore +1 -0
  70. data/spec/support/Vagrantfile +13 -0
  71. data/spec/support/matchers.rb +5 -0
  72. data/spec/support/tasks/database.cap +11 -0
  73. data/spec/support/test_app.rb +138 -0
  74. metadata +251 -179
  75. data/CHANGELOG +0 -512
  76. data/MIT-LICENSE +0 -20
  77. data/README +0 -43
  78. data/examples/sample.rb +0 -14
  79. data/lib/capistrano/callback.rb +0 -45
  80. data/lib/capistrano/cli/execute.rb +0 -82
  81. data/lib/capistrano/cli/help.rb +0 -102
  82. data/lib/capistrano/cli/help.txt +0 -53
  83. data/lib/capistrano/cli/options.rb +0 -183
  84. data/lib/capistrano/cli/ui.rb +0 -28
  85. data/lib/capistrano/cli.rb +0 -47
  86. data/lib/capistrano/command.rb +0 -161
  87. data/lib/capistrano/configuration/actions/file_transfer.rb +0 -35
  88. data/lib/capistrano/configuration/actions/inspect.rb +0 -46
  89. data/lib/capistrano/configuration/actions/invocation.rb +0 -134
  90. data/lib/capistrano/configuration/callbacks.rb +0 -148
  91. data/lib/capistrano/configuration/connections.rb +0 -159
  92. data/lib/capistrano/configuration/execution.rb +0 -126
  93. data/lib/capistrano/configuration/loading.rb +0 -198
  94. data/lib/capistrano/configuration/namespaces.rb +0 -196
  95. data/lib/capistrano/configuration/roles.rb +0 -51
  96. data/lib/capistrano/configuration/variables.rb +0 -127
  97. data/lib/capistrano/errors.rb +0 -15
  98. data/lib/capistrano/extensions.rb +0 -57
  99. data/lib/capistrano/gateway.rb +0 -131
  100. data/lib/capistrano/logger.rb +0 -59
  101. data/lib/capistrano/recipes/compat.rb +0 -32
  102. data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
  103. data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -46
  104. data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -96
  105. data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
  106. data/lib/capistrano/recipes/deploy/scm/base.rb +0 -192
  107. data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
  108. data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -151
  109. data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -85
  110. data/lib/capistrano/recipes/deploy/scm/git.rb +0 -191
  111. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -129
  112. data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -126
  113. data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -114
  114. data/lib/capistrano/recipes/deploy/scm.rb +0 -19
  115. data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -64
  116. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
  117. data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -144
  118. data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
  119. data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
  120. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -47
  121. data/lib/capistrano/recipes/deploy/strategy.rb +0 -19
  122. data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +0 -53
  123. data/lib/capistrano/recipes/deploy.rb +0 -494
  124. data/lib/capistrano/recipes/standard.rb +0 -37
  125. data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
  126. data/lib/capistrano/recipes/upgrade.rb +0 -33
  127. data/lib/capistrano/server_definition.rb +0 -51
  128. data/lib/capistrano/shell.rb +0 -256
  129. data/lib/capistrano/ssh.rb +0 -109
  130. data/lib/capistrano/task_definition.rb +0 -69
  131. data/lib/capistrano/upload.rb +0 -146
  132. data/test/cli/execute_test.rb +0 -132
  133. data/test/cli/help_test.rb +0 -139
  134. data/test/cli/options_test.rb +0 -226
  135. data/test/cli/ui_test.rb +0 -28
  136. data/test/cli_test.rb +0 -17
  137. data/test/command_test.rb +0 -309
  138. data/test/configuration/actions/file_transfer_test.rb +0 -40
  139. data/test/configuration/actions/inspect_test.rb +0 -62
  140. data/test/configuration/actions/invocation_test.rb +0 -202
  141. data/test/configuration/callbacks_test.rb +0 -206
  142. data/test/configuration/connections_test.rb +0 -288
  143. data/test/configuration/execution_test.rb +0 -159
  144. data/test/configuration/loading_test.rb +0 -127
  145. data/test/configuration/namespace_dsl_test.rb +0 -297
  146. data/test/configuration/roles_test.rb +0 -47
  147. data/test/configuration/servers_test.rb +0 -90
  148. data/test/configuration/variables_test.rb +0 -180
  149. data/test/configuration_test.rb +0 -81
  150. data/test/deploy/scm/accurev_test.rb +0 -23
  151. data/test/deploy/scm/base_test.rb +0 -55
  152. data/test/deploy/scm/git_test.rb +0 -112
  153. data/test/deploy/strategy/copy_test.rb +0 -147
  154. data/test/extensions_test.rb +0 -69
  155. data/test/fixtures/cli_integration.rb +0 -5
  156. data/test/fixtures/config.rb +0 -5
  157. data/test/fixtures/custom.rb +0 -3
  158. data/test/gateway_test.rb +0 -167
  159. data/test/logger_test.rb +0 -123
  160. data/test/server_definition_test.rb +0 -108
  161. data/test/shell_test.rb +0 -64
  162. data/test/ssh_test.rb +0 -97
  163. data/test/task_definition_test.rb +0 -101
  164. data/test/upload_test.rb +0 -131
  165. data/test/utils.rb +0 -42
  166. data/test/version_test.rb +0 -24
data/test/command_test.rb DELETED
@@ -1,309 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/utils"
2
- require 'capistrano/command'
3
-
4
- class CommandTest < Test::Unit::TestCase
5
- def test_command_should_open_channels_on_all_sessions
6
- s1 = mock(:open_channel => nil)
7
- s2 = mock(:open_channel => nil)
8
- s3 = mock(:open_channel => nil)
9
- assert_equal "ls", Capistrano::Command.new("ls", [s1, s2, s3]).command
10
- end
11
-
12
- def test_command_with_newlines_should_be_properly_escaped
13
- cmd = Capistrano::Command.new("ls\necho", [mock(:open_channel => nil)])
14
- assert_equal "ls\\\necho", cmd.command
15
- end
16
-
17
- def test_command_with_windows_newlines_should_be_properly_escaped
18
- cmd = Capistrano::Command.new("ls\r\necho", [mock(:open_channel => nil)])
19
- assert_equal "ls\\\necho", cmd.command
20
- end
21
-
22
- def test_command_with_pty_should_request_pty_and_register_success_callback
23
- session = setup_for_extracting_channel_action(:on_success) do |ch|
24
- ch.expects(:request_pty).with(:want_reply => true)
25
- ch.expects(:exec).with(%(sh -c "ls"))
26
- end
27
- Capistrano::Command.new("ls", [session], :pty => true)
28
- end
29
-
30
- def test_command_with_env_key_should_have_environment_constructed_and_prepended
31
- session = setup_for_extracting_channel_action do |ch|
32
- ch.expects(:request_pty).never
33
- ch.expects(:exec).with(%(env FOO=bar sh -c "ls"))
34
- end
35
- Capistrano::Command.new("ls", [session], :env => { "FOO" => "bar" })
36
- end
37
-
38
- def test_env_with_symbolic_key_should_be_accepted_as_a_string
39
- session = setup_for_extracting_channel_action do |ch|
40
- ch.expects(:exec).with(%(env FOO=bar sh -c "ls"))
41
- end
42
- Capistrano::Command.new("ls", [session], :env => { :FOO => "bar" })
43
- end
44
-
45
- def test_env_as_string_should_be_substituted_in_directly
46
- session = setup_for_extracting_channel_action do |ch|
47
- ch.expects(:exec).with(%(env HOWDY=there sh -c "ls"))
48
- end
49
- Capistrano::Command.new("ls", [session], :env => "HOWDY=there")
50
- end
51
-
52
- def test_env_with_symbolic_value_should_be_accepted_as_string
53
- session = setup_for_extracting_channel_action do |ch|
54
- ch.expects(:exec).with(%(env FOO=bar sh -c "ls"))
55
- end
56
- Capistrano::Command.new("ls", [session], :env => { "FOO" => :bar })
57
- end
58
-
59
- def test_env_value_should_be_escaped
60
- session = setup_for_extracting_channel_action do |ch|
61
- ch.expects(:exec).with(%(env FOO=(\\ \\\"bar\\\"\\ ) sh -c "ls"))
62
- end
63
- Capistrano::Command.new("ls", [session], :env => { "FOO" => '( "bar" )' })
64
- end
65
-
66
- def test_env_with_multiple_keys_should_chain_the_entries_together
67
- session = setup_for_extracting_channel_action do |ch|
68
- ch.expects(:exec).with do |command|
69
- command =~ /^env / &&
70
- command =~ /\ba=b\b/ &&
71
- command =~ /\bc=d\b/ &&
72
- command =~ /\be=f\b/ &&
73
- command =~ / sh -c "ls"$/
74
- end
75
- end
76
- Capistrano::Command.new("ls", [session], :env => { :a => :b, :c => :d, :e => :f })
77
- end
78
-
79
- def test_open_channel_should_set_host_key_on_channel
80
- session = mock(:xserver => server("capistrano"))
81
- channel = stub_everything
82
-
83
- session.expects(:open_channel).yields(channel)
84
- channel.expects(:[]=).with(:host, "capistrano")
85
- channel.stubs(:[]).with(:host).returns("capistrano")
86
-
87
- Capistrano::Command.new("ls", [session])
88
- end
89
-
90
- def test_open_channel_should_set_options_key_on_channel
91
- session = mock(:xserver => server("capistrano"))
92
- channel = stub_everything
93
-
94
- session.expects(:open_channel).yields(channel)
95
- channel.expects(:[]=).with(:options, {:data => "here we go"})
96
- channel.stubs(:[]).with(:host).returns("capistrano")
97
-
98
- Capistrano::Command.new("ls", [session], :data => "here we go")
99
- end
100
-
101
- def test_successful_channel_should_send_command
102
- session = setup_for_extracting_channel_action do |ch|
103
- ch.expects(:exec).with(%(sh -c "ls"))
104
- end
105
- Capistrano::Command.new("ls", [session])
106
- end
107
-
108
- def test_successful_channel_with_shell_option_should_send_command_via_specified_shell
109
- session = setup_for_extracting_channel_action do |ch|
110
- ch.expects(:exec).with(%(/bin/bash -c "ls"))
111
- end
112
- Capistrano::Command.new("ls", [session], :shell => "/bin/bash")
113
- end
114
-
115
- def test_successful_channel_with_shell_false_should_send_command_without_shell
116
- session = setup_for_extracting_channel_action do |ch|
117
- ch.expects(:exec).with(%(echo `hostname`))
118
- end
119
- Capistrano::Command.new("echo `hostname`", [session], :shell => false)
120
- end
121
-
122
- def test_successful_channel_should_send_data_if_data_key_is_present
123
- session = setup_for_extracting_channel_action do |ch|
124
- ch.expects(:exec).with(%(sh -c "ls"))
125
- ch.expects(:send_data).with("here we go")
126
- end
127
- Capistrano::Command.new("ls", [session], :data => "here we go")
128
- end
129
-
130
- def test_unsuccessful_pty_request_should_close_channel
131
- session = setup_for_extracting_channel_action(:on_failure) do |ch|
132
- ch.expects(:close)
133
- end
134
- Capistrano::Command.new("ls", [session], :pty => true)
135
- end
136
-
137
- def test_on_data_should_invoke_callback_as_stdout
138
- session = setup_for_extracting_channel_action(:on_data, "hello")
139
- called = false
140
- Capistrano::Command.new("ls", [session]) do |ch, stream, data|
141
- called = true
142
- assert_equal :out, stream
143
- assert_equal "hello", data
144
- end
145
- assert called
146
- end
147
-
148
- def test_on_extended_data_should_invoke_callback_as_stderr
149
- session = setup_for_extracting_channel_action(:on_extended_data, 2, "hello")
150
- called = false
151
- Capistrano::Command.new("ls", [session]) do |ch, stream, data|
152
- called = true
153
- assert_equal :err, stream
154
- assert_equal "hello", data
155
- end
156
- assert called
157
- end
158
-
159
- def test_on_request_should_record_exit_status
160
- data = mock(:read_long => 5)
161
- session = setup_for_extracting_channel_action(:on_request, "exit-status", nil, data) do |ch|
162
- ch.expects(:[]=).with(:status, 5)
163
- end
164
- Capistrano::Command.new("ls", [session])
165
- end
166
-
167
- def test_on_close_should_set_channel_closed
168
- session = setup_for_extracting_channel_action(:on_close) do |ch|
169
- ch.expects(:[]=).with(:closed, true)
170
- end
171
- Capistrano::Command.new("ls", [session])
172
- end
173
-
174
- def test_stop_should_close_all_open_channels
175
- sessions = [mock("session", :open_channel => new_channel(false)),
176
- mock("session", :open_channel => new_channel(true)),
177
- mock("session", :open_channel => 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", :open_channel => new_channel(true, 0)),
185
- mock("session", :open_channel => new_channel(true, 0)),
186
- mock("session", :open_channel => 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", :open_channel => new_channel(true, 0)),
193
- mock("session", :open_channel => new_channel(true, 0)),
194
- mock("session", :open_channel => 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", :open_channel => new_channel(true, 0)),
201
- mock("session", :open_channel => new_channel(true, 0)),
202
- mock("session", :open_channel => 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(:[]).with(:closed).returns(*(returns + [true]))
219
- con = mock("connection")
220
- con.expects(:process).with(true).times(times-1)
221
- ch.expects(:connection).times(times-1).returns(con)
222
- ch.expects(:[]).with(:status).returns(0)
223
- ch
224
- end
225
-
226
- sessions = [mock("session", :open_channel => new_channel[5]),
227
- mock("session", :open_channel => new_channel[10]),
228
- mock("session", :open_channel => new_channel[7])]
229
- cmd = Capistrano::Command.new("ls", sessions)
230
- assert_nothing_raised { cmd.process! }
231
- end
232
-
233
- def test_process_should_ping_all_connections_each_second
234
- now = Time.now
235
-
236
- new_channel = Proc.new do
237
- ch = mock("channel")
238
- ch.stubs(:now => now)
239
- def ch.[](key)
240
- case key
241
- when :status then 0
242
- when :closed then Time.now - now < 1.1 ? false : true
243
- else raise "unknown key: #{key}"
244
- end
245
- end
246
- con = mock("connection")
247
- con.stubs(:process)
248
- con.expects(:ping!)
249
- ch.stubs(:connection).returns(con)
250
- ch
251
- end
252
-
253
- sessions = [mock("session", :open_channel => new_channel[]),
254
- mock("session", :open_channel => new_channel[]),
255
- mock("session", :open_channel => new_channel[])]
256
- cmd = Capistrano::Command.new("ls", sessions)
257
- assert_nothing_raised { cmd.process! }
258
- end
259
-
260
- def test_process_should_instantiate_command_and_process!
261
- cmd = mock("command", :process! => nil)
262
- Capistrano::Command.expects(:new).with("ls -l", %w(a b c), {:foo => "bar"}).yields(:command).returns(cmd)
263
- parameter = nil
264
- Capistrano::Command.process("ls -l", %w(a b c), :foo => "bar") { |cmd| parameter = cmd }
265
- assert_equal :command, parameter
266
- end
267
-
268
- def test_process_with_host_placeholder_should_substitute_placeholder_with_each_host
269
- session = setup_for_extracting_channel_action do |ch|
270
- ch.expects(:exec).with(%(sh -c "echo capistrano"))
271
- end
272
- Capistrano::Command.new("echo $CAPISTRANO:HOST$", [session])
273
- end
274
-
275
- def test_process_with_unknown_placeholder_should_not_replace_placeholder
276
- session = setup_for_extracting_channel_action do |ch|
277
- ch.expects(:exec).with(%(sh -c "echo \\$CAPISTRANO:OTHER\\$"))
278
- end
279
- Capistrano::Command.new("echo $CAPISTRANO:OTHER$", [session])
280
- end
281
-
282
- private
283
-
284
- def new_channel(closed, status=nil)
285
- ch = mock("channel")
286
- ch.expects(:[]).with(:closed).returns(closed)
287
- ch.expects(:[]).with(:status).returns(status) if status
288
- ch.expects(:close) unless closed
289
- ch.stubs(:[]).with(:host).returns("capistrano")
290
- ch.stubs(:[]).with(:server).returns(server("capistrano"))
291
- ch
292
- end
293
-
294
- def setup_for_extracting_channel_action(action=nil, *args)
295
- s = server("capistrano")
296
- session = mock("session", :xserver => s)
297
-
298
- channel = stub_everything
299
- session.expects(:open_channel).yields(channel)
300
-
301
- channel.stubs(:[]).with(:server).returns(s)
302
- channel.stubs(:[]).with(:host).returns(s.host)
303
- channel.expects(action).yields(channel, *args) if action
304
-
305
- yield channel if block_given?
306
-
307
- session
308
- end
309
- end
@@ -1,40 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../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
- end
8
-
9
- def setup
10
- @config = MockConfig.new
11
- @config.stubs(:logger).returns(stub_everything)
12
- end
13
-
14
- def test_put_should_pass_options_to_execute_on_servers
15
- @config.expects(:execute_on_servers).with(:foo => "bar")
16
- @config.put("some data", "test.txt", :foo => "bar")
17
- end
18
-
19
- def test_put_should_delegate_to_Upload_process
20
- @config.expects(:execute_on_servers).yields(%w(s1 s2 s3).map { |s| mock(:host => s) })
21
- @config.expects(:sessions).times(3).returns(Hash.new{|h,k| h[k] = k.host.to_sym})
22
- Capistrano::Upload.expects(:process).with([:s1,:s2,:s3], "test.txt", :data => "some data", :mode => 0777, :logger => @config.logger)
23
- @config.put("some data", "test.txt", :mode => 0777)
24
- end
25
-
26
- def test_get_should_pass_options_execute_on_servers_including_once
27
- @config.expects(:execute_on_servers).with(:foo => "bar", :once => true)
28
- @config.get("test.txt", "test.txt", :foo => "bar")
29
- end
30
-
31
- def test_get_should_use_sftp_get_file_to_local_path
32
- sftp = mock("sftp", :state => :closed, :connect => true)
33
- sftp.expects(:get_file).with("remote.txt", "local.txt")
34
-
35
- s = server("capistrano")
36
- @config.expects(:execute_on_servers).yields([s])
37
- @config.expects(:sessions).returns(s => mock("session", :sftp => sftp))
38
- @config.get("remote.txt", "local.txt")
39
- end
40
- end
@@ -1,62 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../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_result_should_raise_capture_error
41
- @config.expects(:invoke_command).yields(mock("channel"), :err, "boom")
42
- assert_raises(Capistrano::CaptureError) { @config.capture("hostname") }
43
- end
44
-
45
- def test_capture_with_stdout_should_aggregate_and_return_stdout
46
- config_expects_invoke_command_to_loop_with(mock("channel"), "foo", "bar", "baz")
47
- assert_equal "foobarbaz", @config.capture("hostname")
48
- end
49
-
50
- private
51
-
52
- def config_expects_invoke_command_to_loop_with(channel, *output)
53
- class <<@config
54
- attr_accessor :script, :channel
55
- def invoke_command(*args)
56
- script.each { |item| yield channel, :out, item }
57
- end
58
- end
59
- @config.channel = channel
60
- @config.script = output
61
- end
62
- end
@@ -1,202 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../utils"
2
- require 'capistrano/configuration/actions/invocation'
3
-
4
- class ConfigurationActionsInvocationTest < Test::Unit::TestCase
5
- class MockConfig
6
- attr_reader :options
7
-
8
- def initialize
9
- @options = {}
10
- end
11
-
12
- def [](*args)
13
- @options[*args]
14
- end
15
-
16
- def set(name, value)
17
- @options[name] = value
18
- end
19
-
20
- def fetch(*args)
21
- @options.fetch(*args)
22
- end
23
-
24
- include Capistrano::Configuration::Actions::Invocation
25
- end
26
-
27
- def setup
28
- @config = MockConfig.new
29
- @original_io_proc = MockConfig.default_io_proc
30
- @config.stubs(:logger).returns(stub_everything)
31
- end
32
-
33
- def teardown
34
- MockConfig.default_io_proc = @original_io_proc
35
- end
36
-
37
- def test_run_options_should_be_passed_to_execute_on_servers
38
- @config.expects(:execute_on_servers).with(:foo => "bar")
39
- @config.run "ls", :foo => "bar"
40
- end
41
-
42
- def test_run_without_block_should_use_default_io_proc
43
- @config.expects(:execute_on_servers).yields(%w(s1 s2 s3).map { |s| server(s) })
44
- @config.expects(:sessions).returns(Hash.new { |h,k| h[k] = k.host.to_sym }).times(3)
45
- prepare_command("ls", [:s1, :s2, :s3], {:logger => @config.logger})
46
- MockConfig.default_io_proc = inspectable_proc
47
- @config.run "ls"
48
- end
49
-
50
- def test_run_with_block_should_use_block
51
- @config.expects(:execute_on_servers).yields(%w(s1 s2 s3).map { |s| mock(:host => s) })
52
- @config.expects(:sessions).returns(Hash.new { |h,k| h[k] = k.host.to_sym }).times(3)
53
- prepare_command("ls", [:s1, :s2, :s3], {:logger => @config.logger})
54
- MockConfig.default_io_proc = Proc.new { |a,b,c| raise "shouldn't get here" }
55
- @config.run("ls", &inspectable_proc)
56
- end
57
-
58
- def test_add_default_command_options_should_return_bare_options_if_there_is_no_env_or_shell_specified
59
- assert_equal({:foo => "bar"}, @config.add_default_command_options(:foo => "bar"))
60
- end
61
-
62
- def test_add_default_command_options_should_merge_default_environment_as_env
63
- @config[:default_environment][:bang] = "baz"
64
- assert_equal({:foo => "bar", :env => { :bang => "baz" }}, @config.add_default_command_options(:foo => "bar"))
65
- end
66
-
67
- def test_add_default_command_options_should_merge_env_with_default_environment
68
- @config[:default_environment][:bang] = "baz"
69
- @config[:default_environment][:bacon] = "crunchy"
70
- assert_equal({:foo => "bar", :env => { :bang => "baz", :bacon => "chunky", :flip => "flop" }}, @config.add_default_command_options(:foo => "bar", :env => {:bacon => "chunky", :flip => "flop"}))
71
- end
72
-
73
- def test_add_default_command_options_should_use_default_shell_if_present
74
- @config.set :default_shell, "/bin/bash"
75
- assert_equal({:foo => "bar", :shell => "/bin/bash"}, @config.add_default_command_options(:foo => "bar"))
76
- end
77
-
78
- def test_add_default_command_options_should_use_shell_in_preference_of_default_shell
79
- @config.set :default_shell, "/bin/bash"
80
- assert_equal({:foo => "bar", :shell => "/bin/sh"}, @config.add_default_command_options(:foo => "bar", :shell => "/bin/sh"))
81
- end
82
-
83
- def test_default_io_proc_should_log_stdout_arguments_as_info
84
- ch = { :host => "capistrano",
85
- :server => server("capistrano"),
86
- :options => { :logger => mock("logger") } }
87
- ch[:options][:logger].expects(:info).with("data stuff", "out :: capistrano")
88
- MockConfig.default_io_proc[ch, :out, "data stuff"]
89
- end
90
-
91
- def test_default_io_proc_should_log_stderr_arguments_as_important
92
- ch = { :host => "capistrano",
93
- :server => server("capistrano"),
94
- :options => { :logger => mock("logger") } }
95
- ch[:options][:logger].expects(:important).with("data stuff", "err :: capistrano")
96
- MockConfig.default_io_proc[ch, :err, "data stuff"]
97
- end
98
-
99
- def test_sudo_should_default_to_sudo
100
- @config.expects(:run).with("sudo -p 'sudo password: ' ls", {})
101
- @config.sudo "ls"
102
- end
103
-
104
- def test_sudo_should_use_sudo_variable_definition
105
- @config.expects(:run).with("/opt/local/bin/sudo -p 'sudo password: ' ls", {})
106
- @config.options[:sudo] = "/opt/local/bin/sudo"
107
- @config.sudo "ls"
108
- end
109
-
110
- def test_sudo_should_interpret_as_option_as_user
111
- @config.expects(:run).with("sudo -p 'sudo password: ' -u app ls", {})
112
- @config.sudo "ls", :as => "app"
113
- end
114
-
115
- def test_sudo_should_pass_options_through_to_run
116
- @config.expects(:run).with("sudo -p 'sudo password: ' ls", :foo => "bar")
117
- @config.sudo "ls", :foo => "bar"
118
- end
119
-
120
- def test_sudo_should_interpret_sudo_prompt_variable_as_custom_prompt
121
- @config.set :sudo_prompt, "give it to me: "
122
- @config.expects(:run).with("sudo -p 'give it to me: ' ls", {})
123
- @config.sudo "ls"
124
- end
125
-
126
- def test_sudo_behavior_callback_should_send_password_when_prompted_with_default_sudo_prompt
127
- ch = mock("channel")
128
- ch.expects(:send_data).with("g00b3r\n")
129
- @config.options[:password] = "g00b3r"
130
- @config.sudo_behavior_callback(nil)[ch, nil, "sudo password: "]
131
- end
132
-
133
- def test_sudo_behavior_callback_should_send_password_when_prompted_with_custom_sudo_prompt
134
- ch = mock("channel")
135
- ch.expects(:send_data).with("g00b3r\n")
136
- @config.set :sudo_prompt, "give it to me: "
137
- @config.options[:password] = "g00b3r"
138
- @config.sudo_behavior_callback(nil)[ch, nil, "give it to me: "]
139
- end
140
-
141
- def test_sudo_behavior_callback_with_incorrect_password_on_first_prompt
142
- ch = mock("channel")
143
- ch.stubs(:[]).with(:host).returns("capistrano")
144
- ch.stubs(:[]).with(:server).returns(server("capistrano"))
145
- @config.expects(:reset!).with(:password)
146
- @config.sudo_behavior_callback(nil)[ch, nil, "blah blah try again blah blah"]
147
- end
148
-
149
- def test_sudo_behavior_callback_with_incorrect_password_on_subsequent_prompts
150
- callback = @config.sudo_behavior_callback(nil)
151
-
152
- ch = mock("channel")
153
- ch.stubs(:[]).with(:host).returns("capistrano")
154
- ch.stubs(:[]).with(:server).returns(server("capistrano"))
155
- ch2 = mock("channel")
156
- ch2.stubs(:[]).with(:host).returns("cap2")
157
- ch2.stubs(:[]).with(:server).returns(server("cap2"))
158
-
159
- @config.expects(:reset!).with(:password).times(2)
160
-
161
- callback[ch, nil, "blah blah try again blah blah"]
162
- callback[ch2, nil, "blah blah try again blah blah"] # shouldn't call reset!
163
- callback[ch, nil, "blah blah try again blah blah"]
164
- end
165
-
166
- def test_sudo_behavior_callback_should_defer_to_fallback_for_other_output
167
- callback = @config.sudo_behavior_callback(inspectable_proc)
168
-
169
- a = mock("channel", :called => true)
170
- b = mock("stream", :called => true)
171
- c = mock("data", :called => true)
172
-
173
- callback[a, b, c]
174
- end
175
-
176
- def test_invoke_command_should_default_to_run
177
- @config.expects(:run).with("ls", :once => true)
178
- @config.invoke_command("ls", :once => true)
179
- end
180
-
181
- def test_invoke_command_should_delegate_to_method_identified_by_via
182
- @config.expects(:foobar).with("ls", :once => true)
183
- @config.invoke_command("ls", :once => true, :via => :foobar)
184
- end
185
-
186
- private
187
-
188
- def inspectable_proc
189
- Proc.new do |ch, stream, data|
190
- ch.called
191
- stream.called
192
- data.called
193
- end
194
- end
195
-
196
- def prepare_command(command, sessions, options)
197
- a = mock("channel", :called => true)
198
- b = mock("stream", :called => true)
199
- c = mock("data", :called => true)
200
- Capistrano::Command.expects(:process).with(command, sessions, options).yields(a, b, c)
201
- end
202
- end