capistrano 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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/gateway_test.rb DELETED
@@ -1,167 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/utils"
2
- require 'capistrano/gateway'
3
-
4
- class GatewayTest < Test::Unit::TestCase
5
- def teardown
6
- Thread.list { |t| t.kill unless Thread.current == t }
7
- end
8
-
9
- def test_initialize_should_open_and_set_session_value
10
- run_test_initialize_should_open_and_set_session_value
11
- end
12
-
13
- def test_initialize_when_connect_lags_should_open_and_set_session_value
14
- run_test_initialize_should_open_and_set_session_value do |expects|
15
- expects.with { |*args| sleep 0.2; true }
16
- end
17
- end
18
-
19
- def test_shutdown_without_any_open_connections_should_terminate_session
20
- gateway = new_gateway
21
- gateway.shutdown!
22
- assert !gateway.thread.alive?
23
- assert !gateway.session.looping?
24
- end
25
-
26
- def test_connect_to_should_start_local_ports_at_65535
27
- gateway = new_gateway
28
- expect_connect_to(:host => "127.0.0.1", :port => 65535).returns(result = sess_with_xserver("app1"))
29
- newsess = gateway.connect_to(server("app1"))
30
- assert_equal result, newsess
31
- assert_equal [65535, "app1", 22], gateway.session.forward.active_locals[65535]
32
- end
33
-
34
- def test_connect_to_should_decrement_port_and_retry_if_ports_are_in_use
35
- gateway = new_gateway(:reserved => lambda { |n| n > 65000 })
36
- expect_connect_to(:host => "127.0.0.1", :port => 65000).returns(result = sess_with_xserver("app1"))
37
- newsess = gateway.connect_to(server("app1"))
38
- assert_equal result, newsess
39
- assert_equal [65000, "app1", 22], gateway.session.forward.active_locals[65000]
40
- end
41
-
42
- def test_connect_to_should_honor_user_specification_in_server_definition
43
- gateway = new_gateway
44
- expect_connect_to(:host => "127.0.0.1", :user => "jamis", :port => 65535).returns(result = sess_with_xserver("app1"))
45
- newsess = gateway.connect_to(server("jamis@app1"))
46
- assert_equal result, newsess
47
- assert_equal [65535, "app1", 22], gateway.session.forward.active_locals[65535]
48
- end
49
-
50
- def test_connect_to_should_honor_port_specification_in_server_definition
51
- gateway = new_gateway
52
- expect_connect_to(:host => "127.0.0.1", :port => 65535).returns(result = sess_with_xserver("app1"))
53
- newsess = gateway.connect_to(server("app1:1234"))
54
- assert_equal result, newsess
55
- assert_equal [65535, "app1", 1234], gateway.session.forward.active_locals[65535]
56
- end
57
-
58
- def test_connect_to_should_set_xserver_to_tunnel_target
59
- gateway = new_gateway
60
- expect_connect_to(:host => "127.0.0.1", :port => 65535).returns(result = sess_with_xserver("app1"))
61
- newsess = gateway.connect_to(server("app1:1234"))
62
- assert_equal result, newsess
63
- end
64
-
65
- def test_shutdown_should_cancel_active_forwarded_ports
66
- gateway = new_gateway
67
- expect_connect_to(:host => "127.0.0.1", :port => 65535).returns(sess_with_xserver("app1"))
68
- gateway.connect_to(server("app1"))
69
- assert !gateway.session.forward.active_locals.empty?
70
- gateway.shutdown!
71
- assert gateway.session.forward.active_locals.empty?
72
- end
73
-
74
- def test_error_while_connecting_should_cause_connection_to_fail
75
- gateway = new_gateway
76
- expect_connect_to(:host => "127.0.0.1").raises(RuntimeError)
77
- gateway.expects(:warn).times(2)
78
- assert_raises(Capistrano::ConnectionError) { gateway.connect_to(server("app1")) }
79
- end
80
-
81
- def test_connection_error_should_include_accessor_with_host_array
82
- gateway = new_gateway
83
- expect_connect_to(:host => "127.0.0.1").raises(RuntimeError)
84
- gateway.expects(:warn).times(2)
85
-
86
- begin
87
- gateway.connect_to(server("app1"))
88
- flunk "expected an exception to be raised"
89
- rescue Capistrano::ConnectionError => e
90
- assert e.respond_to?(:hosts)
91
- assert_equal %w(app1), e.hosts.map { |h| h.to_s }
92
- end
93
- end
94
-
95
- private
96
-
97
- def sess_with_xserver(host)
98
- s = server(host)
99
- sess = mock("session")
100
- sess.expects(:xserver=).with { |v| v.host == host }
101
- sess
102
- end
103
-
104
- def expect_connect_to(options={})
105
- Capistrano::SSH.expects(:connect).with do |server,config|
106
- options.all? do |key, value|
107
- case key
108
- when :host then server.host == value
109
- when :user then server.user == value
110
- when :port then server.port == value
111
- else false
112
- end
113
- end
114
- end
115
- end
116
-
117
- def new_gateway(options={})
118
- expect_connect_to(:host => "capistrano").yields(MockSession.new(options))
119
- Capistrano::Gateway.new(server("capistrano"))
120
- end
121
-
122
- def run_test_initialize_should_open_and_set_session_value
123
- session = mock("Net::SSH session")
124
- session.expects(:loop)
125
- expectation = Capistrano::SSH.expects(:connect).yields(session)
126
- yield expectation if block_given?
127
- gateway = Capistrano::Gateway.new(server("capistrano"))
128
- gateway.thread.join
129
- assert_equal session, gateway.session
130
- end
131
-
132
- class MockForward
133
- attr_reader :active_locals
134
-
135
- def initialize(options)
136
- @options = options
137
- @active_locals = {}
138
- end
139
-
140
- def cancel_local(port)
141
- @active_locals.delete(port)
142
- end
143
-
144
- def local(lport, host, rport)
145
- raise Errno::EADDRINUSE if @options[:reserved] && @options[:reserved][lport]
146
- @active_locals[lport] = [lport, host, rport]
147
- end
148
- end
149
-
150
- class MockSession
151
- attr_reader :forward
152
-
153
- def initialize(options={})
154
- @forward = MockForward.new(options)
155
- end
156
-
157
- def looping?
158
- @looping
159
- end
160
-
161
- def loop
162
- @looping = true
163
- sleep 0.1 while yield
164
- @looping = false
165
- end
166
- end
167
- end
data/test/logger_test.rb DELETED
@@ -1,123 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/utils"
2
- require 'capistrano/logger'
3
- require 'stringio'
4
-
5
- class LoggerTest < Test::Unit::TestCase
6
- def setup
7
- @io = StringIO.new
8
- @logger = Capistrano::Logger.new(:output => @io)
9
- end
10
-
11
- def test_logger_should_use_STDERR_by_default
12
- logger = Capistrano::Logger.new
13
- assert_equal STDERR, logger.device
14
- end
15
-
16
- def test_logger_should_use_output_option_if_output_responds_to_puts
17
- logger = Capistrano::Logger.new(:output => STDOUT)
18
- assert_equal STDOUT, logger.device
19
- end
20
-
21
- def test_logger_should_open_file_if_output_does_not_respond_to_puts
22
- File.expects(:open).with("logs/capistrano.log", "a").returns(:mock)
23
- logger = Capistrano::Logger.new(:output => "logs/capistrano.log")
24
- assert_equal :mock, logger.device
25
- end
26
-
27
- def test_close_should_not_close_device_if_device_is_default
28
- logger = Capistrano::Logger.new
29
- logger.device.expects(:close).never
30
- logger.close
31
- end
32
-
33
- def test_close_should_not_close_device_is_device_is_explicitly_given
34
- logger = Capistrano::Logger.new(:output => STDOUT)
35
- STDOUT.expects(:close).never
36
- logger.close
37
- end
38
-
39
- def test_close_should_close_device_when_device_was_implicitly_opened
40
- f = mock("file", :close => nil)
41
- File.expects(:open).with("logs/capistrano.log", "a").returns(f)
42
- logger = Capistrano::Logger.new(:output => "logs/capistrano.log")
43
- logger.close
44
- end
45
-
46
- def test_log_with_level_greater_than_threshold_should_ignore_message
47
- @logger.level = 3
48
- @logger.log(4, "message")
49
- assert @io.string.empty?
50
- end
51
-
52
- def test_log_with_level_equal_to_threshold_should_log_message
53
- @logger.level = 3
54
- @logger.log(3, "message")
55
- assert @io.string.include?("message")
56
- end
57
-
58
- def test_log_with_level_less_than_threshold_should_log_message
59
- @logger.level = 3
60
- @logger.log(2, "message")
61
- assert @io.string.include?("message")
62
- end
63
-
64
- def test_log_with_multiline_message_should_log_each_line_separately
65
- @logger.log(0, "first line\nsecond line")
66
- assert @io.string.include?("*** first line")
67
- assert @io.string.include?("*** second line")
68
- end
69
-
70
- def test_log_with_line_prefix_should_insert_line_prefix_before_message
71
- @logger.log(0, "message", "prefix")
72
- assert @io.string.include?("*** [prefix] message")
73
- end
74
-
75
- def test_log_with_level_0_should_have_strong_indent
76
- @logger.log(0, "message")
77
- assert @io.string.match(/^\*\*\* message/)
78
- end
79
-
80
- def test_log_with_level_1_should_have_weaker_indent
81
- @logger.level = 1
82
- @logger.log(1, "message")
83
- assert @io.string.match(/^ \*\* message/)
84
- end
85
-
86
- def test_log_with_level_2_should_have_weaker_indent
87
- @logger.level = 2
88
- @logger.log(2, "message")
89
- assert @io.string.match(/^ \* message/)
90
- end
91
-
92
- def test_log_with_level_3_should_have_weakest_indent
93
- @logger.level = 3
94
- @logger.log(3, "message")
95
- assert @io.string.match(/^ message/)
96
- end
97
-
98
- def test_important_should_delegate_to_log_with_level_IMPORTANT
99
- @logger.expects(:log).with(Capistrano::Logger::IMPORTANT, "message", "prefix")
100
- @logger.important("message", "prefix")
101
- end
102
-
103
- def test_info_should_delegate_to_log_with_level_INFO
104
- @logger.expects(:log).with(Capistrano::Logger::INFO, "message", "prefix")
105
- @logger.info("message", "prefix")
106
- end
107
-
108
- def test_debug_should_delegate_to_log_with_level_DEBUG
109
- @logger.expects(:log).with(Capistrano::Logger::DEBUG, "message", "prefix")
110
- @logger.debug("message", "prefix")
111
- end
112
-
113
- def test_trace_should_delegate_to_log_with_level_TRACE
114
- @logger.expects(:log).with(Capistrano::Logger::TRACE, "message", "prefix")
115
- @logger.trace("message", "prefix")
116
- end
117
-
118
- def test_ordering_of_levels
119
- assert Capistrano::Logger::IMPORTANT < Capistrano::Logger::INFO
120
- assert Capistrano::Logger::INFO < Capistrano::Logger::DEBUG
121
- assert Capistrano::Logger::DEBUG < Capistrano::Logger::TRACE
122
- end
123
- end
@@ -1,108 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/utils"
2
- require 'capistrano/server_definition'
3
-
4
- class ServerDefinitionTest < Test::Unit::TestCase
5
- def test_new_without_credentials_or_port_should_set_values_to_defaults
6
- server = Capistrano::ServerDefinition.new("www.capistrano.test")
7
- assert_equal "www.capistrano.test", server.host
8
- assert_nil server.user
9
- assert_nil server.port
10
- end
11
-
12
- def test_new_with_encoded_user_should_extract_user_and_use_default_port
13
- server = Capistrano::ServerDefinition.new("jamis@www.capistrano.test")
14
- assert_equal "www.capistrano.test", server.host
15
- assert_equal "jamis", server.user
16
- assert_nil server.port
17
- end
18
-
19
- def test_new_with_encoded_port_should_extract_port_and_use_default_user
20
- server = Capistrano::ServerDefinition.new("www.capistrano.test:8080")
21
- assert_equal "www.capistrano.test", server.host
22
- assert_nil server.user
23
- assert_equal 8080, server.port
24
- end
25
-
26
- def test_new_with_encoded_user_and_port_should_extract_user_and_port
27
- server = Capistrano::ServerDefinition.new("jamis@www.capistrano.test:8080")
28
- assert_equal "www.capistrano.test", server.host
29
- assert_equal "jamis", server.user
30
- assert_equal 8080, server.port
31
- end
32
-
33
- def test_new_with_user_as_option_should_use_given_user
34
- server = Capistrano::ServerDefinition.new("www.capistrano.test", :user => "jamis")
35
- assert_equal "www.capistrano.test", server.host
36
- assert_equal "jamis", server.user
37
- assert_nil server.port
38
- end
39
-
40
- def test_new_with_port_as_option_should_use_given_user
41
- server = Capistrano::ServerDefinition.new("www.capistrano.test", :port => 8080)
42
- assert_equal "www.capistrano.test", server.host
43
- assert_nil server.user
44
- assert_equal 8080, server.port
45
- end
46
-
47
- def test_encoded_value_should_override_hash_option
48
- server = Capistrano::ServerDefinition.new("jamis@www.capistrano.test:8080", :user => "david", :port => 8081)
49
- assert_equal "www.capistrano.test", server.host
50
- assert_equal "jamis", server.user
51
- assert_equal 8080, server.port
52
- assert server.options.empty?
53
- end
54
-
55
- def test_new_with_option_should_dup_option_hash
56
- options = {}
57
- server = Capistrano::ServerDefinition.new("www.capistrano.test", options)
58
- assert_not_equal options.object_id, server.options.object_id
59
- end
60
-
61
- def test_new_with_options_should_keep_options
62
- server = Capistrano::ServerDefinition.new("www.capistrano.test", :primary => true)
63
- assert_equal true, server.options[:primary]
64
- end
65
-
66
- def test_comparison_should_match_when_host_user_port_are_same
67
- s1 = server("jamis@www.capistrano.test:8080")
68
- s2 = server("www.capistrano.test", :user => "jamis", :port => 8080)
69
- assert_equal s1, s2
70
- assert_equal s1.hash, s2.hash
71
- assert s1.eql?(s2)
72
- end
73
-
74
- def test_servers_should_be_comparable
75
- s1 = server("jamis@www.capistrano.test:8080")
76
- s2 = server("www.alphabet.test:1234")
77
- s3 = server("jamis@www.capistrano.test:8075")
78
- s4 = server("billy@www.capistrano.test:8080")
79
-
80
- assert s2 < s1
81
- assert s3 < s1
82
- assert s4 < s1
83
- assert s2 < s3
84
- assert s2 < s4
85
- assert s3 < s4
86
- end
87
-
88
- def test_comparison_should_not_match_when_any_of_host_user_port_differ
89
- s1 = server("jamis@www.capistrano.test:8080")
90
- s2 = server("bob@www.capistrano.test:8080")
91
- s3 = server("jamis@www.capistrano.test:8081")
92
- s4 = server("jamis@app.capistrano.test:8080")
93
- assert_not_equal s1, s2
94
- assert_not_equal s1, s3
95
- assert_not_equal s1, s4
96
- assert_not_equal s2, s3
97
- assert_not_equal s2, s4
98
- assert_not_equal s3, s4
99
- end
100
-
101
- def test_to_s
102
- assert_equal "www.capistrano.test", server("www.capistrano.test").to_s
103
- assert_equal "www.capistrano.test", server("www.capistrano.test:22").to_s
104
- assert_equal "www.capistrano.test:1234", server("www.capistrano.test:1234").to_s
105
- assert_equal "jamis@www.capistrano.test", server("jamis@www.capistrano.test").to_s
106
- assert_equal "jamis@www.capistrano.test:1234", server("jamis@www.capistrano.test:1234").to_s
107
- end
108
- end
data/test/shell_test.rb DELETED
@@ -1,64 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/utils"
2
- require 'capistrano/configuration'
3
- require 'capistrano/shell'
4
-
5
- class ShellTest < Test::Unit::TestCase
6
- def setup
7
- @config = Capistrano::Configuration.new
8
- @shell = Capistrano::Shell.new(@config)
9
- @shell.stubs(:puts)
10
- end
11
-
12
- def test_readline_fallback_prompt_should_write_to_stdout_and_read_from_stdin
13
- STDOUT.expects(:print).with("prompt> ")
14
- STDOUT.expects(:flush)
15
- STDIN.expects(:gets).returns("hi\n")
16
- assert_equal "hi\n", Capistrano::Shell::ReadlineFallback.readline("prompt> ")
17
- end
18
-
19
- def test_question_mark_as_input_should_trigger_help
20
- @shell.expects(:read_line).returns("?")
21
- @shell.expects(:help)
22
- assert @shell.read_and_execute
23
- end
24
-
25
- def test_help_as_input_should_trigger_help
26
- @shell.expects(:read_line).returns("help")
27
- @shell.expects(:help)
28
- assert @shell.read_and_execute
29
- end
30
-
31
- def test_quit_as_input_should_cause_read_and_execute_to_return_false
32
- @shell.expects(:read_line).returns("quit")
33
- assert !@shell.read_and_execute
34
- end
35
-
36
- def test_exit_as_input_should_cause_read_and_execute_to_return_false
37
- @shell.expects(:read_line).returns("exit")
38
- assert !@shell.read_and_execute
39
- end
40
-
41
- def test_set_should_parse_flag_and_value_and_call_set_option
42
- @shell.expects(:read_line).returns("set -v 5")
43
- @shell.expects(:set_option).with("v", "5")
44
- assert @shell.read_and_execute
45
- end
46
-
47
- def test_text_without_with_or_on_gets_processed_verbatim
48
- @shell.expects(:read_line).returns("hello world")
49
- @shell.expects(:process_command).with(nil, nil, "hello world")
50
- assert @shell.read_and_execute
51
- end
52
-
53
- def test_text_with_with_gets_processed_with_with # lol
54
- @shell.expects(:read_line).returns("with app,db hello world")
55
- @shell.expects(:process_command).with("with", "app,db", "hello world")
56
- assert @shell.read_and_execute
57
- end
58
-
59
- def test_text_with_on_gets_processed_with_on
60
- @shell.expects(:read_line).returns("on app,db hello world")
61
- @shell.expects(:process_command).with("on", "app,db", "hello world")
62
- assert @shell.read_and_execute
63
- end
64
- end
data/test/ssh_test.rb DELETED
@@ -1,97 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/utils"
2
- require 'capistrano/ssh'
3
-
4
- class SSHTest < Test::Unit::TestCase
5
- def setup
6
- @options = { :username => nil,
7
- :password => nil,
8
- :port => 22,
9
- :auth_methods => %w(publickey hostbased) }
10
- @server = server("capistrano")
11
- end
12
-
13
- def test_connect_with_bare_server_without_options_or_config_with_public_key_succeeding_should_only_loop_once
14
- Net::SSH.expects(:start).with(@server.host, @options).returns(success = Object.new)
15
- assert_equal success, Capistrano::SSH.connect(@server)
16
- end
17
-
18
- def test_connect_with_bare_server_without_options_with_public_key_failing_should_try_password
19
- Net::SSH.expects(:start).with(@server.host, @options).raises(Net::SSH::AuthenticationFailed)
20
- Net::SSH.expects(:start).with(@server.host, @options.merge(:password => "f4b13n", :auth_methods => %w(password keyboard-interactive))).returns(success = Object.new)
21
- assert_equal success, Capistrano::SSH.connect(@server, :password => "f4b13n")
22
- end
23
-
24
- def test_connect_with_bare_server_without_options_public_key_and_password_failing_should_raise_error
25
- Net::SSH.expects(:start).with(@server.host, @options).raises(Net::SSH::AuthenticationFailed)
26
- Net::SSH.expects(:start).with(@server.host, @options.merge(:password => "f4b13n", :auth_methods => %w(password keyboard-interactive))).raises(Net::SSH::AuthenticationFailed)
27
- assert_raises(Net::SSH::AuthenticationFailed) do
28
- Capistrano::SSH.connect(@server, :password => "f4b13n")
29
- end
30
- end
31
-
32
- def test_connect_with_bare_server_and_user_via_public_key_should_pass_user_to_net_ssh
33
- Net::SSH.expects(:start).with(@server.host, @options.merge(:username => "jamis")).returns(success = Object.new)
34
- assert_equal success, Capistrano::SSH.connect(@server, :user => "jamis")
35
- end
36
-
37
- def test_connect_with_bare_server_and_user_via_password_should_pass_user_to_net_ssh
38
- Net::SSH.expects(:start).with(@server.host, @options.merge(:username => "jamis")).raises(Net::SSH::AuthenticationFailed)
39
- Net::SSH.expects(:start).with(@server.host, @options.merge(:username => "jamis", :password => "f4b13n", :auth_methods => %w(password keyboard-interactive))).returns(success = Object.new)
40
- assert_equal success, Capistrano::SSH.connect(@server, :user => "jamis", :password => "f4b13n")
41
- end
42
-
43
- def test_connect_with_bare_server_with_explicit_port_should_pass_port_to_net_ssh
44
- Net::SSH.expects(:start).with(@server.host, @options.merge(:port => 1234)).returns(success = Object.new)
45
- assert_equal success, Capistrano::SSH.connect(@server, :port => 1234)
46
- end
47
-
48
- def test_connect_with_server_with_user_should_pass_user_to_net_ssh
49
- server = server("jamis@capistrano")
50
- Net::SSH.expects(:start).with(server.host, @options.merge(:username => "jamis")).returns(success = Object.new)
51
- assert_equal success, Capistrano::SSH.connect(server)
52
- end
53
-
54
- def test_connect_with_server_with_port_should_pass_port_to_net_ssh
55
- server = server("capistrano:1235")
56
- Net::SSH.expects(:start).with(server.host, @options.merge(:port => 1235)).returns(success = Object.new)
57
- assert_equal success, Capistrano::SSH.connect(server)
58
- end
59
-
60
- def test_connect_with_server_with_user_and_port_should_pass_user_and_port_to_net_ssh
61
- server = server("jamis@capistrano:1235")
62
- Net::SSH.expects(:start).with(server.host, @options.merge(:username => "jamis", :port => 1235)).returns(success = Object.new)
63
- assert_equal success, Capistrano::SSH.connect(server)
64
- end
65
-
66
- def test_connect_with_ssh_options_should_use_ssh_options
67
- ssh_options = { :username => "JamisMan", :port => 8125 }
68
- Net::SSH.expects(:start).with(@server.host, @options.merge(:username => "JamisMan", :port => 8125)).returns(success = Object.new)
69
- assert_equal success, Capistrano::SSH.connect(@server, {:ssh_options => ssh_options})
70
- end
71
-
72
- def test_connect_with_options_and_ssh_options_should_see_options_override_ssh_options
73
- ssh_options = { :username => "JamisMan", :port => 8125, :forward_agent => true }
74
- Net::SSH.expects(:start).with(@server.host, @options.merge(:username => "jamis", :port => 1235, :forward_agent => true)).returns(success = Object.new)
75
- assert_equal success, Capistrano::SSH.connect(@server, {:ssh_options => ssh_options, :user => "jamis", :port => 1235})
76
- end
77
-
78
- def test_connect_with_ssh_options_should_see_server_options_override_ssh_options
79
- ssh_options = { :username => "JamisMan", :port => 8125, :forward_agent => true }
80
- server = server("jamis@capistrano:1235")
81
- Net::SSH.expects(:start).with(server.host, @options.merge(:username => "jamis", :port => 1235, :forward_agent => true)).returns(success = Object.new)
82
- assert_equal success, Capistrano::SSH.connect(server, {:ssh_options => ssh_options})
83
- end
84
-
85
- def test_connect_should_add_xserver_accessor_to_connection
86
- Net::SSH.expects(:start).with(@server.host, @options).returns(success = Object.new)
87
- assert_equal success, Capistrano::SSH.connect(@server)
88
- assert success.respond_to?(:xserver)
89
- assert success.respond_to?(:xserver)
90
- assert_equal success.xserver, @server
91
- end
92
-
93
- def test_connect_should_not_retry_if_custom_auth_methods_are_given
94
- Net::SSH.expects(:start).with(@server.host, @options.merge(:auth_methods => %w(publickey))).raises(Net::SSH::AuthenticationFailed)
95
- assert_raises(Net::SSH::AuthenticationFailed) { Capistrano::SSH.connect(@server, :ssh_options => { :auth_methods => %w(publickey) }) }
96
- end
97
- end
@@ -1,101 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/utils"
2
- require 'capistrano/task_definition'
3
-
4
- class TaskDefinitionTest < Test::Unit::TestCase
5
- def setup
6
- @namespace = namespace
7
- end
8
-
9
- def test_fqn_at_top_level_should_be_task_name
10
- task = new_task(:testing)
11
- assert_equal "testing", task.fully_qualified_name
12
- end
13
-
14
- def test_fqn_in_namespace_should_include_namespace_fqn
15
- ns = namespace("outer:inner")
16
- task = new_task(:testing, ns)
17
- assert_equal "outer:inner:testing", task.fully_qualified_name
18
- end
19
-
20
- def test_fqn_at_top_level_when_default_should_be_default
21
- task = new_task(:default)
22
- assert_equal "default", task.fully_qualified_name
23
- end
24
-
25
- def test_fqn_in_namespace_when_default_should_be_namespace_fqn
26
- ns = namespace("outer:inner")
27
- task = new_task(:default, ns)
28
- ns.stubs(:default_task => task)
29
- assert_equal "outer:inner", task.fully_qualified_name
30
- end
31
-
32
- def test_task_should_require_block
33
- assert_raises(ArgumentError) do
34
- Capistrano::TaskDefinition.new(:testing, @namespace)
35
- end
36
- end
37
-
38
- def test_description_should_return_empty_string_if_not_given
39
- assert_equal "", new_task(:testing).description
40
- end
41
-
42
- def test_description_should_return_desc_attribute
43
- assert_equal "something", new_task(:testing, @namespace, :desc => "something").description
44
- end
45
-
46
- def test_description_should_strip_leading_and_trailing_whitespace
47
- assert_equal "something", new_task(:testing, @namespace, :desc => " something ").description
48
- end
49
-
50
- def test_description_should_normalize_newlines
51
- assert_equal "a\nb\nc", new_task(:testing, @namespace, :desc => "a\nb\r\nc").description
52
- end
53
-
54
- def test_description_should_detect_and_remove_indentation
55
- desc = <<-DESC
56
- Here is some indented text \
57
- and I want all of this to \
58
- run together on a single line, \
59
- without any extraneous spaces.
60
-
61
- additional indentation will
62
- be preserved.
63
- DESC
64
-
65
- task = new_task(:testing, @namespace, :desc => desc)
66
- assert_equal "Here is some indented text and I want all of this to run together on a single line, without any extraneous spaces.\n\n additional indentation will\n be preserved.", task.description
67
- end
68
-
69
- def test_description_munging_should_be_sensitive_to_code_blocks
70
- desc = <<-DESC
71
- Here is a line \
72
- wrapped with spacing in it.
73
-
74
- foo bar
75
- baz bang
76
- DESC
77
-
78
- task = new_task(:testing, @namespace, :desc => desc)
79
- assert_equal "Here is a line wrapped with spacing in it.\n\n foo bar\n baz bang", task.description
80
- end
81
-
82
- def test_brief_description_should_return_first_sentence_in_description
83
- desc = "This is the task. It does all kinds of things."
84
- task = new_task(:testing, @namespace, :desc => desc)
85
- assert_equal "This is the task.", task.brief_description
86
- end
87
-
88
- def test_brief_description_should_truncate_if_length_given
89
- desc = "This is the task that does all kinds of things. And then some."
90
- task = new_task(:testing, @namespace, :desc => desc)
91
- assert_equal "This is the task ...", task.brief_description(20)
92
- end
93
-
94
- def test_brief_description_should_not_break_at_period_in_middle_of_sentence
95
- task = new_task(:testing, @namespace, :desc => "Take file.txt and copy it.")
96
- assert_equal "Take file.txt and copy it.", task.brief_description
97
-
98
- task = new_task(:testing, @namespace, :desc => "Take file.txt and copy it. Then do something else.")
99
- assert_equal "Take file.txt and copy it.", task.brief_description
100
- end
101
- end