minmb-capistrano 2.15.4

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 (119) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +7 -0
  3. data/CHANGELOG +1170 -0
  4. data/Gemfile +13 -0
  5. data/README.md +94 -0
  6. data/Rakefile +11 -0
  7. data/bin/cap +4 -0
  8. data/bin/capify +92 -0
  9. data/capistrano.gemspec +40 -0
  10. data/lib/capistrano.rb +5 -0
  11. data/lib/capistrano/callback.rb +45 -0
  12. data/lib/capistrano/cli.rb +47 -0
  13. data/lib/capistrano/cli/execute.rb +85 -0
  14. data/lib/capistrano/cli/help.rb +125 -0
  15. data/lib/capistrano/cli/help.txt +81 -0
  16. data/lib/capistrano/cli/options.rb +243 -0
  17. data/lib/capistrano/cli/ui.rb +40 -0
  18. data/lib/capistrano/command.rb +303 -0
  19. data/lib/capistrano/configuration.rb +57 -0
  20. data/lib/capistrano/configuration/actions/file_transfer.rb +50 -0
  21. data/lib/capistrano/configuration/actions/inspect.rb +46 -0
  22. data/lib/capistrano/configuration/actions/invocation.rb +329 -0
  23. data/lib/capistrano/configuration/alias_task.rb +26 -0
  24. data/lib/capistrano/configuration/callbacks.rb +147 -0
  25. data/lib/capistrano/configuration/connections.rb +237 -0
  26. data/lib/capistrano/configuration/execution.rb +142 -0
  27. data/lib/capistrano/configuration/loading.rb +205 -0
  28. data/lib/capistrano/configuration/log_formatters.rb +75 -0
  29. data/lib/capistrano/configuration/namespaces.rb +223 -0
  30. data/lib/capistrano/configuration/roles.rb +77 -0
  31. data/lib/capistrano/configuration/servers.rb +116 -0
  32. data/lib/capistrano/configuration/variables.rb +127 -0
  33. data/lib/capistrano/errors.rb +19 -0
  34. data/lib/capistrano/ext/multistage.rb +64 -0
  35. data/lib/capistrano/ext/string.rb +5 -0
  36. data/lib/capistrano/extensions.rb +57 -0
  37. data/lib/capistrano/fix_rake_deprecated_dsl.rb +8 -0
  38. data/lib/capistrano/logger.rb +166 -0
  39. data/lib/capistrano/processable.rb +57 -0
  40. data/lib/capistrano/recipes/compat.rb +32 -0
  41. data/lib/capistrano/recipes/deploy.rb +625 -0
  42. data/lib/capistrano/recipes/deploy/assets.rb +201 -0
  43. data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
  44. data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
  45. data/lib/capistrano/recipes/deploy/remote_dependency.rb +117 -0
  46. data/lib/capistrano/recipes/deploy/scm.rb +19 -0
  47. data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
  48. data/lib/capistrano/recipes/deploy/scm/base.rb +200 -0
  49. data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
  50. data/lib/capistrano/recipes/deploy/scm/cvs.rb +153 -0
  51. data/lib/capistrano/recipes/deploy/scm/darcs.rb +96 -0
  52. data/lib/capistrano/recipes/deploy/scm/git.rb +293 -0
  53. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
  54. data/lib/capistrano/recipes/deploy/scm/none.rb +55 -0
  55. data/lib/capistrano/recipes/deploy/scm/perforce.rb +152 -0
  56. data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
  57. data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
  58. data/lib/capistrano/recipes/deploy/strategy/base.rb +92 -0
  59. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
  60. data/lib/capistrano/recipes/deploy/strategy/copy.rb +338 -0
  61. data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
  62. data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
  63. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +57 -0
  64. data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +21 -0
  65. data/lib/capistrano/recipes/standard.rb +37 -0
  66. data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
  67. data/lib/capistrano/role.rb +102 -0
  68. data/lib/capistrano/server_definition.rb +56 -0
  69. data/lib/capistrano/shell.rb +265 -0
  70. data/lib/capistrano/ssh.rb +95 -0
  71. data/lib/capistrano/task_definition.rb +77 -0
  72. data/lib/capistrano/transfer.rb +218 -0
  73. data/lib/capistrano/version.rb +11 -0
  74. data/test/cli/execute_test.rb +132 -0
  75. data/test/cli/help_test.rb +165 -0
  76. data/test/cli/options_test.rb +329 -0
  77. data/test/cli/ui_test.rb +28 -0
  78. data/test/cli_test.rb +17 -0
  79. data/test/command_test.rb +322 -0
  80. data/test/configuration/actions/file_transfer_test.rb +61 -0
  81. data/test/configuration/actions/inspect_test.rb +76 -0
  82. data/test/configuration/actions/invocation_test.rb +288 -0
  83. data/test/configuration/alias_task_test.rb +118 -0
  84. data/test/configuration/callbacks_test.rb +201 -0
  85. data/test/configuration/connections_test.rb +439 -0
  86. data/test/configuration/execution_test.rb +175 -0
  87. data/test/configuration/loading_test.rb +148 -0
  88. data/test/configuration/namespace_dsl_test.rb +332 -0
  89. data/test/configuration/roles_test.rb +157 -0
  90. data/test/configuration/servers_test.rb +183 -0
  91. data/test/configuration/variables_test.rb +190 -0
  92. data/test/configuration_test.rb +77 -0
  93. data/test/deploy/local_dependency_test.rb +76 -0
  94. data/test/deploy/remote_dependency_test.rb +146 -0
  95. data/test/deploy/scm/accurev_test.rb +23 -0
  96. data/test/deploy/scm/base_test.rb +55 -0
  97. data/test/deploy/scm/bzr_test.rb +51 -0
  98. data/test/deploy/scm/darcs_test.rb +37 -0
  99. data/test/deploy/scm/git_test.rb +221 -0
  100. data/test/deploy/scm/mercurial_test.rb +134 -0
  101. data/test/deploy/scm/none_test.rb +35 -0
  102. data/test/deploy/scm/perforce_test.rb +23 -0
  103. data/test/deploy/scm/subversion_test.rb +40 -0
  104. data/test/deploy/strategy/copy_test.rb +360 -0
  105. data/test/extensions_test.rb +69 -0
  106. data/test/fixtures/cli_integration.rb +5 -0
  107. data/test/fixtures/config.rb +5 -0
  108. data/test/fixtures/custom.rb +3 -0
  109. data/test/logger_formatting_test.rb +149 -0
  110. data/test/logger_test.rb +134 -0
  111. data/test/recipes_test.rb +25 -0
  112. data/test/role_test.rb +11 -0
  113. data/test/server_definition_test.rb +121 -0
  114. data/test/shell_test.rb +96 -0
  115. data/test/ssh_test.rb +113 -0
  116. data/test/task_definition_test.rb +117 -0
  117. data/test/transfer_test.rb +168 -0
  118. data/test/utils.rb +37 -0
  119. metadata +316 -0
@@ -0,0 +1,165 @@
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
@@ -0,0 +1,329 @@
1
+ require "utils"
2
+ require 'capistrano/cli/options'
3
+
4
+ class CLIOptionsTest < Test::Unit::TestCase
5
+ class ExitException < Exception; end
6
+
7
+ class MockCLI
8
+ def initialize
9
+ @args = []
10
+ end
11
+
12
+ attr_reader :args
13
+
14
+ include Capistrano::CLI::Options
15
+ end
16
+
17
+ def setup
18
+ @cli = MockCLI.new
19
+ end
20
+
21
+ def test_parse_options_should_require_non_empty_args_list
22
+ @cli.stubs(:warn)
23
+ @cli.expects(:exit).raises(ExitException)
24
+ assert_raises(ExitException) { @cli.parse_options! }
25
+ end
26
+
27
+ def test_parse_options_with_d_should_set_debug_option
28
+ @cli.args << "-d"
29
+ @cli.parse_options!
30
+ assert @cli.options[:debug]
31
+ end
32
+
33
+ def test_parse_options_with_n_should_set_dry_run_option
34
+ @cli.args << "-n"
35
+ @cli.parse_options!
36
+ assert @cli.options[:dry_run]
37
+ end
38
+
39
+ def test_parse_options_with_dry_run_should_set_dry_run_option
40
+ @cli.args << "--dry-run"
41
+ @cli.parse_options!
42
+ assert @cli.options[:dry_run]
43
+ end
44
+
45
+ def test_parse_options_with_e_should_set_explain_option
46
+ @cli.args << "-e" << "sample"
47
+ @cli.parse_options!
48
+ assert_equal "sample", @cli.options[:explain]
49
+ end
50
+
51
+ def test_parse_options_with_f_should_add_recipe_file
52
+ @cli.args << "-f" << "deploy"
53
+ @cli.parse_options!
54
+ assert_equal %w(deploy), @cli.options[:recipes]
55
+ end
56
+
57
+ def test_parse_options_with_multiple_f_should_add_each_as_recipe_file
58
+ @cli.args << "-f" << "deploy" << "-f" << "monitor"
59
+ @cli.parse_options!
60
+ assert_equal %w(deploy monitor), @cli.options[:recipes]
61
+ end
62
+
63
+ def test_parse_options_with_H_should_show_verbose_help_and_exit
64
+ @cli.expects(:exit).raises(ExitException)
65
+ @cli.expects(:long_help)
66
+ @cli.args << "-H"
67
+ assert_raises(ExitException) { @cli.parse_options! }
68
+ end
69
+
70
+ def test_parse_options_with_h_should_show_options_and_exit
71
+ @cli.expects(:puts).with(@cli.option_parser)
72
+ @cli.expects(:exit).raises(ExitException)
73
+ @cli.args << "-h"
74
+ assert_raises(ExitException) { @cli.parse_options! }
75
+ end
76
+
77
+ def test_parse_options_with_p_should_prompt_for_password
78
+ MockCLI.expects(:password_prompt).returns(:the_password)
79
+ @cli.args << "-p"
80
+ @cli.parse_options!
81
+ assert_equal :the_password, @cli.options[:password]
82
+ end
83
+
84
+ def test_parse_options_without_p_should_set_proc_for_password
85
+ @cli.args << "-e" << "sample"
86
+ @cli.parse_options!
87
+ assert_instance_of Proc, @cli.options[:password]
88
+ end
89
+
90
+ def test_parse_options_with_q_should_set_verbose_to_0
91
+ @cli.args << "-q"
92
+ @cli.parse_options!
93
+ assert_equal 0, @cli.options[:verbose]
94
+ end
95
+
96
+ def test_parse_options_with_r_should_set_preserve_roles_option
97
+ @cli.args << "-r"
98
+ @cli.parse_options!
99
+ assert @cli.options[:preserve_roles]
100
+ end
101
+
102
+ def test_parse_options_with_preserve_roles_should_set_preserve_roles_option
103
+ @cli.args << "--preserve-roles"
104
+ @cli.parse_options!
105
+ assert @cli.options[:preserve_roles]
106
+ end
107
+
108
+ def test_parse_options_with_S_should_set_pre_vars
109
+ @cli.args << "-S" << "foo=bar"
110
+ @cli.parse_options!
111
+ assert_equal "bar", @cli.options[:pre_vars][:foo]
112
+ end
113
+
114
+ def test_S_should_coerce_digits_to_integers
115
+ @cli.args << "-S" << "foo=1234"
116
+ @cli.parse_options!
117
+ assert_equal 1234, @cli.options[:pre_vars][:foo]
118
+ end
119
+
120
+ def test_S_should_treat_quoted_integers_as_string
121
+ @cli.args << "-S" << "foo=\"1234\""
122
+ @cli.parse_options!
123
+ assert_equal "1234", @cli.options[:pre_vars][:foo]
124
+ end
125
+
126
+ def test_S_should_treat_digits_with_dot_as_floating_point
127
+ @cli.args << "-S" << "foo=3.1415"
128
+ @cli.parse_options!
129
+ assert_equal 3.1415, @cli.options[:pre_vars][:foo]
130
+ end
131
+
132
+ def test_S_should_treat_true_as_boolean_true
133
+ @cli.args << "-S" << "foo=true"
134
+ @cli.parse_options!
135
+ assert_equal true, @cli.options[:pre_vars][:foo]
136
+ end
137
+
138
+ def test_S_should_treat_false_as_boolean_false
139
+ @cli.args << "-S" << "foo=false"
140
+ @cli.parse_options!
141
+ assert_equal false, @cli.options[:pre_vars][:foo]
142
+ end
143
+
144
+ def test_S_should_treat_nil_as_nil
145
+ @cli.args << "-S" << "foo=nil"
146
+ @cli.parse_options!
147
+ assert_equal nil, @cli.options[:pre_vars][:foo]
148
+ end
149
+
150
+ def test_parse_options_with_s_should_set_vars
151
+ @cli.args << "-s" << "foo=bar"
152
+ @cli.parse_options!
153
+ assert_equal "bar", @cli.options[:vars][:foo]
154
+ end
155
+
156
+ def test_s_should_coerce_digits_to_integers
157
+ @cli.args << "-s" << "foo=1234"
158
+ @cli.parse_options!
159
+ assert_equal 1234, @cli.options[:vars][:foo]
160
+ end
161
+
162
+ def test_s_should_treat_quoted_integers_as_string
163
+ @cli.args << "-s" << "foo=\"1234\""
164
+ @cli.parse_options!
165
+ assert_equal "1234", @cli.options[:vars][:foo]
166
+ end
167
+
168
+ def test_s_should_treat_digits_with_dot_as_floating_point
169
+ @cli.args << "-s" << "foo=3.1415"
170
+ @cli.parse_options!
171
+ assert_equal 3.1415, @cli.options[:vars][:foo]
172
+ end
173
+
174
+ def test_s_should_treat_true_as_boolean_true
175
+ @cli.args << "-s" << "foo=true"
176
+ @cli.parse_options!
177
+ assert_equal true, @cli.options[:vars][:foo]
178
+ end
179
+
180
+ def test_s_should_treat_false_as_boolean_false
181
+ @cli.args << "-s" << "foo=false"
182
+ @cli.parse_options!
183
+ assert_equal false, @cli.options[:vars][:foo]
184
+ end
185
+
186
+ def test_s_should_treat_nil_as_nil
187
+ @cli.args << "-s" << "foo=nil"
188
+ @cli.parse_options!
189
+ assert_equal nil, @cli.options[:vars][:foo]
190
+ end
191
+
192
+ def test_parse_options_with_T_should_set_tasks_option_and_set_verbose_off
193
+ @cli.args << "-T"
194
+ @cli.parse_options!
195
+ assert @cli.options[:tasks]
196
+ assert_equal 0, @cli.options[:verbose]
197
+ end
198
+
199
+ def test_parse_options_with_V_should_show_version_and_exit
200
+ @cli.args << "-V"
201
+ @cli.expects(:puts).with { |s| s.include?(Capistrano::Version.to_s) }
202
+ @cli.expects(:exit).raises(ExitException)
203
+ assert_raises(ExitException) { @cli.parse_options! }
204
+ end
205
+
206
+ def test_parse_options_with_v_should_set_verbose_to_1
207
+ @cli.args << "-v"
208
+ @cli.parse_options!
209
+ assert_equal 1, @cli.options[:verbose]
210
+ end
211
+
212
+ def test_parse_options_with_multiple_v_should_set_verbose_accordingly
213
+ @cli.args << "-vvvvvvv"
214
+ @cli.parse_options!
215
+ assert_equal 7, @cli.options[:verbose]
216
+ end
217
+
218
+ def test_parse_options_without_X_should_set_sysconf
219
+ @cli.args << "-v"
220
+ @cli.parse_options!
221
+ assert @cli.options.key?(:sysconf)
222
+ end
223
+
224
+ def test_parse_options_with_X_should_unset_sysconf
225
+ @cli.args << "-X"
226
+ @cli.parse_options!
227
+ assert !@cli.options.key?(:sysconf)
228
+ end
229
+
230
+ def test_parse_options_without_x_should_set_dotfile
231
+ @cli.args << "-v"
232
+ @cli.parse_options!
233
+ assert @cli.options.key?(:dotfile)
234
+ end
235
+
236
+ def test_parse_options_with_x_should_unset_dotfile
237
+ @cli.args << "-x"
238
+ @cli.parse_options!
239
+ assert !@cli.options.key?(:dotfile)
240
+ end
241
+
242
+ def test_parse_options_without_q_or_v_should_set_verbose_to_3
243
+ @cli.args << "-x"
244
+ @cli.parse_options!
245
+ assert_equal 3, @cli.options[:verbose]
246
+ end
247
+
248
+ def test_should_search_for_default_recipes_if_f_not_given
249
+ @cli.expects(:look_for_default_recipe_file!)
250
+ @cli.args << "-v"
251
+ @cli.parse_options!
252
+ end
253
+
254
+ def test_should_not_search_for_default_recipes_if_f_given
255
+ @cli.expects(:look_for_default_recipe_file!).never
256
+ @cli.args << "-f" << "hello"
257
+ @cli.parse_options!
258
+ end
259
+
260
+ def test_F_should_search_for_default_recipes_even_if_f_is_given
261
+ @cli.expects(:look_for_default_recipe_file!)
262
+ @cli.args << "-Ff" << "hello"
263
+ @cli.parse_options!
264
+ end
265
+
266
+ def test_should_extract_env_vars_from_command_line
267
+ assert_nil ENV["HELLO"]
268
+ assert_nil ENV["ANOTHER"]
269
+
270
+ @cli.args << "HELLO=world" << "hello" << "ANOTHER=value"
271
+ @cli.parse_options!
272
+
273
+ assert_equal "world", ENV["HELLO"]
274
+ assert_equal "value", ENV["ANOTHER"]
275
+ ensure
276
+ ENV.delete("HELLO")
277
+ ENV.delete("ANOTHER")
278
+ end
279
+
280
+ def test_remaining_args_should_be_added_to_actions_list
281
+ @cli.args << "-v" << "HELLO=world" << "-f" << "foo" << "something" << "else"
282
+ @cli.parse_options!
283
+ assert_equal %w(something else), @cli.args
284
+ ensure
285
+ ENV.delete("HELLO")
286
+ end
287
+
288
+ def test_search_for_default_recipe_file_should_look_for_Capfile
289
+ File.stubs(:file?).returns(false)
290
+ File.expects(:file?).with("Capfile").returns(true)
291
+ @cli.args << "-v"
292
+ @cli.parse_options!
293
+ assert_equal %w(Capfile), @cli.options[:recipes]
294
+ end
295
+
296
+ def test_search_for_default_recipe_file_should_look_for_capfile
297
+ File.stubs(:file?).returns(false)
298
+ File.expects(:file?).with("capfile").returns(true)
299
+ @cli.args << "-v"
300
+ @cli.parse_options!
301
+ assert_equal %w(capfile), @cli.options[:recipes]
302
+ end
303
+
304
+ def test_search_for_default_recipe_should_hike_up_the_directory_tree_until_it_finds_default_recipe
305
+ File.stubs(:file?).returns(false)
306
+ File.expects(:file?).with("capfile").times(2).returns(false,true)
307
+ Dir.expects(:pwd).times(3).returns(*%w(/bar/baz /bar/baz /bar))
308
+ Dir.expects(:chdir).with("..")
309
+ @cli.args << "-v"
310
+ @cli.parse_options!
311
+ assert_equal %w(capfile), @cli.options[:recipes]
312
+ end
313
+
314
+ def test_search_for_default_recipe_should_halt_at_root_directory
315
+ File.stubs(:file?).returns(false)
316
+ Dir.expects(:pwd).times(7).returns(*%w(/bar/baz /bar/baz /bar /bar / / /))
317
+ Dir.expects(:chdir).with("..").times(3)
318
+ Dir.expects(:chdir).with("/bar/baz")
319
+ @cli.args << "-v"
320
+ @cli.parse_options!
321
+ assert @cli.options[:recipes].empty?
322
+ end
323
+
324
+ def test_parse_should_instantiate_new_cli_and_call_parse_options
325
+ cli = mock("cli", :parse_options! => nil)
326
+ MockCLI.expects(:new).with(%w(a b c)).returns(cli)
327
+ assert_equal cli, MockCLI.parse(%w(a b c))
328
+ end
329
+ end