acquia_toolbelt 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data/.gitignore +7 -0
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +7 -0
  4. data/CONTRIBUTING.md +11 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +55 -0
  7. data/Guardfile +5 -0
  8. data/LICENSE +19 -0
  9. data/README.md +149 -0
  10. data/Rakefile +1 -0
  11. data/acquia_toolbelt.gemspec +34 -0
  12. data/bin/acquia +9 -0
  13. data/lib/acquia_toolbelt/cli/api.rb +164 -0
  14. data/lib/acquia_toolbelt/cli/auth.rb +31 -0
  15. data/lib/acquia_toolbelt/cli/database.rb +237 -0
  16. data/lib/acquia_toolbelt/cli/deploy.rb +36 -0
  17. data/lib/acquia_toolbelt/cli/domain.rb +177 -0
  18. data/lib/acquia_toolbelt/cli/environment.rb +71 -0
  19. data/lib/acquia_toolbelt/cli/file.rb +31 -0
  20. data/lib/acquia_toolbelt/cli/server.rb +67 -0
  21. data/lib/acquia_toolbelt/cli/site.rb +28 -0
  22. data/lib/acquia_toolbelt/cli/ssh.rb +78 -0
  23. data/lib/acquia_toolbelt/cli/svn.rb +73 -0
  24. data/lib/acquia_toolbelt/cli/task.rb +74 -0
  25. data/lib/acquia_toolbelt/cli/ui.rb +44 -0
  26. data/lib/acquia_toolbelt/cli.rb +103 -0
  27. data/lib/acquia_toolbelt/error.rb +4 -0
  28. data/lib/acquia_toolbelt/thor.rb +95 -0
  29. data/lib/acquia_toolbelt/version.rb +3 -0
  30. data/lib/acquia_toolbelt.rb +4 -0
  31. data/lib/vendor/thor/CHANGELOG.md +139 -0
  32. data/lib/vendor/thor/Gemfile +20 -0
  33. data/lib/vendor/thor/LICENSE.md +20 -0
  34. data/lib/vendor/thor/README.md +35 -0
  35. data/lib/vendor/thor/lib/thor/actions/create_file.rb +105 -0
  36. data/lib/vendor/thor/lib/thor/actions/create_link.rb +60 -0
  37. data/lib/vendor/thor/lib/thor/actions/directory.rb +119 -0
  38. data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +137 -0
  39. data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +317 -0
  40. data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +109 -0
  41. data/lib/vendor/thor/lib/thor/actions.rb +318 -0
  42. data/lib/vendor/thor/lib/thor/base.rb +654 -0
  43. data/lib/vendor/thor/lib/thor/command.rb +136 -0
  44. data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
  45. data/lib/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
  46. data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
  47. data/lib/vendor/thor/lib/thor/error.rb +32 -0
  48. data/lib/vendor/thor/lib/thor/group.rb +282 -0
  49. data/lib/vendor/thor/lib/thor/invocation.rb +172 -0
  50. data/lib/vendor/thor/lib/thor/parser/argument.rb +74 -0
  51. data/lib/vendor/thor/lib/thor/parser/arguments.rb +171 -0
  52. data/lib/vendor/thor/lib/thor/parser/option.rb +121 -0
  53. data/lib/vendor/thor/lib/thor/parser/options.rb +218 -0
  54. data/lib/vendor/thor/lib/thor/parser.rb +4 -0
  55. data/lib/vendor/thor/lib/thor/rake_compat.rb +72 -0
  56. data/lib/vendor/thor/lib/thor/runner.rb +322 -0
  57. data/lib/vendor/thor/lib/thor/shell/basic.rb +422 -0
  58. data/lib/vendor/thor/lib/thor/shell/color.rb +148 -0
  59. data/lib/vendor/thor/lib/thor/shell/html.rb +127 -0
  60. data/lib/vendor/thor/lib/thor/shell.rb +88 -0
  61. data/lib/vendor/thor/lib/thor/util.rb +270 -0
  62. data/lib/vendor/thor/lib/thor/version.rb +3 -0
  63. data/lib/vendor/thor/lib/thor.rb +474 -0
  64. data/lib/vendor/thor/spec/actions/create_file_spec.rb +170 -0
  65. data/lib/vendor/thor/spec/actions/create_link_spec.rb +95 -0
  66. data/lib/vendor/thor/spec/actions/directory_spec.rb +169 -0
  67. data/lib/vendor/thor/spec/actions/empty_directory_spec.rb +129 -0
  68. data/lib/vendor/thor/spec/actions/file_manipulation_spec.rb +382 -0
  69. data/lib/vendor/thor/spec/actions/inject_into_file_spec.rb +135 -0
  70. data/lib/vendor/thor/spec/actions_spec.rb +331 -0
  71. data/lib/vendor/thor/spec/base_spec.rb +291 -0
  72. data/lib/vendor/thor/spec/command_spec.rb +80 -0
  73. data/lib/vendor/thor/spec/core_ext/hash_with_indifferent_access_spec.rb +48 -0
  74. data/lib/vendor/thor/spec/core_ext/ordered_hash_spec.rb +115 -0
  75. data/lib/vendor/thor/spec/exit_condition_spec.rb +19 -0
  76. data/lib/vendor/thor/spec/fixtures/application.rb +2 -0
  77. data/lib/vendor/thor/spec/fixtures/app{1}/README +3 -0
  78. data/lib/vendor/thor/spec/fixtures/bundle/execute.rb +6 -0
  79. data/lib/vendor/thor/spec/fixtures/bundle/main.thor +1 -0
  80. data/lib/vendor/thor/spec/fixtures/command.thor +10 -0
  81. data/lib/vendor/thor/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  82. data/lib/vendor/thor/spec/fixtures/doc/COMMENTER +11 -0
  83. data/lib/vendor/thor/spec/fixtures/doc/README +3 -0
  84. data/lib/vendor/thor/spec/fixtures/doc/block_helper.rb +3 -0
  85. data/lib/vendor/thor/spec/fixtures/doc/components/.empty_directory +0 -0
  86. data/lib/vendor/thor/spec/fixtures/doc/config.rb +1 -0
  87. data/lib/vendor/thor/spec/fixtures/doc/config.yaml.tt +1 -0
  88. data/lib/vendor/thor/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
  89. data/lib/vendor/thor/spec/fixtures/enum.thor +10 -0
  90. data/lib/vendor/thor/spec/fixtures/group.thor +128 -0
  91. data/lib/vendor/thor/spec/fixtures/invoke.thor +118 -0
  92. data/lib/vendor/thor/spec/fixtures/path with spaces +0 -0
  93. data/lib/vendor/thor/spec/fixtures/preserve/script.sh +3 -0
  94. data/lib/vendor/thor/spec/fixtures/script.thor +220 -0
  95. data/lib/vendor/thor/spec/fixtures/subcommand.thor +17 -0
  96. data/lib/vendor/thor/spec/group_spec.rb +222 -0
  97. data/lib/vendor/thor/spec/helper.rb +67 -0
  98. data/lib/vendor/thor/spec/invocation_spec.rb +108 -0
  99. data/lib/vendor/thor/spec/parser/argument_spec.rb +53 -0
  100. data/lib/vendor/thor/spec/parser/arguments_spec.rb +66 -0
  101. data/lib/vendor/thor/spec/parser/option_spec.rb +202 -0
  102. data/lib/vendor/thor/spec/parser/options_spec.rb +400 -0
  103. data/lib/vendor/thor/spec/rake_compat_spec.rb +72 -0
  104. data/lib/vendor/thor/spec/register_spec.rb +197 -0
  105. data/lib/vendor/thor/spec/runner_spec.rb +241 -0
  106. data/lib/vendor/thor/spec/shell/basic_spec.rb +330 -0
  107. data/lib/vendor/thor/spec/shell/color_spec.rb +95 -0
  108. data/lib/vendor/thor/spec/shell/html_spec.rb +31 -0
  109. data/lib/vendor/thor/spec/shell_spec.rb +47 -0
  110. data/lib/vendor/thor/spec/subcommand_spec.rb +30 -0
  111. data/lib/vendor/thor/spec/thor_spec.rb +499 -0
  112. data/lib/vendor/thor/spec/util_spec.rb +196 -0
  113. data/lib/vendor/thor/thor.gemspec +24 -0
  114. data/script/release +50 -0
  115. data/script/setup_build +6 -0
  116. data/script/test +23 -0
  117. data/spec/auth_spec.rb +15 -0
  118. data/spec/cassettes/databases/all_databases.json +1 -0
  119. data/spec/cassettes/databases/copy_database_from_dev_to_stage.json +1 -0
  120. data/spec/cassettes/databases/create_a_database_backup.json +1 -0
  121. data/spec/cassettes/databases/create_a_new_database.json +1 -0
  122. data/spec/cassettes/databases/delete_a_database.json +1 -0
  123. data/spec/cassettes/databases/get_all_existing_databases.json +1 -0
  124. data/spec/cassettes/databases/list_all_database_backups.json +1 -0
  125. data/spec/cassettes/databases/view_database_instance_details.json +1 -0
  126. data/spec/cassettes/deploy/release_vcs_branch.json +1 -0
  127. data/spec/cassettes/domains/create_new_domain.json +1 -0
  128. data/spec/cassettes/domains/delete_a_domain.json +1 -0
  129. data/spec/cassettes/domains/get_all_existing_domains.json +1 -0
  130. data/spec/cassettes/domains/list_all_dev_domains.json +1 -0
  131. data/spec/cassettes/domains/move_from_dev_to_stage.json +1 -0
  132. data/spec/cassettes/domains/purge_varnish_cache.json +1 -0
  133. data/spec/cassettes/environments/all_environments.json +1 -0
  134. data/spec/cassettes/environments/disable_live_development.json +1 -0
  135. data/spec/cassettes/environments/enable_live_development.json +1 -0
  136. data/spec/cassettes/files/copy_from_dev_to_stage.json +1 -0
  137. data/spec/cassettes/servers/all_dev_servers.json +1 -0
  138. data/spec/cassettes/servers/all_prod_servers.json +1 -0
  139. data/spec/cassettes/sites/all_sites.json +1 -0
  140. data/spec/cassettes/ssh/all_sshkeys.json +1 -0
  141. data/spec/cassettes/svn/all_svnusers.json +1 -0
  142. data/spec/cassettes/tasks/all_tasks.json +1 -0
  143. data/spec/databases_spec.rb +78 -0
  144. data/spec/deploy_spec.rb +12 -0
  145. data/spec/domains_spec.rb +59 -0
  146. data/spec/environments_spec.rb +35 -0
  147. data/spec/files_spec.rb +11 -0
  148. data/spec/helper.rb +104 -0
  149. data/spec/servers_spec.rb +59 -0
  150. data/spec/sites_spec.rb +19 -0
  151. data/spec/ssh_spec.rb +19 -0
  152. data/spec/svn_spec.rb +11 -0
  153. data/spec/tasks_spec.rb +11 -0
  154. metadata +158 -4
@@ -0,0 +1,330 @@
1
+ # coding: UTF-8
2
+ require 'helper'
3
+
4
+ describe Thor::Shell::Basic do
5
+ def shell
6
+ @shell ||= Thor::Shell::Basic.new
7
+ end
8
+
9
+ describe "#padding" do
10
+ it "cannot be set to below zero" do
11
+ shell.padding = 10
12
+ expect(shell.padding).to eq(10)
13
+
14
+ shell.padding = -1
15
+ expect(shell.padding).to eq(0)
16
+ end
17
+ end
18
+
19
+ describe "#ask" do
20
+ it "prints a message to the user and gets the response" do
21
+ expect($stdout).to receive(:print).with("Should I overwrite it? ")
22
+ expect($stdin).to receive(:gets).and_return('Sure')
23
+ expect($stdin).to_not receive(:noecho)
24
+ expect(shell.ask("Should I overwrite it?")).to eq("Sure")
25
+ end
26
+
27
+ it "prints a message and returns nil if EOF is sent to stdin" do
28
+ expect($stdout).to receive(:print).with(" ")
29
+ expect($stdin).to receive(:gets).and_return(nil)
30
+ expect(shell.ask("")).to eq(nil)
31
+ end
32
+
33
+ it "prints a message to the user and does not echo stdin if the echo option is set to false" do
34
+ expect($stdout).to receive(:print).with('What\'s your password? ')
35
+ expect($stdin).to receive(:noecho).and_return('mysecretpass')
36
+ expect(shell.ask("What's your password?", :echo => false)).to eq("mysecretpass")
37
+ end
38
+
39
+ it "prints a message to the user with the available options and determines the correctness of the answer" do
40
+ expect($stdout).to receive(:print).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ')
41
+ expect($stdin).to receive(:gets).and_return('chocolate')
42
+ expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("chocolate")
43
+ end
44
+
45
+ it "prints a message to the user with the available options and reasks the question after an incorrect repsonse" do
46
+ expect($stdout).to receive(:print).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ').twice
47
+ expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n")
48
+ expect($stdin).to receive(:gets).and_return('moose tracks', 'chocolate')
49
+ expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("chocolate")
50
+ end
51
+
52
+ it "prints a message to the user containing a default and sets the default if only enter is pressed" do
53
+ expect($stdout).to receive(:print).with('What\'s your favorite Neopolitan flavor? (vanilla) ')
54
+ expect($stdin).to receive(:gets).and_return('')
55
+ expect(shell.ask("What's your favorite Neopolitan flavor?", :default => "vanilla")).to eq("vanilla")
56
+ end
57
+
58
+ it "prints a message to the user with the available options and reasks the question after an incorrect repsonse and then returns the default" do
59
+ expect($stdout).to receive(:print).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] (vanilla) ').twice
60
+ expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n")
61
+ expect($stdin).to receive(:gets).and_return('moose tracks', '')
62
+ expect(shell.ask("What's your favorite Neopolitan flavor?", :default => "vanilla", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("vanilla")
63
+ end
64
+ end
65
+
66
+ describe "#yes?" do
67
+ it "asks the user and returns true if the user replies yes" do
68
+ expect($stdout).to receive(:print).with("Should I overwrite it? ")
69
+ expect($stdin).to receive(:gets).and_return('y')
70
+ expect(shell.yes?("Should I overwrite it?")).to be_true
71
+
72
+ expect($stdout).to receive(:print).with("Should I overwrite it? ")
73
+ expect($stdin).to receive(:gets).and_return('n')
74
+ expect(shell.yes?("Should I overwrite it?")).not_to be_true
75
+ end
76
+ end
77
+
78
+ describe "#no?" do
79
+ it "asks the user and returns true if the user replies no" do
80
+ expect($stdout).to receive(:print).with("Should I overwrite it? ")
81
+ expect($stdin).to receive(:gets).and_return('n')
82
+ expect(shell.no?("Should I overwrite it?")).to be_true
83
+
84
+ expect($stdout).to receive(:print).with("Should I overwrite it? ")
85
+ expect($stdin).to receive(:gets).and_return('Yes')
86
+ expect(shell.no?("Should I overwrite it?")).to be_false
87
+ end
88
+ end
89
+
90
+ describe "#say" do
91
+ it "prints a message to the user" do
92
+ expect($stdout).to receive(:print).with("Running...\n")
93
+ shell.say("Running...")
94
+ end
95
+
96
+ it "prints a message to the user without new line if it ends with a whitespace" do
97
+ expect($stdout).to receive(:print).with("Running... ")
98
+ shell.say("Running... ")
99
+ end
100
+
101
+ it "does not use a new line with whitespace+newline embedded" do
102
+ expect($stdout).to receive(:print).with("It's \nRunning...\n")
103
+ shell.say("It's \nRunning...")
104
+ end
105
+
106
+ it "prints a message to the user without new line" do
107
+ expect($stdout).to receive(:print).with("Running...")
108
+ shell.say("Running...", nil, false)
109
+ end
110
+ end
111
+
112
+ describe "#say_status" do
113
+ it "prints a message to the user with status" do
114
+ expect($stdout).to receive(:print).with(" create ~/.thor/command.thor\n")
115
+ shell.say_status(:create, "~/.thor/command.thor")
116
+ end
117
+
118
+ it "always uses new line" do
119
+ expect($stdout).to receive(:print).with(" create \n")
120
+ shell.say_status(:create, "")
121
+ end
122
+
123
+ it "does not print a message if base is muted" do
124
+ expect(shell).to receive(:mute?).and_return(true)
125
+ expect($stdout).not_to receive(:print)
126
+
127
+ shell.mute do
128
+ shell.say_status(:created, "~/.thor/command.thor")
129
+ end
130
+ end
131
+
132
+ it "does not print a message if base is set to quiet" do
133
+ base = MyCounter.new [1,2]
134
+ expect(base).to receive(:options).and_return(:quiet => true)
135
+
136
+ expect($stdout).not_to receive(:print)
137
+ shell.base = base
138
+ shell.say_status(:created, "~/.thor/command.thor")
139
+ end
140
+
141
+ it "does not print a message if log status is set to false" do
142
+ expect($stdout).not_to receive(:print)
143
+ shell.say_status(:created, "~/.thor/command.thor", false)
144
+ end
145
+
146
+ it "uses padding to set message's left margin" do
147
+ shell.padding = 2
148
+ expect($stdout).to receive(:print).with(" create ~/.thor/command.thor\n")
149
+ shell.say_status(:create, "~/.thor/command.thor")
150
+ end
151
+ end
152
+
153
+ describe "#print_in_columns" do
154
+ before do
155
+ @array = [1234567890]
156
+ @array += ('a'..'e').to_a
157
+ end
158
+
159
+ it "prints in columns" do
160
+ content = capture(:stdout) { shell.print_in_columns(@array) }
161
+ expect(content.rstrip).to eq("1234567890 a b c d e")
162
+ end
163
+ end
164
+
165
+ describe "#print_table" do
166
+ before do
167
+ @table = []
168
+ @table << ["abc", "#123", "first three"]
169
+ @table << ["", "#0", "empty"]
170
+ @table << ["xyz", "#786", "last three"]
171
+ end
172
+
173
+ it "prints a table" do
174
+ content = capture(:stdout) { shell.print_table(@table) }
175
+ expect(content).to eq(<<-TABLE)
176
+ abc #123 first three
177
+ #0 empty
178
+ xyz #786 last three
179
+ TABLE
180
+ end
181
+
182
+ it "prints a table with indentation" do
183
+ content = capture(:stdout) { shell.print_table(@table, :indent => 2) }
184
+ expect(content).to eq(<<-TABLE)
185
+ abc #123 first three
186
+ #0 empty
187
+ xyz #786 last three
188
+ TABLE
189
+ end
190
+
191
+ it "uses maximum terminal width" do
192
+ @table << ["def", "#456", "Lançam foo bar"]
193
+ @table << ["ghi", "#789", "بالله عليكم"]
194
+ expect(shell).to receive(:terminal_width).and_return(20)
195
+ content = capture(:stdout) { shell.print_table(@table, :indent => 2, :truncate => true) }
196
+ expect(content).to eq(<<-TABLE)
197
+ abc #123 firs...
198
+ #0 empty
199
+ xyz #786 last...
200
+ def #456 Lanç...
201
+ ghi #789 بالل...
202
+ TABLE
203
+ end
204
+
205
+ it "honors the colwidth option" do
206
+ content = capture(:stdout) { shell.print_table(@table, :colwidth => 10)}
207
+ expect(content).to eq(<<-TABLE)
208
+ abc #123 first three
209
+ #0 empty
210
+ xyz #786 last three
211
+ TABLE
212
+ end
213
+
214
+ it "prints tables with implicit columns" do
215
+ 2.times { @table.first.pop }
216
+ content = capture(:stdout) { shell.print_table(@table) }
217
+ expect(content).to eq(<<-TABLE)
218
+ abc
219
+ #0 empty
220
+ xyz #786 last three
221
+ TABLE
222
+ end
223
+
224
+ it "prints a table with small numbers and right-aligns them" do
225
+ table = [
226
+ ["Name", "Number", "Color"],
227
+ ["Erik", 1, "green"]
228
+ ]
229
+ content = capture(:stdout) { shell.print_table(table) }
230
+ expect(content).to eq(<<-TABLE)
231
+ Name Number Color
232
+ Erik 1 green
233
+ TABLE
234
+ end
235
+
236
+ it "doesn't output extra spaces for right-aligned columns in the last column" do
237
+ table = [
238
+ ["Name", "Number"],
239
+ ["Erik", 1]
240
+ ]
241
+ content = capture(:stdout) { shell.print_table(table) }
242
+ expect(content).to eq(<<-TABLE)
243
+ Name Number
244
+ Erik 1
245
+ TABLE
246
+ end
247
+
248
+ it "prints a table with big numbers" do
249
+ table = [
250
+ ["Name", "Number", "Color"],
251
+ ["Erik", 1234567890123, "green"]
252
+ ]
253
+ content = capture(:stdout) { shell.print_table(table) }
254
+ expect(content).to eq(<<-TABLE)
255
+ Name Number Color
256
+ Erik 1234567890123 green
257
+ TABLE
258
+ end
259
+ end
260
+
261
+ describe "#file_collision" do
262
+ it "shows a menu with options" do
263
+ expect($stdout).to receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqh] ')
264
+ expect($stdin).to receive(:gets).and_return('n')
265
+ shell.file_collision('foo')
266
+ end
267
+
268
+ it "returns true if the user chooses default option" do
269
+ allow($stdout).to receive(:print)
270
+ expect($stdin).to receive(:gets).and_return('')
271
+ expect(shell.file_collision('foo')).to be_true
272
+ end
273
+
274
+ it "returns false if the user chooses no" do
275
+ allow($stdout).to receive(:print)
276
+ expect($stdin).to receive(:gets).and_return('n')
277
+ expect(shell.file_collision('foo')).to be_false
278
+ end
279
+
280
+ it "returns true if the user chooses yes" do
281
+ allow($stdout).to receive(:print)
282
+ expect($stdin).to receive(:gets).and_return('y')
283
+ expect(shell.file_collision('foo')).to be_true
284
+ end
285
+
286
+ it "shows help usage if the user chooses help" do
287
+ allow($stdout).to receive(:print)
288
+ expect($stdin).to receive(:gets).and_return('h')
289
+ expect($stdin).to receive(:gets).and_return('n')
290
+ help = capture(:stdout) { shell.file_collision('foo') }
291
+ expect(help).to match(/h \- help, show this help/)
292
+ end
293
+
294
+ it "quits if the user chooses quit" do
295
+ allow($stdout).to receive(:print)
296
+ expect($stdout).to receive(:print).with("Aborting...\n")
297
+ expect($stdin).to receive(:gets).and_return('q')
298
+
299
+ expect {
300
+ shell.file_collision('foo')
301
+ }.to raise_error(SystemExit)
302
+ end
303
+
304
+ it "always returns true if the user chooses always" do
305
+ expect($stdout).to receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqh] ')
306
+ expect($stdin).to receive(:gets).and_return('a')
307
+
308
+ expect(shell.file_collision('foo')).to be_true
309
+
310
+ expect($stdout).not_to receive(:print)
311
+ expect(shell.file_collision('foo')).to be_true
312
+ end
313
+
314
+ describe "when a block is given" do
315
+ it "displays diff options to the user" do
316
+ expect($stdout).to receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqdh] ')
317
+ expect($stdin).to receive(:gets).and_return('s')
318
+ shell.file_collision('foo'){ }
319
+ end
320
+
321
+ it "invokes the diff command" do
322
+ allow($stdout).to receive(:print)
323
+ expect($stdin).to receive(:gets).and_return('d')
324
+ expect($stdin).to receive(:gets).and_return('n')
325
+ expect(shell).to receive(:system).with(/diff -u/)
326
+ capture(:stdout) { shell.file_collision('foo'){ } }
327
+ end
328
+ end
329
+ end
330
+ end
@@ -0,0 +1,95 @@
1
+ require 'helper'
2
+
3
+ describe Thor::Shell::Color do
4
+ def shell
5
+ @shell ||= Thor::Shell::Color.new
6
+ end
7
+
8
+ before do
9
+ allow_any_instance_of(StringIO).to receive(:tty?).and_return(true)
10
+ end
11
+
12
+ describe "#say" do
13
+ it "set the color if specified and tty?" do
14
+ out = capture(:stdout) do
15
+ shell.say "Wow! Now we have colors!", :green
16
+ end
17
+
18
+ expect(out.chomp).to eq("\e[32mWow! Now we have colors!\e[0m")
19
+ end
20
+
21
+ it "does not set the color if output is not a tty" do
22
+ out = capture(:stdout) do
23
+ expect($stdout).to receive(:tty?).and_return(false)
24
+ shell.say "Wow! Now we have colors!", :green
25
+ end
26
+
27
+ expect(out.chomp).to eq("Wow! Now we have colors!")
28
+ end
29
+
30
+ it "does not use a new line even with colors" do
31
+ out = capture(:stdout) do
32
+ shell.say "Wow! Now we have colors! ", :green
33
+ end
34
+
35
+ expect(out.chomp).to eq("\e[32mWow! Now we have colors! \e[0m")
36
+ end
37
+
38
+ it "handles an Array of colors" do
39
+ out = capture(:stdout) do
40
+ shell.say "Wow! Now we have colors *and* background colors", [:green, :on_red, :bold]
41
+ end
42
+
43
+ expect(out.chomp).to eq("\e[32m\e[41m\e[1mWow! Now we have colors *and* background colors\e[0m")
44
+ end
45
+ end
46
+
47
+ describe "#say_status" do
48
+ it "uses color to say status" do
49
+ out = capture(:stdout) do
50
+ shell.say_status :conflict, "README", :red
51
+ end
52
+
53
+ expect(out.chomp).to eq("\e[1m\e[31m conflict\e[0m README")
54
+ end
55
+ end
56
+
57
+ describe "#set_color" do
58
+ it "colors a string with a foreground color" do
59
+ red = shell.set_color "hi!", :red
60
+ expect(red).to eq("\e[31mhi!\e[0m")
61
+ end
62
+
63
+ it "colors a string with a background color" do
64
+ on_red = shell.set_color "hi!", :white, :on_red
65
+ expect(on_red).to eq("\e[37m\e[41mhi!\e[0m")
66
+ end
67
+
68
+ it "colors a string with a bold color" do
69
+ bold = shell.set_color "hi!", :white, true
70
+ expect(bold).to eq("\e[1m\e[37mhi!\e[0m")
71
+
72
+ bold = shell.set_color "hi!", :white, :bold
73
+ expect(bold).to eq("\e[37m\e[1mhi!\e[0m")
74
+
75
+ bold = shell.set_color "hi!", :white, :on_red, :bold
76
+ expect(bold).to eq("\e[37m\e[41m\e[1mhi!\e[0m")
77
+ end
78
+ end
79
+
80
+ describe "#file_collision" do
81
+ describe "when a block is given" do
82
+ it "invokes the diff command" do
83
+ allow($stdout).to receive(:print)
84
+ allow($stdout).to receive(:tty?).and_return(true)
85
+ expect($stdin).to receive(:gets).and_return('d')
86
+ expect($stdin).to receive(:gets).and_return('n')
87
+
88
+ output = capture(:stdout) { shell.file_collision('spec/fixtures/doc/README'){ "README\nEND\n" } }
89
+ expect(output).to match(/\e\[31m\- __start__\e\[0m/)
90
+ expect(output).to match(/^ README/)
91
+ expect(output).to match(/\e\[32m\+ END\e\[0m/)
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ describe Thor::Shell::HTML do
4
+ def shell
5
+ @shell ||= Thor::Shell::HTML.new
6
+ end
7
+
8
+ describe "#say" do
9
+ it "sets the color if specified" do
10
+ out = capture(:stdout) { shell.say "Wow! Now we have colors!", :green }
11
+ expect(out.chomp).to eq('<span style="color: green;">Wow! Now we have colors!</span>')
12
+ end
13
+
14
+ it "sets bold if specified" do
15
+ out = capture(:stdout) { shell.say "Wow! Now we have colors *and* bold!", [:green, :bold] }
16
+ expect(out.chomp).to eq('<span style="color: green; font-weight: bold;">Wow! Now we have colors *and* bold!</span>')
17
+ end
18
+
19
+ it "does not use a new line even with colors" do
20
+ out = capture(:stdout) { shell.say "Wow! Now we have colors! ", :green }
21
+ expect(out.chomp).to eq('<span style="color: green;">Wow! Now we have colors! </span>')
22
+ end
23
+ end
24
+
25
+ describe "#say_status" do
26
+ it "uses color to say status" do
27
+ expect($stdout).to receive(:print).with("<span style=\"color: red; font-weight: bold;\"> conflict</span> README\n")
28
+ shell.say_status :conflict, "README", :red
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,47 @@
1
+ require 'helper'
2
+
3
+ describe Thor::Shell do
4
+ def shell
5
+ @shell ||= Thor::Base.shell.new
6
+ end
7
+
8
+ describe "#initialize" do
9
+ it "sets shell value" do
10
+ base = MyCounter.new [1, 2], { }, :shell => shell
11
+ expect(base.shell).to eq(shell)
12
+ end
13
+
14
+ it "sets the base value on the shell if an accessor is available" do
15
+ base = MyCounter.new [1, 2], { }, :shell => shell
16
+ expect(shell.base).to eq(base)
17
+ end
18
+ end
19
+
20
+ describe "#shell" do
21
+ it "returns the shell in use" do
22
+ expect(MyCounter.new([1,2]).shell).to be_kind_of(Thor::Base.shell)
23
+ end
24
+
25
+ it "uses $THOR_SHELL" do
26
+ class Thor::Shell::TestShell < Thor::Shell::Basic; end
27
+
28
+ expect(Thor::Base.shell).to eq(shell.class)
29
+ ENV['THOR_SHELL'] = 'TestShell'
30
+ Thor::Base.shell = nil
31
+ expect(Thor::Base.shell).to eq(Thor::Shell::TestShell)
32
+ ENV['THOR_SHELL'] = ''
33
+ Thor::Base.shell = shell.class
34
+ expect(Thor::Base.shell).to eq(shell.class)
35
+ end
36
+ end
37
+
38
+ describe "with_padding" do
39
+ it "uses padding for inside block outputs" do
40
+ base = MyCounter.new([1,2])
41
+ base.with_padding do
42
+ expect(capture(:stdout) { base.say_status :padding, "cool" }.strip).to eq("padding cool")
43
+ end
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+
3
+ describe Thor do
4
+
5
+ describe "#subcommand" do
6
+
7
+ it "maps a given subcommand to another Thor subclass" do
8
+ barn_help = capture(:stdout) { Scripts::MyDefaults.start(%w[barn]) }
9
+ expect(barn_help).to include("barn help [COMMAND] # Describe subcommands or one specific subcommand")
10
+ end
11
+
12
+ it "passes commands to subcommand classes" do
13
+ expect(capture(:stdout) { Scripts::MyDefaults.start(%w[barn open]) }.strip).to eq("Open sesame!")
14
+ end
15
+
16
+ it "passes arguments to subcommand classes" do
17
+ expect(capture(:stdout) { Scripts::MyDefaults.start(%w[barn open shotgun]) }.strip).to eq("That's going to leave a mark.")
18
+ end
19
+
20
+ it "ignores unknown options (the subcommand class will handle them)" do
21
+ expect(capture(:stdout) { Scripts::MyDefaults.start(%w[barn paint blue --coats 4])}.strip).to eq("4 coats of blue paint")
22
+ end
23
+
24
+ it "passes parsed options to subcommands" do
25
+ output = capture(:stdout) { TestSubcommands::Parent.start(%w[sub print_opt --opt output]) }
26
+ expect(output).to eq("output")
27
+ end
28
+ end
29
+
30
+ end