thor 0.19.1 → 0.19.2

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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/CONTRIBUTING.md +15 -0
  4. data/README.md +7 -1
  5. data/lib/thor.rb +31 -23
  6. data/lib/thor/actions.rb +21 -22
  7. data/lib/thor/actions/create_file.rb +1 -1
  8. data/lib/thor/actions/create_link.rb +1 -1
  9. data/lib/thor/actions/directory.rb +2 -2
  10. data/lib/thor/actions/empty_directory.rb +8 -8
  11. data/lib/thor/actions/file_manipulation.rb +23 -12
  12. data/lib/thor/actions/inject_into_file.rb +10 -14
  13. data/lib/thor/base.rb +33 -33
  14. data/lib/thor/command.rb +9 -9
  15. data/lib/thor/core_ext/hash_with_indifferent_access.rb +9 -1
  16. data/lib/thor/core_ext/io_binary_read.rb +7 -5
  17. data/lib/thor/core_ext/ordered_hash.rb +94 -63
  18. data/lib/thor/error.rb +3 -3
  19. data/lib/thor/group.rb +12 -12
  20. data/lib/thor/invocation.rb +4 -5
  21. data/lib/thor/parser/argument.rb +4 -7
  22. data/lib/thor/parser/arguments.rb +16 -16
  23. data/lib/thor/parser/option.rb +39 -19
  24. data/lib/thor/parser/options.rb +7 -5
  25. data/lib/thor/runner.rb +25 -25
  26. data/lib/thor/shell.rb +1 -1
  27. data/lib/thor/shell/basic.rb +41 -26
  28. data/lib/thor/shell/color.rb +1 -1
  29. data/lib/thor/shell/html.rb +4 -4
  30. data/lib/thor/util.rb +8 -7
  31. data/lib/thor/version.rb +1 -1
  32. data/thor.gemspec +6 -9
  33. metadata +6 -148
  34. data/Thorfile +0 -29
  35. data/spec/actions/create_file_spec.rb +0 -168
  36. data/spec/actions/create_link_spec.rb +0 -96
  37. data/spec/actions/directory_spec.rb +0 -169
  38. data/spec/actions/empty_directory_spec.rb +0 -129
  39. data/spec/actions/file_manipulation_spec.rb +0 -392
  40. data/spec/actions/inject_into_file_spec.rb +0 -135
  41. data/spec/actions_spec.rb +0 -331
  42. data/spec/base_spec.rb +0 -298
  43. data/spec/command_spec.rb +0 -79
  44. data/spec/core_ext/hash_with_indifferent_access_spec.rb +0 -48
  45. data/spec/core_ext/ordered_hash_spec.rb +0 -115
  46. data/spec/exit_condition_spec.rb +0 -19
  47. data/spec/fixtures/application.rb +0 -2
  48. data/spec/fixtures/app{1}/README +0 -3
  49. data/spec/fixtures/bundle/execute.rb +0 -6
  50. data/spec/fixtures/bundle/main.thor +0 -1
  51. data/spec/fixtures/command.thor +0 -10
  52. data/spec/fixtures/doc/%file_name%.rb.tt +0 -1
  53. data/spec/fixtures/doc/COMMENTER +0 -11
  54. data/spec/fixtures/doc/README +0 -3
  55. data/spec/fixtures/doc/block_helper.rb +0 -3
  56. data/spec/fixtures/doc/config.rb +0 -1
  57. data/spec/fixtures/doc/config.yaml.tt +0 -1
  58. data/spec/fixtures/doc/excluding/%file_name%.rb.tt +0 -1
  59. data/spec/fixtures/enum.thor +0 -10
  60. data/spec/fixtures/group.thor +0 -128
  61. data/spec/fixtures/invoke.thor +0 -131
  62. data/spec/fixtures/path with spaces b/data/spec/fixtures/path with → spaces +0 -0
  63. data/spec/fixtures/preserve/script.sh +0 -3
  64. data/spec/fixtures/script.thor +0 -220
  65. data/spec/fixtures/subcommand.thor +0 -17
  66. data/spec/group_spec.rb +0 -222
  67. data/spec/helper.rb +0 -80
  68. data/spec/invocation_spec.rb +0 -120
  69. data/spec/line_editor/basic_spec.rb +0 -28
  70. data/spec/line_editor/readline_spec.rb +0 -69
  71. data/spec/line_editor_spec.rb +0 -43
  72. data/spec/parser/argument_spec.rb +0 -53
  73. data/spec/parser/arguments_spec.rb +0 -66
  74. data/spec/parser/option_spec.rb +0 -210
  75. data/spec/parser/options_spec.rb +0 -414
  76. data/spec/quality_spec.rb +0 -75
  77. data/spec/rake_compat_spec.rb +0 -72
  78. data/spec/register_spec.rb +0 -227
  79. data/spec/runner_spec.rb +0 -246
  80. data/spec/sandbox/application.rb +0 -2
  81. data/spec/sandbox/app{1}/README +0 -3
  82. data/spec/sandbox/bundle/execute.rb +0 -6
  83. data/spec/sandbox/bundle/main.thor +0 -1
  84. data/spec/sandbox/command.thor +0 -10
  85. data/spec/sandbox/doc/%file_name%.rb.tt +0 -1
  86. data/spec/sandbox/doc/COMMENTER +0 -11
  87. data/spec/sandbox/doc/README +0 -3
  88. data/spec/sandbox/doc/block_helper.rb +0 -3
  89. data/spec/sandbox/doc/config.rb +0 -1
  90. data/spec/sandbox/doc/config.yaml.tt +0 -1
  91. data/spec/sandbox/doc/excluding/%file_name%.rb.tt +0 -1
  92. data/spec/sandbox/enum.thor +0 -10
  93. data/spec/sandbox/group.thor +0 -128
  94. data/spec/sandbox/invoke.thor +0 -131
  95. data/spec/sandbox/path with spaces b/data/spec/sandbox/path with → spaces +0 -0
  96. data/spec/sandbox/preserve/script.sh +0 -3
  97. data/spec/sandbox/script.thor +0 -220
  98. data/spec/sandbox/subcommand.thor +0 -17
  99. data/spec/shell/basic_spec.rb +0 -337
  100. data/spec/shell/color_spec.rb +0 -119
  101. data/spec/shell/html_spec.rb +0 -31
  102. data/spec/shell_spec.rb +0 -47
  103. data/spec/subcommand_spec.rb +0 -48
  104. data/spec/thor_spec.rb +0 -505
  105. data/spec/util_spec.rb +0 -196
@@ -1,17 +0,0 @@
1
- module TestSubcommands
2
-
3
- class Subcommand < Thor
4
- desc "print_opt", "My method"
5
- def print_opt
6
- print options["opt"]
7
- end
8
- end
9
-
10
- class Parent < Thor
11
- class_option "opt"
12
-
13
- desc "sub", "My subcommand"
14
- subcommand "sub", Subcommand
15
- end
16
-
17
- end
@@ -1,337 +0,0 @@
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(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {}).and_return("Sure")
22
- expect(shell.ask("Should I overwrite it?")).to eq("Sure")
23
- end
24
-
25
- it "prints a message to the user prefixed with the current padding" do
26
- expect(Thor::LineEditor).to receive(:readline).with(" Enter your name: ", {}).and_return("George")
27
- shell.padding = 2
28
- shell.ask("Enter your name:")
29
- end
30
-
31
- it "prints a message and returns nil if EOF is given as input" do
32
- expect(Thor::LineEditor).to receive(:readline).with(" ", {}).and_return(nil)
33
- expect(shell.ask("")).to eq(nil)
34
- end
35
-
36
- it "prints a message to the user and does not echo stdin if the echo option is set to false" do
37
- expect($stdout).to receive(:print).with('What\'s your password? ')
38
- expect($stdin).to receive(:noecho).and_return("mysecretpass")
39
- expect(shell.ask("What's your password?", :echo => false)).to eq("mysecretpass")
40
- end
41
-
42
- it "prints a message to the user with the available options and determines the correctness of the answer" do
43
- flavors = %w[strawberry chocolate vanilla]
44
- expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', :limited_to => flavors).and_return("chocolate")
45
- expect(shell.ask('What\'s your favorite Neopolitan flavor?', :limited_to => flavors)).to eq("chocolate")
46
- end
47
-
48
- it "prints a message to the user with the available options and reasks the question after an incorrect repsonse" do
49
- flavors = %w[strawberry chocolate vanilla]
50
- expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n")
51
- expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', :limited_to => flavors).and_return("moose tracks", "chocolate")
52
- expect(shell.ask('What\'s your favorite Neopolitan flavor?', :limited_to => flavors)).to eq("chocolate")
53
- end
54
-
55
- it "prints a message to the user containing a default and sets the default if only enter is pressed" do
56
- expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? (vanilla) ', :default => "vanilla").and_return("")
57
- expect(shell.ask('What\'s your favorite Neopolitan flavor?', :default => "vanilla")).to eq("vanilla")
58
- end
59
-
60
- 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
61
- flavors = %w[strawberry chocolate vanilla]
62
- expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n")
63
- expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] (vanilla) ', :default => "vanilla", :limited_to => flavors).and_return("moose tracks", "")
64
- expect(shell.ask("What's your favorite Neopolitan flavor?", :default => "vanilla", :limited_to => flavors)).to eq("vanilla")
65
- end
66
- end
67
-
68
- describe "#yes?" do
69
- it "asks the user and returns true if the user replies yes" do
70
- expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", :add_to_history => false).and_return("y")
71
- expect(shell.yes?("Should I overwrite it?")).to be_true
72
- end
73
-
74
- it "asks the user and returns false if the user replies no" do
75
- expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", :add_to_history => false).and_return("n")
76
- expect(shell.yes?("Should I overwrite it?")).not_to be_true
77
- end
78
-
79
- it "asks the user and returns false if the user replies with an answer other than yes or no" do
80
- expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", :add_to_history => false).and_return("foobar")
81
- expect(shell.yes?("Should I overwrite it?")).to be_false
82
- end
83
- end
84
-
85
- describe "#no?" do
86
- it "asks the user and returns true if the user replies no" do
87
- expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", :add_to_history => false).and_return("n")
88
- expect(shell.no?("Should I overwrite it?")).to be_true
89
- end
90
-
91
- it "asks the user and returns false if the user replies yes" do
92
- expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", :add_to_history => false).and_return("Yes")
93
- expect(shell.no?("Should I overwrite it?")).to be_false
94
- end
95
-
96
- it "asks the user and returns false if the user replies with an answer other than yes or no" do
97
- expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", :add_to_history => false).and_return("foobar")
98
- expect(shell.no?("Should I overwrite it?")).to be_false
99
- end
100
- end
101
-
102
- describe "#say" do
103
- it "prints a message to the user" do
104
- expect($stdout).to receive(:print).with("Running...\n")
105
- shell.say("Running...")
106
- end
107
-
108
- it "prints a message to the user without new line if it ends with a whitespace" do
109
- expect($stdout).to receive(:print).with("Running... ")
110
- shell.say("Running... ")
111
- end
112
-
113
- it "does not use a new line with whitespace+newline embedded" do
114
- expect($stdout).to receive(:print).with("It's \nRunning...\n")
115
- shell.say("It's \nRunning...")
116
- end
117
-
118
- it "prints a message to the user without new line" do
119
- expect($stdout).to receive(:print).with("Running...")
120
- shell.say("Running...", nil, false)
121
- end
122
-
123
- it "coerces everything to a string before printing" do
124
- expect($stdout).to receive(:print).with("this_is_not_a_string\n")
125
- shell.say(:this_is_not_a_string, nil, true)
126
- end
127
- end
128
-
129
- describe "#say_status" do
130
- it "prints a message to the user with status" do
131
- expect($stdout).to receive(:print).with(" create ~/.thor/command.thor\n")
132
- shell.say_status(:create, "~/.thor/command.thor")
133
- end
134
-
135
- it "always uses new line" do
136
- expect($stdout).to receive(:print).with(" create \n")
137
- shell.say_status(:create, "")
138
- end
139
-
140
- it "does not print a message if base is muted" do
141
- expect(shell).to receive(:mute?).and_return(true)
142
- expect($stdout).not_to receive(:print)
143
-
144
- shell.mute do
145
- shell.say_status(:created, "~/.thor/command.thor")
146
- end
147
- end
148
-
149
- it "does not print a message if base is set to quiet" do
150
- base = MyCounter.new [1, 2]
151
- expect(base).to receive(:options).and_return(:quiet => true)
152
-
153
- expect($stdout).not_to receive(:print)
154
- shell.base = base
155
- shell.say_status(:created, "~/.thor/command.thor")
156
- end
157
-
158
- it "does not print a message if log status is set to false" do
159
- expect($stdout).not_to receive(:print)
160
- shell.say_status(:created, "~/.thor/command.thor", false)
161
- end
162
-
163
- it "uses padding to set message's left margin" do
164
- shell.padding = 2
165
- expect($stdout).to receive(:print).with(" create ~/.thor/command.thor\n")
166
- shell.say_status(:create, "~/.thor/command.thor")
167
- end
168
- end
169
-
170
- describe "#print_in_columns" do
171
- before do
172
- @array = [1_234_567_890]
173
- @array += ("a".."e").to_a
174
- end
175
-
176
- it "prints in columns" do
177
- content = capture(:stdout) { shell.print_in_columns(@array) }
178
- expect(content.rstrip).to eq("1234567890 a b c d e")
179
- end
180
- end
181
-
182
- describe "#print_table" do
183
- before do
184
- @table = []
185
- @table << ["abc", "#123", "first three"]
186
- @table << ["", "#0", "empty"]
187
- @table << ["xyz", "#786", "last three"]
188
- end
189
-
190
- it "prints a table" do
191
- content = capture(:stdout) { shell.print_table(@table) }
192
- expect(content).to eq(<<-TABLE)
193
- abc #123 first three
194
- #0 empty
195
- xyz #786 last three
196
- TABLE
197
- end
198
-
199
- it "prints a table with indentation" do
200
- content = capture(:stdout) { shell.print_table(@table, :indent => 2) }
201
- expect(content).to eq(<<-TABLE)
202
- abc #123 first three
203
- #0 empty
204
- xyz #786 last three
205
- TABLE
206
- end
207
-
208
- it "uses maximum terminal width" do
209
- @table << ["def", "#456", "Lançam foo bar"]
210
- @table << ["ghi", "#789", "بالله عليكم"]
211
- expect(shell).to receive(:terminal_width).and_return(20)
212
- content = capture(:stdout) { shell.print_table(@table, :indent => 2, :truncate => true) }
213
- expect(content).to eq(<<-TABLE)
214
- abc #123 firs...
215
- #0 empty
216
- xyz #786 last...
217
- def #456 Lanç...
218
- ghi #789 بالل...
219
- TABLE
220
- end
221
-
222
- it "honors the colwidth option" do
223
- content = capture(:stdout) { shell.print_table(@table, :colwidth => 10) }
224
- expect(content).to eq(<<-TABLE)
225
- abc #123 first three
226
- #0 empty
227
- xyz #786 last three
228
- TABLE
229
- end
230
-
231
- it "prints tables with implicit columns" do
232
- 2.times { @table.first.pop }
233
- content = capture(:stdout) { shell.print_table(@table) }
234
- expect(content).to eq(<<-TABLE)
235
- abc
236
- #0 empty
237
- xyz #786 last three
238
- TABLE
239
- end
240
-
241
- it "prints a table with small numbers and right-aligns them" do
242
- table = [
243
- ["Name", "Number", "Color"], # rubocop: disable WordArray
244
- ["Erik", 1, "green"]
245
- ]
246
- content = capture(:stdout) { shell.print_table(table) }
247
- expect(content).to eq(<<-TABLE)
248
- Name Number Color
249
- Erik 1 green
250
- TABLE
251
- end
252
-
253
- it "doesn't output extra spaces for right-aligned columns in the last column" do
254
- table = [
255
- ["Name", "Number"], # rubocop: disable WordArray
256
- ["Erik", 1]
257
- ]
258
- content = capture(:stdout) { shell.print_table(table) }
259
- expect(content).to eq(<<-TABLE)
260
- Name Number
261
- Erik 1
262
- TABLE
263
- end
264
-
265
- it "prints a table with big numbers" do
266
- table = [
267
- ["Name", "Number", "Color"], # rubocop: disable WordArray
268
- ["Erik", 1_234_567_890_123, "green"]
269
- ]
270
- content = capture(:stdout) { shell.print_table(table) }
271
- expect(content).to eq(<<-TABLE)
272
- Name Number Color
273
- Erik 1234567890123 green
274
- TABLE
275
- end
276
- end
277
-
278
- describe "#file_collision" do
279
- it "shows a menu with options" do
280
- expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqh] ', :add_to_history => false).and_return("n")
281
- shell.file_collision("foo")
282
- end
283
-
284
- it "returns true if the user chooses default option" do
285
- expect(Thor::LineEditor).to receive(:readline).and_return("")
286
- expect(shell.file_collision("foo")).to be_true
287
- end
288
-
289
- it "returns false if the user chooses no" do
290
- expect(Thor::LineEditor).to receive(:readline).and_return("n")
291
- expect(shell.file_collision("foo")).to be_false
292
- end
293
-
294
- it "returns true if the user chooses yes" do
295
- expect(Thor::LineEditor).to receive(:readline).and_return("y")
296
- expect(shell.file_collision("foo")).to be_true
297
- end
298
-
299
- it "shows help usage if the user chooses help" do
300
- expect(Thor::LineEditor).to receive(:readline).and_return("h", "n")
301
- help = capture(:stdout) { shell.file_collision("foo") }
302
- expect(help).to match(/h \- help, show this help/)
303
- end
304
-
305
- it "quits if the user chooses quit" do
306
- expect($stdout).to receive(:print).with("Aborting...\n")
307
- expect(Thor::LineEditor).to receive(:readline).and_return("q")
308
-
309
- expect do
310
- shell.file_collision("foo")
311
- end.to raise_error(SystemExit)
312
- end
313
-
314
- it "always returns true if the user chooses always" do
315
- expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqh] ', :add_to_history => false).and_return("a")
316
-
317
- expect(shell.file_collision("foo")).to be true
318
-
319
- expect($stdout).not_to receive(:print)
320
- expect(shell.file_collision("foo")).to be true
321
- end
322
-
323
- describe "when a block is given" do
324
- it "displays diff options to the user" do
325
- expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqdh] ', :add_to_history => false).and_return("s")
326
- shell.file_collision("foo") {}
327
- end
328
-
329
- it "invokes the diff command" do
330
- expect(Thor::LineEditor).to receive(:readline).and_return("d")
331
- expect(Thor::LineEditor).to receive(:readline).and_return("n")
332
- expect(shell).to receive(:system).with(/diff -u/)
333
- capture(:stdout) { shell.file_collision("foo") {} }
334
- end
335
- end
336
- end
337
- end
@@ -1,119 +0,0 @@
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($stdout).to receive(:tty?).and_return(true)
10
- allow_any_instance_of(StringIO).to receive(:tty?).and_return(true)
11
- end
12
-
13
- describe "#ask" do
14
- it "sets the color if specified and tty?" do
15
- expect(Thor::LineEditor).to receive(:readline).with("\e[32mIs this green? \e[0m", anything).and_return("yes")
16
- shell.ask "Is this green?", :green
17
-
18
- expect(Thor::LineEditor).to receive(:readline).with("\e[32mIs this green? [Yes, No, Maybe] \e[0m", anything).and_return("Yes")
19
- shell.ask "Is this green?", :green, :limited_to => %w[Yes No Maybe]
20
- end
21
- end
22
-
23
- describe "#say" do
24
- it "set the color if specified and tty?" do
25
- out = capture(:stdout) do
26
- shell.say "Wow! Now we have colors!", :green
27
- end
28
-
29
- expect(out.chomp).to eq("\e[32mWow! Now we have colors!\e[0m")
30
- end
31
-
32
- it "does not set the color if output is not a tty" do
33
- out = capture(:stdout) do
34
- expect($stdout).to receive(:tty?).and_return(false)
35
- shell.say "Wow! Now we have colors!", :green
36
- end
37
-
38
- expect(out.chomp).to eq("Wow! Now we have colors!")
39
- end
40
-
41
- it "does not use a new line even with colors" do
42
- out = capture(:stdout) do
43
- shell.say "Wow! Now we have colors! ", :green
44
- end
45
-
46
- expect(out.chomp).to eq("\e[32mWow! Now we have colors! \e[0m")
47
- end
48
-
49
- it "handles an Array of colors" do
50
- out = capture(:stdout) do
51
- shell.say "Wow! Now we have colors *and* background colors", [:green, :on_red, :bold]
52
- end
53
-
54
- expect(out.chomp).to eq("\e[32m\e[41m\e[1mWow! Now we have colors *and* background colors\e[0m")
55
- end
56
- end
57
-
58
- describe "#say_status" do
59
- it "uses color to say status" do
60
- out = capture(:stdout) do
61
- shell.say_status :conflict, "README", :red
62
- end
63
-
64
- expect(out.chomp).to eq("\e[1m\e[31m conflict\e[0m README")
65
- end
66
- end
67
-
68
- describe "#set_color" do
69
- it "colors a string with a foreground color" do
70
- red = shell.set_color "hi!", :red
71
- expect(red).to eq("\e[31mhi!\e[0m")
72
- end
73
-
74
- it "colors a string with a background color" do
75
- on_red = shell.set_color "hi!", :white, :on_red
76
- expect(on_red).to eq("\e[37m\e[41mhi!\e[0m")
77
- end
78
-
79
- it "colors a string with a bold color" do
80
- bold = shell.set_color "hi!", :white, true
81
- expect(bold).to eq("\e[1m\e[37mhi!\e[0m")
82
-
83
- bold = shell.set_color "hi!", :white, :bold
84
- expect(bold).to eq("\e[37m\e[1mhi!\e[0m")
85
-
86
- bold = shell.set_color "hi!", :white, :on_red, :bold
87
- expect(bold).to eq("\e[37m\e[41m\e[1mhi!\e[0m")
88
- end
89
-
90
- it "does nothing when there are no colors" do
91
- colorless = shell.set_color "hi!", nil
92
- expect(colorless).to eq("hi!")
93
-
94
- colorless = shell.set_color "hi!"
95
- expect(colorless).to eq("hi!")
96
- end
97
-
98
- it "does nothing when the terminal does not support color" do
99
- allow($stdout).to receive(:tty?).and_return(false)
100
- colorless = shell.set_color "hi!", :white
101
- expect(colorless).to eq("hi!")
102
- end
103
- end
104
-
105
- describe "#file_collision" do
106
- describe "when a block is given" do
107
- it "invokes the diff command" do
108
- allow($stdout).to receive(:print)
109
- allow($stdout).to receive(:tty?).and_return(true)
110
- expect(Thor::LineEditor).to receive(:readline).and_return("d", "n")
111
-
112
- output = capture(:stdout) { shell.file_collision("spec/fixtures/doc/README") { "README\nEND\n" } }
113
- expect(output).to match(/\e\[31m\- __start__\e\[0m/)
114
- expect(output).to match(/^ README/)
115
- expect(output).to match(/\e\[32m\+ END\e\[0m/)
116
- end
117
- end
118
- end
119
- end