capistrano 2.15.11 → 3.0.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,201 +0,0 @@
1
- require "utils"
2
- require 'capistrano/configuration/callbacks'
3
-
4
- class ConfigurationCallbacksTest < Test::Unit::TestCase
5
- class MockConfig
6
- attr_reader :original_initialize_called
7
- attr_reader :called
8
-
9
- def initialize
10
- @original_initialize_called = true
11
- @called = []
12
- end
13
-
14
- def execute_task(task)
15
- invoke_task_directly(task)
16
- end
17
-
18
- protected
19
-
20
- def invoke_task_directly(task)
21
- @called << task
22
- end
23
-
24
- include Capistrano::Configuration::Callbacks
25
- end
26
-
27
- def setup
28
- @config = MockConfig.new
29
- @config.stubs(:logger).returns(stub_everything("logger"))
30
- end
31
-
32
- def test_initialize_should_initialize_callbacks_collection
33
- assert @config.original_initialize_called
34
- assert @config.callbacks.empty?
35
- end
36
-
37
- def test_before_should_delegate_to_on
38
- @config.expects(:on).with(:before, :foo, "bing:blang", {:only => :bar, :zip => :zing})
39
- @config.before :bar, :foo, "bing:blang", :zip => :zing
40
- end
41
-
42
- def test_before_should_map_before_deploy_symlink
43
- @config.before "deploy:symlink", "bing:blang", "deploy:symlink"
44
- assert_equal "bing:blang", @config.callbacks[:before][0].source
45
- assert_equal "deploy:create_symlink", @config.callbacks[:before][1].source
46
- assert_equal ["deploy:create_symlink"], @config.callbacks[:before][1].only
47
- end
48
-
49
- def test_before_should_map_before_deploy_symlink_array
50
- @config.before ["deploy:symlink", "bingo:blast"], "bing:blang"
51
- assert_equal ["deploy:create_symlink", "bingo:blast"], @config.callbacks[:before].last.only
52
- end
53
-
54
- def test_after_should_delegate_to_on
55
- @config.expects(:on).with(:after, :foo, "bing:blang", {:only => :bar, :zip => :zing})
56
- @config.after :bar, :foo, "bing:blang", :zip => :zing
57
- end
58
-
59
- def test_after_should_map_before_deploy_symlink
60
- @config.after "deploy:symlink", "bing:blang", "deploy:symlink"
61
- assert_equal "bing:blang", @config.callbacks[:after][0].source
62
- assert_equal "deploy:create_symlink", @config.callbacks[:after][1].source
63
- assert_equal ["deploy:create_symlink"], @config.callbacks[:after][1].only
64
- end
65
-
66
- def test_after_should_map_before_deploy_symlink_array
67
- @config.after ["deploy:symlink", "bingo:blast"], "bing:blang"
68
- assert_equal ["deploy:create_symlink", "bingo:blast"], @config.callbacks[:after].last.only
69
- end
70
-
71
- def test_on_with_single_reference_should_add_task_callback
72
- @config.on :before, :a_test
73
- assert_equal 1, @config.callbacks[:before].length
74
- assert_equal :a_test, @config.callbacks[:before][0].source
75
- @config.expects(:find_and_execute_task).with(:a_test)
76
- @config.callbacks[:before][0].call
77
- end
78
-
79
- def test_on_with_multi_reference_should_add_all_as_task_callback
80
- @config.on :before, :first, :second, :third
81
- assert_equal 3, @config.callbacks[:before].length
82
- assert_equal %w(first second third), @config.callbacks[:before].map { |c| c.source.to_s }
83
- end
84
-
85
- def test_on_with_block_should_add_block_as_proc_callback
86
- called = false
87
- @config.on(:before) { called = true }
88
- assert_equal 1, @config.callbacks[:before].length
89
- assert_instance_of Proc, @config.callbacks[:before][0].source
90
- @config.callbacks[:before][0].call
91
- assert called
92
- end
93
-
94
- def test_on_with_single_only_should_set_only_as_string_array_on_all_references
95
- @config.on :before, :first, "second:third", :only => :primary
96
- assert_equal 2, @config.callbacks[:before].length
97
- assert @config.callbacks[:before].all? { |c| c.only == %w(primary) }
98
- end
99
-
100
- def test_on_with_multi_only_should_set_only_as_string_array_on_all_references
101
- @config.on :before, :first, "second:third", :only => [:primary, "other:one"]
102
- assert_equal 2, @config.callbacks[:before].length
103
- assert @config.callbacks[:before].all? { |c| c.only == %w(primary other:one) }
104
- end
105
-
106
- def test_on_with_single_except_should_set_except_as_string_array_on_all_references
107
- @config.on :before, :first, "second:third", :except => :primary
108
- assert_equal 2, @config.callbacks[:before].length
109
- assert @config.callbacks[:before].all? { |c| c.except == %w(primary) }
110
- end
111
-
112
- def test_on_with_multi_except_should_set_except_as_string_array_on_all_references
113
- @config.on :before, :first, "second:third", :except => [:primary, "other:one"]
114
- assert_equal 2, @config.callbacks[:before].length
115
- assert @config.callbacks[:before].all? { |c| c.except == %w(primary other:one) }
116
- end
117
-
118
- def test_on_with_only_and_block_should_set_only_as_string_array
119
- @config.on(:before, :only => :primary) { blah }
120
- assert_equal 1, @config.callbacks[:before].length
121
- assert_equal %w(primary), @config.callbacks[:before].first.only
122
- end
123
-
124
- def test_on_with_except_and_block_should_set_except_as_string_array
125
- @config.on(:before, :except => :primary) { blah }
126
- assert_equal 1, @config.callbacks[:before].length
127
- assert_equal %w(primary), @config.callbacks[:before].first.except
128
- end
129
-
130
- def test_on_without_tasks_or_block_should_raise_error
131
- assert_raises(ArgumentError) { @config.on(:before) }
132
- end
133
-
134
- def test_on_with_both_tasks_and_block_should_raise_error
135
- assert_raises(ArgumentError) { @config.on(:before, :first) { blah } }
136
- end
137
-
138
- def test_trigger_without_constraints_should_invoke_all_callbacks
139
- task = stub(:fully_qualified_name => "any:old:thing")
140
- @config.on(:before, :first, "second:third")
141
- @config.on(:after, :another, "and:another")
142
- @config.expects(:find_and_execute_task).with(:first)
143
- @config.expects(:find_and_execute_task).with("second:third")
144
- @config.expects(:find_and_execute_task).with(:another).never
145
- @config.expects(:find_and_execute_task).with("and:another").never
146
- @config.trigger(:before, task)
147
- end
148
-
149
- def test_trigger_with_only_constraint_should_invoke_only_matching_callbacks
150
- task = stub(:fully_qualified_name => "any:old:thing")
151
- @config.on(:before, :first)
152
- @config.on(:before, "second:third", :only => "any:old:thing")
153
- @config.on(:before, "this:too", :only => "any:other:thing")
154
- @config.on(:after, :another, "and:another")
155
- @config.expects(:find_and_execute_task).with(:first)
156
- @config.expects(:find_and_execute_task).with("second:third")
157
- @config.expects(:find_and_execute_task).with("this:too").never
158
- @config.expects(:find_and_execute_task).with(:another).never
159
- @config.expects(:find_and_execute_task).with("and:another").never
160
- @config.trigger(:before, task)
161
- end
162
-
163
- def test_trigger_with_except_constraint_should_invoke_anything_but_matching_callbacks
164
- task = stub(:fully_qualified_name => "any:old:thing")
165
- @config.on(:before, :first)
166
- @config.on(:before, "second:third", :except => "any:old:thing")
167
- @config.on(:before, "this:too", :except => "any:other:thing")
168
- @config.on(:after, :another, "and:another")
169
- @config.expects(:find_and_execute_task).with(:first)
170
- @config.expects(:find_and_execute_task).with("second:third").never
171
- @config.expects(:find_and_execute_task).with("this:too")
172
- @config.expects(:find_and_execute_task).with(:another).never
173
- @config.expects(:find_and_execute_task).with("and:another").never
174
- @config.trigger(:before, task)
175
- end
176
-
177
- def test_trigger_without_task_should_invoke_all_callbacks_for_that_event
178
- task = stub(:fully_qualified_name => "any:old:thing")
179
- @config.on(:before, :first)
180
- @config.on(:before, "second:third", :except => "any:old:thing")
181
- @config.on(:before, "this:too", :except => "any:other:thing")
182
- @config.on(:after, :another, "and:another")
183
- @config.expects(:find_and_execute_task).with(:first)
184
- @config.expects(:find_and_execute_task).with("second:third")
185
- @config.expects(:find_and_execute_task).with("this:too")
186
- @config.expects(:find_and_execute_task).with(:another).never
187
- @config.expects(:find_and_execute_task).with("and:another").never
188
- @config.trigger(:before)
189
- end
190
-
191
- def test_execute_task_without_named_hooks_should_just_call_task
192
- ns = stub("namespace", :default_task => nil, :name => "old", :fully_qualified_name => "any:old")
193
- task = stub(:fully_qualified_name => "any:old:thing", :name => "thing", :namespace => ns)
194
-
195
- ns.stubs(:search_task).returns(nil)
196
-
197
- @config.execute_task(task)
198
- assert_equal [task], @config.called
199
- end
200
-
201
- end
@@ -1,439 +0,0 @@
1
- require "utils"
2
- require 'capistrano/configuration/connections'
3
-
4
- class ConfigurationConnectionsTest < Test::Unit::TestCase
5
- class MockConfig
6
- attr_reader :original_initialize_called
7
- attr_reader :values
8
- attr_reader :dry_run
9
- attr_accessor :current_task
10
-
11
- def initialize
12
- @original_initialize_called = true
13
- @values = {}
14
- end
15
-
16
- def fetch(*args)
17
- @values.fetch(*args)
18
- end
19
-
20
- def [](key)
21
- @values[key]
22
- end
23
-
24
- def exists?(key)
25
- @values.key?(key)
26
- end
27
-
28
- include Capistrano::Configuration::Connections
29
- end
30
-
31
- def setup
32
- @config = MockConfig.new
33
- @config.stubs(:logger).returns(stub_everything)
34
- Net::SSH.stubs(:configuration_for).returns({})
35
- @ssh_options = {
36
- :user => "user",
37
- :port => 8080,
38
- :password => "g00b3r",
39
- :ssh_options => { :debug => :verbose }
40
- }
41
- end
42
-
43
- def test_initialize_should_initialize_collections_and_call_original_initialize
44
- assert @config.original_initialize_called
45
- assert @config.sessions.empty?
46
- end
47
-
48
- def test_connection_factory_should_return_default_connection_factory_instance
49
- factory = @config.connection_factory
50
- assert_instance_of Capistrano::Configuration::Connections::DefaultConnectionFactory, factory
51
- end
52
-
53
- def test_connection_factory_instance_should_be_cached
54
- assert_same @config.connection_factory, @config.connection_factory
55
- end
56
-
57
- def test_default_connection_factory_honors_config_options
58
- server = server("capistrano")
59
- Capistrano::SSH.expects(:connect).with(server, @config).returns(:session)
60
- assert_equal :session, @config.connection_factory.connect_to(server)
61
- end
62
-
63
- def test_should_connect_through_gateway_if_gateway_variable_is_set
64
- @config.values[:gateway] = "j@gateway"
65
- Net::SSH::Gateway.expects(:new).with("gateway", "j", :password => nil, :auth_methods => %w(publickey hostbased), :config => false).returns(stub_everything)
66
- assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
67
- end
68
-
69
- def test_connection_factory_as_gateway_should_honor_config_options
70
- @config.values[:gateway] = "gateway"
71
- @config.values.update(@ssh_options)
72
- Net::SSH::Gateway.expects(:new).with("gateway", "user", :debug => :verbose, :port => 8080, :password => nil, :auth_methods => %w(publickey hostbased), :config => false).returns(stub_everything)
73
- assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
74
- end
75
-
76
- def test_connection_factory_as_gateway_should_chain_gateways_if_gateway_variable_is_an_array
77
- @config.values[:gateway] = ["j@gateway1", "k@gateway2"]
78
- gateway1 = mock
79
- Net::SSH::Gateway.expects(:new).with("gateway1", "j", :password => nil, :auth_methods => %w(publickey hostbased), :config => false).returns(gateway1)
80
- gateway1.expects(:open).returns(65535)
81
- Net::SSH::Gateway.expects(:new).with("127.0.0.1", "k", :port => 65535, :password => nil, :auth_methods => %w(publickey hostbased), :config => false).returns(stub_everything)
82
- assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
83
- end
84
-
85
- def test_connection_factory_as_gateway_should_chain_gateways_if_gateway_variable_is_a_hash
86
- @config.values[:gateway] = { ["j@gateway1", "k@gateway2"] => :default }
87
- gateway1 = mock
88
- Net::SSH::Gateway.expects(:new).with("gateway1", "j", :password => nil, :auth_methods => %w(publickey hostbased), :config => false).returns(gateway1)
89
- gateway1.expects(:open).returns(65535)
90
- Net::SSH::Gateway.expects(:new).with("127.0.0.1", "k", :port => 65535, :password => nil, :auth_methods => %w(publickey hostbased), :config => false).returns(stub_everything)
91
- assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
92
- end
93
-
94
- def test_connection_factory_as_gateway_should_share_gateway_between_connections
95
- @config.values[:gateway] = "j@gateway"
96
- Net::SSH::Gateway.expects(:new).once.with("gateway", "j", :password => nil, :auth_methods => %w(publickey hostbased), :config => false).returns(stub_everything)
97
- Capistrano::SSH.stubs(:connect).returns(stub_everything)
98
- assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
99
- @config.establish_connections_to(server("capistrano"))
100
- @config.establish_connections_to(server("another"))
101
- end
102
-
103
- def test_connection_factory_as_gateway_should_share_gateway_between_like_connections_if_gateway_variable_is_a_hash
104
- @config.values[:gateway] = { "j@gateway" => [ "capistrano", "another"] }
105
- Net::SSH::Gateway.expects(:new).once.with("gateway", "j", :password => nil, :auth_methods => %w(publickey hostbased), :config => false).returns(stub_everything)
106
- Capistrano::SSH.stubs(:connect).returns(stub_everything)
107
- assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
108
- @config.establish_connections_to(server("capistrano"))
109
- @config.establish_connections_to(server("another"))
110
- end
111
-
112
- def test_connection_factory_as_gateways_should_not_share_gateway_between_unlike_connections_if_gateway_variable_is_a_hash
113
- @config.values[:gateway] = { "j@gateway" => [ "capistrano", "another"], "k@gateway2" => "yafhost" }
114
- Net::SSH::Gateway.expects(:new).once.with("gateway", "j", :password => nil, :auth_methods => %w(publickey hostbased), :config => false).returns(stub_everything)
115
- Net::SSH::Gateway.expects(:new).once.with("gateway2", "k", :password => nil, :auth_methods => %w(publickey hostbased), :config => false).returns(stub_everything)
116
- Capistrano::SSH.stubs(:connect).returns(stub_everything)
117
- assert_instance_of Capistrano::Configuration::Connections::GatewayConnectionFactory, @config.connection_factory
118
- @config.establish_connections_to(server("capistrano"))
119
- @config.establish_connections_to(server("another"))
120
- @config.establish_connections_to(server("yafhost"))
121
- end
122
-
123
- def test_establish_connections_to_should_accept_a_single_nonarray_parameter
124
- Capistrano::SSH.expects(:connect).with { |s,| s.host == "capistrano" }.returns(:success)
125
- assert @config.sessions.empty?
126
- @config.establish_connections_to(server("capistrano"))
127
- assert_equal ["capistrano"], @config.sessions.keys.map(&:host)
128
- end
129
-
130
- def test_establish_connections_to_should_accept_an_array
131
- Capistrano::SSH.expects(:connect).times(3).returns(:success)
132
- assert @config.sessions.empty?
133
- @config.establish_connections_to(%w(cap1 cap2 cap3).map { |s| server(s) })
134
- assert_equal %w(cap1 cap2 cap3), @config.sessions.keys.sort.map(&:host)
135
- end
136
-
137
- def test_establish_connections_to_should_not_attempt_to_reestablish_existing_connections
138
- Capistrano::SSH.expects(:connect).times(2).returns(:success)
139
- @config.sessions[server("cap1")] = :ok
140
- @config.establish_connections_to(%w(cap1 cap2 cap3).map { |s| server(s) })
141
- assert_equal %w(cap1 cap2 cap3), @config.sessions.keys.sort.map(&:host)
142
- end
143
-
144
- def test_establish_connections_to_should_raise_one_connection_error_on_failure
145
- Capistrano::SSH.expects(:connect).times(2).raises(Exception)
146
- assert_raises(Capistrano::ConnectionError) {
147
- @config.establish_connections_to(%w(cap1 cap2).map { |s| server(s) })
148
- }
149
- end
150
-
151
- def test_connection_error_should_include_accessor_with_host_array
152
- Capistrano::SSH.expects(:connect).times(2).raises(Exception)
153
- begin
154
- @config.establish_connections_to(%w(cap1 cap2).map { |s| server(s) })
155
- flunk "expected an exception to be raised"
156
- rescue Capistrano::ConnectionError => e
157
- assert e.respond_to?(:hosts)
158
- assert_equal %w(cap1 cap2), e.hosts.map { |h| h.to_s }.sort
159
- end
160
- end
161
-
162
- def test_connection_error_should_only_include_failed_hosts
163
- Capistrano::SSH.expects(:connect).with(server('cap1'), anything).raises(Exception)
164
- Capistrano::SSH.expects(:connect).with(server('cap2'), anything).returns(:success)
165
-
166
- begin
167
- @config.establish_connections_to(%w(cap1 cap2).map { |s| server(s) })
168
- flunk "expected an exception to be raised"
169
- rescue Capistrano::ConnectionError => e
170
- assert_equal %w(cap1), e.hosts.map { |h| h.to_s }
171
- end
172
- end
173
-
174
- def test_execute_on_servers_should_require_a_block
175
- assert_raises(ArgumentError) { @config.execute_on_servers }
176
- end
177
-
178
- def test_execute_on_servers_without_current_task_should_call_find_servers
179
- list = [server("first"), server("second")]
180
- @config.expects(:find_servers).with(:a => :b, :c => :d).returns(list)
181
- @config.expects(:establish_connections_to).with(list).returns(:done)
182
- @config.execute_on_servers(:a => :b, :c => :d) do |result|
183
- assert_equal list, result
184
- end
185
- end
186
-
187
- def test_execute_on_servers_without_current_task_should_raise_error_if_no_matching_servers
188
- @config.expects(:find_servers).with(:a => :b, :c => :d).returns([])
189
- assert_raises(Capistrano::NoMatchingServersError) { @config.execute_on_servers(:a => :b, :c => :d) { |list| } }
190
- end
191
-
192
- def test_execute_on_servers_without_current_task_should_not_raise_error_if_no_matching_servers_and_continue_on_no_matching_servers
193
- @config.expects(:find_servers).with(:a => :b, :c => :d, :on_no_matching_servers => :continue).returns([])
194
- assert_nothing_raised { @config.execute_on_servers(:a => :b, :c => :d, :on_no_matching_servers => :continue) { |list| } }
195
- end
196
-
197
- def test_execute_on_servers_should_raise_an_error_if_the_current_task_has_no_matching_servers_by_default
198
- @config.current_task = mock_task
199
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([])
200
- assert_raises(Capistrano::NoMatchingServersError) do
201
- @config.execute_on_servers do
202
- flunk "should not get here"
203
- end
204
- end
205
- end
206
-
207
- def test_execute_on_servers_should_not_raise_an_error_if_the_current_task_has_no_matching_servers_by_default_and_continue_on_no_matching_servers
208
- @config.current_task = mock_task(:on_no_matching_servers => :continue)
209
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([])
210
- assert_nothing_raised do
211
- @config.execute_on_servers do
212
- flunk "should not get here"
213
- end
214
- end
215
- end
216
-
217
- def test_execute_on_servers_should_not_raise_an_error_if_the_current_task_has_no_matching_servers_by_default_and_command_continues_on_no_matching_servers
218
- @config.current_task = mock_task
219
- @config.expects(:find_servers_for_task).with(@config.current_task, :on_no_matching_servers => :continue).returns([])
220
- assert_nothing_raised do
221
- @config.execute_on_servers(:on_no_matching_servers => :continue) do
222
- flunk "should not get here"
223
- end
224
- end
225
- end
226
-
227
- def test_execute_on_servers_should_determine_server_list_from_active_task
228
- assert @config.sessions.empty?
229
- @config.current_task = mock_task
230
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([server("cap1"), server("cap2"), server("cap3")])
231
- Capistrano::SSH.expects(:connect).times(3).returns(:success)
232
- @config.execute_on_servers {}
233
- assert_equal %w(cap1 cap2 cap3), @config.sessions.keys.sort.map { |s| s.host }
234
- end
235
-
236
- def test_execute_on_servers_should_yield_server_list_to_block
237
- assert @config.sessions.empty?
238
- @config.current_task = mock_task
239
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([server("cap1"), server("cap2"), server("cap3")])
240
- Capistrano::SSH.expects(:connect).times(3).returns(:success)
241
- block_called = false
242
- @config.execute_on_servers do |servers|
243
- block_called = true
244
- assert servers.detect { |s| s.host == "cap1" }
245
- assert servers.detect { |s| s.host == "cap2" }
246
- assert servers.detect { |s| s.host == "cap3" }
247
- assert servers.all? { |s| @config.sessions[s] }
248
- end
249
- assert block_called
250
- end
251
-
252
- def test_execute_on_servers_with_once_option_should_establish_connection_to_and_yield_only_the_first_server
253
- assert @config.sessions.empty?
254
- @config.current_task = mock_task
255
- @config.expects(:find_servers_for_task).with(@config.current_task, :once => true).returns([server("cap1"), server("cap2"), server("cap3")])
256
- Capistrano::SSH.expects(:connect).returns(:success)
257
- block_called = false
258
- @config.execute_on_servers(:once => true) do |servers|
259
- block_called = true
260
- assert_equal %w(cap1), servers.map { |s| s.host }
261
- end
262
- assert block_called
263
- assert_equal %w(cap1), @config.sessions.keys.sort.map { |s| s.host }
264
- end
265
-
266
- def test_execute_servers_should_raise_connection_error_on_failure_by_default
267
- @config.current_task = mock_task
268
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([server("cap1")])
269
- Capistrano::SSH.expects(:connect).raises(Exception)
270
- assert_raises(Capistrano::ConnectionError) do
271
- @config.execute_on_servers do
272
- flunk "expected an exception to be raised"
273
- end
274
- end
275
- end
276
-
277
- def test_execute_servers_should_not_raise_connection_error_on_failure_with_on_errors_continue
278
- @config.current_task = mock_task(:on_error => :continue)
279
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([server("cap1"), server("cap2")])
280
- Capistrano::SSH.expects(:connect).with(server('cap1'), anything).raises(Exception)
281
- Capistrano::SSH.expects(:connect).with(server('cap2'), anything).returns(:success)
282
- assert_nothing_raised {
283
- @config.execute_on_servers do |servers|
284
- assert_equal %w(cap2), servers.map { |s| s.host }
285
- end
286
- }
287
- end
288
-
289
- def test_execute_on_servers_should_not_try_to_connect_to_hosts_with_connection_errors_with_on_errors_continue
290
- list = [server("cap1"), server("cap2")]
291
- @config.current_task = mock_task(:on_error => :continue)
292
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns(list)
293
- Capistrano::SSH.expects(:connect).with(server('cap1'), anything).raises(Exception)
294
- Capistrano::SSH.expects(:connect).with(server('cap2'), anything).returns(:success)
295
- @config.execute_on_servers do |servers|
296
- assert_equal %w(cap2), servers.map { |s| s.host }
297
- end
298
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns(list)
299
- @config.execute_on_servers do |servers|
300
- assert_equal %w(cap2), servers.map { |s| s.host }
301
- end
302
- end
303
-
304
- def test_execute_on_servers_should_not_try_to_connect_to_hosts_with_command_errors_with_on_errors_continue
305
- cap1 = server("cap1")
306
- cap2 = server("cap2")
307
- @config.current_task = mock_task(:on_error => :continue)
308
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([cap1, cap2])
309
- Capistrano::SSH.expects(:connect).times(2).returns(:success)
310
- @config.execute_on_servers do |servers|
311
- error = Capistrano::CommandError.new
312
- error.hosts = [cap1]
313
- raise error
314
- end
315
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([cap1, cap2])
316
- @config.execute_on_servers do |servers|
317
- assert_equal %w(cap2), servers.map { |s| s.host }
318
- end
319
- end
320
-
321
- def test_execute_on_servers_should_not_try_to_connect_to_hosts_with_transfer_errors_with_on_errors_continue
322
- cap1 = server("cap1")
323
- cap2 = server("cap2")
324
- @config.current_task = mock_task(:on_error => :continue)
325
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([cap1, cap2])
326
- Capistrano::SSH.expects(:connect).times(2).returns(:success)
327
- @config.execute_on_servers do |servers|
328
- error = Capistrano::TransferError.new
329
- error.hosts = [cap1]
330
- raise error
331
- end
332
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([cap1, cap2])
333
- @config.execute_on_servers do |servers|
334
- assert_equal %w(cap2), servers.map { |s| s.host }
335
- end
336
- end
337
-
338
- def test_connect_should_establish_connections_to_all_servers_in_scope
339
- assert @config.sessions.empty?
340
- @config.current_task = mock_task
341
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([server("cap1"), server("cap2"), server("cap3")])
342
- Capistrano::SSH.expects(:connect).times(3).returns(:success)
343
- @config.connect!
344
- assert_equal %w(cap1 cap2 cap3), @config.sessions.keys.sort.map { |s| s.host }
345
- end
346
-
347
- def test_execute_on_servers_should_only_run_on_tasks_max_hosts_hosts_at_once
348
- cap1 = server("cap1")
349
- cap2 = server("cap2")
350
- connection1 = mock()
351
- connection2 = mock()
352
- connection1.expects(:close)
353
- connection2.expects(:close)
354
- @config.current_task = mock_task(:max_hosts => 1)
355
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([cap1, cap2])
356
- Capistrano::SSH.expects(:connect).times(2).returns(connection1).then.returns(connection2)
357
- block_called = 0
358
- @config.execute_on_servers do |servers|
359
- block_called += 1
360
- assert_equal 1, servers.size
361
- end
362
- assert_equal 2, block_called
363
- end
364
-
365
- def test_execute_on_servers_should_only_run_on_max_hosts_hosts_at_once
366
- cap1 = server("cap1")
367
- cap2 = server("cap2")
368
- connection1 = mock()
369
- connection2 = mock()
370
- connection1.expects(:close)
371
- connection2.expects(:close)
372
- @config.current_task = mock_task(:max_hosts => 1)
373
- @config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([cap1, cap2])
374
- Capistrano::SSH.expects(:connect).times(2).returns(connection1).then.returns(connection2)
375
- block_called = 0
376
- @config.execute_on_servers do |servers|
377
- block_called += 1
378
- assert_equal 1, servers.size
379
- end
380
- assert_equal 2, block_called
381
- end
382
-
383
- def test_execute_on_servers_should_cope_with_already_dropped_connections_when_attempting_to_close_them
384
- cap1 = server("cap1")
385
- cap2 = server("cap2")
386
- connection1 = mock()
387
- connection2 = mock()
388
- connection3 = mock()
389
- connection4 = mock()
390
- connection1.expects(:close).raises(IOError)
391
- connection2.expects(:close)
392
- connection3.expects(:close)
393
- connection4.expects(:close)
394
- @config.current_task = mock_task(:max_hosts => 1)
395
- @config.expects(:find_servers_for_task).times(2).with(@config.current_task, {}).returns([cap1, cap2])
396
- Capistrano::SSH.expects(:connect).times(4).returns(connection1).then.returns(connection2).then.returns(connection3).then.returns(connection4)
397
- @config.execute_on_servers {}
398
- @config.execute_on_servers {}
399
- end
400
-
401
- def test_execute_on_servers_should_cope_with_already_disconnected_connections_when_attempting_to_close_them
402
- cap1 = server("cap1")
403
- cap2 = server("cap2")
404
- connection1 = mock()
405
- connection2 = mock()
406
- connection3 = mock()
407
- connection4 = mock()
408
- connection1.expects(:close).raises(Net::SSH::Disconnect)
409
- connection2.expects(:close)
410
- connection3.expects(:close)
411
- connection4.expects(:close)
412
- @config.current_task = mock_task(:max_hosts => 1)
413
- @config.expects(:find_servers_for_task).times(2).with(@config.current_task, {}).returns([cap1, cap2])
414
- Capistrano::SSH.expects(:connect).times(4).returns(connection1).then.returns(connection2).then.returns(connection3).then.returns(connection4)
415
- @config.execute_on_servers {}
416
- @config.execute_on_servers {}
417
- end
418
-
419
- def test_connect_should_honor_once_option
420
- assert @config.sessions.empty?
421
- @config.current_task = mock_task
422
- @config.expects(:find_servers_for_task).with(@config.current_task, :once => true).returns([server("cap1"), server("cap2"), server("cap3")])
423
- Capistrano::SSH.expects(:connect).returns(:success)
424
- @config.connect! :once => true
425
- assert_equal %w(cap1), @config.sessions.keys.sort.map { |s| s.host }
426
- end
427
-
428
- private
429
-
430
- def mock_task(options={})
431
- continue_on_error = options[:on_error] == :continue
432
- stub("task",
433
- :fully_qualified_name => "name",
434
- :options => options,
435
- :continue_on_error? => continue_on_error,
436
- :max_hosts => options[:max_hosts]
437
- )
438
- end
439
- end