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,218 +0,0 @@
1
- require 'net/scp'
2
- require 'net/sftp'
3
-
4
- require 'capistrano/processable'
5
-
6
- module Capistrano
7
- class Transfer
8
- include Processable
9
-
10
- def self.process(direction, from, to, sessions, options={}, &block)
11
- new(direction, from, to, sessions, options, &block).process!
12
- end
13
-
14
- attr_reader :sessions
15
- attr_reader :options
16
- attr_reader :callback
17
-
18
- attr_reader :transport
19
- attr_reader :direction
20
- attr_reader :from
21
- attr_reader :to
22
-
23
- attr_reader :logger
24
- attr_reader :transfers
25
-
26
- def initialize(direction, from, to, sessions, options={}, &block)
27
- @direction = direction
28
- @from = from
29
- @to = to
30
- @sessions = sessions
31
- @options = options
32
- @callback = block
33
-
34
- @transport = options.fetch(:via, :sftp)
35
- @logger = options.delete(:logger)
36
-
37
- @session_map = {}
38
-
39
- prepare_transfers
40
- end
41
-
42
- def process!
43
- loop do
44
- begin
45
- break unless process_iteration { active? }
46
- rescue Exception => error
47
- if error.respond_to?(:session)
48
- handle_error(error)
49
- else
50
- raise
51
- end
52
- end
53
- end
54
-
55
- failed = transfers.select { |txfr| txfr[:failed] }
56
- if failed.any?
57
- hosts = failed.map { |txfr| txfr[:server] }
58
- errors = failed.map { |txfr| "#{txfr[:error]} (#{txfr[:error].message})" }.uniq.join(", ")
59
- error = TransferError.new("#{operation} via #{transport} failed on #{hosts.join(',')}: #{errors}")
60
- error.hosts = hosts
61
-
62
- logger.important(error.message) if logger
63
- raise error
64
- end
65
-
66
- logger.debug "#{transport} #{operation} complete" if logger
67
- self
68
- end
69
-
70
- def active?
71
- transfers.any? { |transfer| transfer.active? }
72
- end
73
-
74
- def operation
75
- "#{direction}load"
76
- end
77
-
78
- def sanitized_from
79
- if from.responds_to?(:read)
80
- "#<#{from.class}>"
81
- else
82
- from
83
- end
84
- end
85
-
86
- def sanitized_to
87
- if to.responds_to?(:read)
88
- "#<#{to.class}>"
89
- else
90
- to
91
- end
92
- end
93
-
94
- private
95
-
96
- def session_map
97
- @session_map
98
- end
99
-
100
- def prepare_transfers
101
- logger.info "#{transport} #{operation} #{from} -> #{to}" if logger
102
-
103
- @transfers = sessions.map do |session|
104
- session_from = normalize(from, session)
105
- session_to = normalize(to, session)
106
-
107
- session_map[session] = case transport
108
- when :sftp
109
- prepare_sftp_transfer(session_from, session_to, session)
110
- when :scp
111
- prepare_scp_transfer(session_from, session_to, session)
112
- else
113
- raise ArgumentError, "unsupported transport type: #{transport.inspect}"
114
- end
115
- end
116
- end
117
-
118
- def prepare_scp_transfer(from, to, session)
119
- real_callback = callback || Proc.new do |channel, name, sent, total|
120
- logger.trace "[#{channel[:host]}] #{name}" if logger && sent == 0
121
- end
122
-
123
- channel = case direction
124
- when :up
125
- session.scp.upload(from, to, options, &real_callback)
126
- when :down
127
- session.scp.download(from, to, options, &real_callback)
128
- else
129
- raise ArgumentError, "unsupported transfer direction: #{direction.inspect}"
130
- end
131
-
132
- channel[:server] = session.xserver
133
- channel[:host] = session.xserver.host
134
-
135
- return channel
136
- end
137
-
138
- class SFTPTransferWrapper
139
- attr_reader :operation
140
-
141
- def initialize(session, &callback)
142
- session.sftp(false).connect do |sftp|
143
- @operation = callback.call(sftp)
144
- end
145
- end
146
-
147
- def active?
148
- @operation.nil? || @operation.active?
149
- end
150
-
151
- def [](key)
152
- @operation[key]
153
- end
154
-
155
- def []=(key, value)
156
- @operation[key] = value
157
- end
158
-
159
- def abort!
160
- @operation.abort!
161
- end
162
- end
163
-
164
- def prepare_sftp_transfer(from, to, session)
165
- SFTPTransferWrapper.new(session) do |sftp|
166
- real_callback = Proc.new do |event, op, *args|
167
- if callback
168
- callback.call(event, op, *args)
169
- elsif event == :open
170
- logger.trace "[#{op[:host]}] #{args[0].remote}"
171
- elsif event == :finish
172
- logger.trace "[#{op[:host]}] done"
173
- end
174
- end
175
-
176
- opts = options.dup
177
- opts[:properties] = (opts[:properties] || {}).merge(
178
- :server => session.xserver,
179
- :host => session.xserver.host)
180
-
181
- case direction
182
- when :up
183
- sftp.upload(from, to, opts, &real_callback)
184
- when :down
185
- sftp.download(from, to, opts, &real_callback)
186
- else
187
- raise ArgumentError, "unsupported transfer direction: #{direction.inspect}"
188
- end
189
- end
190
- end
191
-
192
- def normalize(argument, session)
193
- if argument.is_a?(String)
194
- argument.gsub(/\$CAPISTRANO:HOST\$/, session.xserver.host)
195
- elsif argument.respond_to?(:read)
196
- pos = argument.pos
197
- clone = StringIO.new(argument.read)
198
- clone.pos = argument.pos = pos
199
- clone
200
- else
201
- argument
202
- end
203
- end
204
-
205
- def handle_error(error)
206
- raise error if error.message.include?('expected a file to upload')
207
-
208
- transfer = session_map[error.session]
209
- transfer[:error] = error
210
- transfer[:failed] = true
211
-
212
- case transport
213
- when :sftp then transfer.abort!
214
- when :scp then transfer.close
215
- end
216
- end
217
- end
218
- end
@@ -1,132 +0,0 @@
1
- require "utils"
2
- require 'capistrano/cli/execute'
3
-
4
- class CLIExecuteTest < Test::Unit::TestCase
5
- class MockCLI
6
- attr_reader :options
7
-
8
- def initialize
9
- @options = {}
10
- end
11
-
12
- include Capistrano::CLI::Execute
13
- end
14
-
15
- def setup
16
- @cli = MockCLI.new
17
- @logger = stub_everything
18
- @config = stub(:logger => @logger, :debug= => nil, :dry_run= => nil, :preserve_roles= => nil)
19
- @config.stubs(:set)
20
- @config.stubs(:load)
21
- @config.stubs(:trigger)
22
- @cli.stubs(:instantiate_configuration).returns(@config)
23
- end
24
-
25
- def test_execute_should_set_logger_verbosity
26
- @cli.options[:verbose] = 7
27
- @logger.expects(:level=).with(7)
28
- @cli.execute!
29
- end
30
-
31
- def test_execute_should_set_password
32
- @cli.options[:password] = "nosoup4u"
33
- @config.expects(:set).with(:password, "nosoup4u")
34
- @cli.execute!
35
- end
36
-
37
- def test_execute_should_set_prevars_before_loading
38
- @config.expects(:load).never
39
- @config.expects(:set).with(:stage, "foobar")
40
- @config.expects(:load).with("standard")
41
- @cli.options[:pre_vars] = { :stage => "foobar" }
42
- @cli.execute!
43
- end
44
-
45
- def test_execute_should_load_sysconf_if_sysconf_set_and_exists
46
- @cli.options[:sysconf] = "/etc/capistrano.conf"
47
- @config.expects(:load).with("/etc/capistrano.conf")
48
- File.expects(:file?).with("/etc/capistrano.conf").returns(true)
49
- @cli.execute!
50
- end
51
-
52
- def test_execute_should_not_load_sysconf_when_sysconf_set_and_not_exists
53
- @cli.options[:sysconf] = "/etc/capistrano.conf"
54
- File.expects(:file?).with("/etc/capistrano.conf").returns(false)
55
- @cli.execute!
56
- end
57
-
58
- def test_execute_should_load_dotfile_if_dotfile_set_and_exists
59
- @cli.options[:dotfile] = "/home/jamis/.caprc"
60
- @config.expects(:load).with("/home/jamis/.caprc")
61
- File.expects(:file?).with("/home/jamis/.caprc").returns(true)
62
- @cli.execute!
63
- end
64
-
65
- def test_execute_should_not_load_dotfile_when_dotfile_set_and_not_exists
66
- @cli.options[:dotfile] = "/home/jamis/.caprc"
67
- File.expects(:file?).with("/home/jamis/.caprc").returns(false)
68
- @cli.execute!
69
- end
70
-
71
- def test_execute_should_load_recipes_when_recipes_are_given
72
- @cli.options[:recipes] = %w(config/deploy path/to/extra)
73
- @config.expects(:load).with("config/deploy")
74
- @config.expects(:load).with("path/to/extra")
75
- @cli.execute!
76
- end
77
-
78
- def test_execute_should_set_vars_and_execute_tasks
79
- @cli.options[:vars] = { :foo => "bar", :baz => "bang" }
80
- @cli.options[:actions] = %w(first second)
81
- @config.expects(:set).with(:foo, "bar")
82
- @config.expects(:set).with(:baz, "bang")
83
- @config.expects(:find_and_execute_task).with("first", :before => :start, :after => :finish)
84
- @config.expects(:find_and_execute_task).with("second", :before => :start, :after => :finish)
85
- @cli.execute!
86
- end
87
-
88
- def test_execute_should_call_load_and_exit_triggers
89
- @cli.options[:actions] = %w(first second)
90
- @config.expects(:find_and_execute_task).with("first", :before => :start, :after => :finish)
91
- @config.expects(:find_and_execute_task).with("second", :before => :start, :after => :finish)
92
- @config.expects(:trigger).never
93
- @config.expects(:trigger).with(:load)
94
- @config.expects(:trigger).with(:exit)
95
- @cli.execute!
96
- end
97
-
98
- def test_execute_should_call_handle_error_when_exceptions_occur
99
- @config.expects(:load).raises(Exception, "boom")
100
- @cli.expects(:handle_error).with { |e,| Exception === e }
101
- @cli.execute!
102
- end
103
-
104
- def test_execute_should_return_config_instance
105
- assert_equal @config, @cli.execute!
106
- end
107
-
108
- def test_instantiate_configuration_should_return_new_configuration_instance
109
- assert_instance_of Capistrano::Configuration, MockCLI.new.instantiate_configuration
110
- end
111
-
112
- def test_handle_error_with_auth_error_should_abort_with_message_including_user_name
113
- @cli.expects(:abort).with { |s| s.include?("jamis") }
114
- @cli.handle_error(Net::SSH::AuthenticationFailed.new("jamis"))
115
- end
116
-
117
- def test_handle_error_with_cap_error_should_abort_with_message
118
- @cli.expects(:abort).with("Wish you were here")
119
- @cli.handle_error(Capistrano::Error.new("Wish you were here"))
120
- end
121
-
122
- def test_handle_error_with_other_errors_should_reraise_error
123
- other_error = Class.new(RuntimeError)
124
- assert_raises(other_error) { @cli.handle_error(other_error.new("boom")) }
125
- end
126
-
127
- def test_class_execute_method_should_call_parse_and_execute_with_ARGV
128
- cli = mock(:execute! => nil)
129
- MockCLI.expects(:parse).with(ARGV).returns(cli)
130
- MockCLI.execute
131
- end
132
- end
@@ -1,165 +0,0 @@
1
- require "utils"
2
- require 'capistrano/cli/help'
3
-
4
- class CLIHelpTest < Test::Unit::TestCase
5
- class MockCLI
6
- attr_reader :options, :called_original
7
-
8
- def initialize
9
- @options = {}
10
- @called_original = false
11
- end
12
-
13
- def execute_requested_actions(config)
14
- @called_original = config
15
- end
16
-
17
- include Capistrano::CLI::Help
18
- end
19
-
20
- def setup
21
- @cli = MockCLI.new
22
- @cli.options[:verbose] = 0
23
- @ui = stub("ui", :output_cols => 80, :output_rows => 20, :page_at= => nil)
24
- MockCLI.stubs(:ui).returns(@ui)
25
- end
26
-
27
- def test_execute_requested_actions_without_tasks_or_explain_should_call_original
28
- @cli.execute_requested_actions(:config)
29
- @cli.expects(:task_list).never
30
- @cli.expects(:explain_task).never
31
- assert_equal :config, @cli.called_original
32
- end
33
-
34
- def test_execute_requested_actions_with_tasks_should_call_task_list
35
- @cli.options[:tasks] = true
36
- @cli.expects(:task_list).with(:config, true)
37
- @cli.expects(:explain_task).never
38
- @cli.execute_requested_actions(:config)
39
- assert !@cli.called_original
40
- end
41
-
42
- def test_execute_requested_actions_with_explain_should_call_explain_task
43
- @cli.options[:explain] = "deploy_with_niftiness"
44
- @cli.expects(:task_list).never
45
- @cli.expects(:explain_task).with(:config, "deploy_with_niftiness")
46
- @cli.execute_requested_actions(:config)
47
- assert !@cli.called_original
48
- end
49
-
50
- def test_task_list_with_no_tasks_should_emit_warning
51
- config = mock("config", :task_list => [])
52
- @cli.expects(:warn)
53
- @cli.task_list(config)
54
- end
55
-
56
- def test_task_list_should_query_all_tasks_in_all_namespaces
57
- expected_max_len = 80 - 3 - MockCLI::LINE_PADDING
58
- task_list = [task("c"), task("g", "c:g"), task("b", "c:b"), task("a")]
59
- task_list.each { |t| t.expects(:brief_description).with(expected_max_len).returns(t.fully_qualified_name) }
60
-
61
- config = mock("config")
62
- config.expects(:task_list).with(:all).returns(task_list)
63
- @cli.stubs(:puts)
64
- @cli.task_list(config)
65
- end
66
-
67
- def test_task_list_should_query_tasks_with_pattern
68
- expected_max_len = 80 - 3 - MockCLI::LINE_PADDING
69
- task_list = [task("g", "c:g"), task("b", "c:b")]
70
- task_list.each { |t| t.expects(:brief_description).with(expected_max_len).returns(t.fully_qualified_name)}
71
-
72
- config = mock("config")
73
- config.expects(:task_list).with(:all).once.returns(task_list)
74
-
75
- @cli.stubs(:puts)
76
- @cli.task_list(config, "c")
77
- end
78
-
79
- def test_task_list_should_query_for_all_tasks_when_pattern_doesnt_match
80
- expected_max_len = 80 - 3 - MockCLI::LINE_PADDING
81
- task_list = [task("g", "c:g"), task("b", "c:b")]
82
- task_list.each { |t| t.expects(:brief_description).with(expected_max_len).returns(t.fully_qualified_name) }
83
-
84
- config = mock("config")
85
- config.expects(:task_list).with(:all).times(2).returns(task_list)
86
-
87
- @cli.stubs(:warn)
88
- @cli.stubs(:puts)
89
- @cli.task_list(config, "z")
90
- end
91
-
92
- def test_task_list_should_never_use_less_than_MIN_MAX_LEN_chars_for_descriptions
93
- @ui.stubs(:output_cols).returns(20)
94
- t = task("c")
95
- t.expects(:brief_description).with(30).returns("hello")
96
- config = mock("config", :task_list => [t])
97
- @cli.stubs(:puts)
98
- @cli.task_list(config)
99
- end
100
-
101
- def test_task_list_should_not_include_tasks_with_blank_description_or_internal_by_default
102
- t1 = task("c")
103
- t1.expects(:brief_description).returns("hello")
104
- t2 = task("d", "d", "[internal] howdy")
105
- t2.expects(:brief_description).never
106
- t3 = task("e", "e", "")
107
- t3.expects(:brief_description).never
108
-
109
- config = mock("config", :task_list => [t1, t2, t3])
110
- @cli.stubs(:puts)
111
- @cli.expects(:puts).never.with { |s,| (s || "").include?("[internal]") || s =~ /#\s*$/ }
112
- @cli.task_list(config)
113
- end
114
-
115
- def test_task_list_should_include_tasks_with_blank_descriptions_and_internal_when_verbose
116
- t1 = task("c")
117
- t1.expects(:brief_description).returns("hello")
118
- t2 = task("d", "d", "[internal] howdy")
119
- t2.expects(:brief_description).returns("[internal] howdy")
120
- t3 = task("e", "e", "")
121
- t3.expects(:brief_description).returns("")
122
-
123
- config = mock("config", :task_list => [t1, t2, t3])
124
- @cli.options[:verbose] = 1
125
- @cli.stubs(:puts)
126
- @cli.expects(:puts).with { |s,| (s || "").include?("[internal]") || s =~ /#\s*$/ }.at_least_once
127
- @cli.task_list(config)
128
- end
129
-
130
- def test_explain_task_should_warn_if_task_does_not_exist
131
- config = mock("config", :find_task => nil)
132
- @cli.expects(:warn).with { |s,| s =~ /`deploy_with_niftiness'/ }
133
- @cli.explain_task(config, "deploy_with_niftiness")
134
- end
135
-
136
- def test_explain_task_with_task_that_has_no_description_should_emit_stub
137
- t = mock("task", :description => "")
138
- config = mock("config")
139
- config.expects(:find_task).with("deploy_with_niftiness").returns(t)
140
- @cli.stubs(:puts)
141
- @cli.expects(:puts).with("There is no description for this task.")
142
- @cli.explain_task(config, "deploy_with_niftiness")
143
- end
144
-
145
- def test_explain_task_with_task_should_format_description
146
- t = stub("task", :description => "line1\nline2\n\nline3")
147
- config = mock("config", :find_task => t)
148
- @cli.stubs(:puts)
149
- @cli.explain_task(config, "deploy_with_niftiness")
150
- end
151
-
152
- def test_long_help_should_load_and_format_help_txt_file
153
- File.expects(:dirname).returns "a/b/c"
154
- File.expects(:read).with("a/b/c/help.txt").returns("text")
155
- @ui.expects(:say).with("text\n")
156
- @cli.long_help
157
- end
158
-
159
- private
160
-
161
- def task(name, fqn=name, desc="a description")
162
- stub("task", :name => name, :fully_qualified_name => fqn, :description => desc)
163
- end
164
-
165
- end