thor-exclude_pattern 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/CHANGELOG.md +130 -0
- data/LICENSE.md +20 -0
- data/README.md +34 -0
- data/Thorfile +30 -0
- data/bin/rake2thor +86 -0
- data/bin/thor +6 -0
- data/lib/thor.rb +458 -0
- data/lib/thor/actions.rb +318 -0
- data/lib/thor/actions/create_file.rb +105 -0
- data/lib/thor/actions/create_link.rb +60 -0
- data/lib/thor/actions/directory.rb +119 -0
- data/lib/thor/actions/empty_directory.rb +153 -0
- data/lib/thor/actions/file_manipulation.rb +314 -0
- data/lib/thor/actions/inject_into_file.rb +109 -0
- data/lib/thor/base.rb +649 -0
- data/lib/thor/command.rb +136 -0
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
- data/lib/thor/core_ext/io_binary_read.rb +12 -0
- data/lib/thor/core_ext/ordered_hash.rb +100 -0
- data/lib/thor/error.rb +32 -0
- data/lib/thor/exclude_pattern/version.rb +5 -0
- data/lib/thor/group.rb +287 -0
- data/lib/thor/invocation.rb +172 -0
- data/lib/thor/parser.rb +4 -0
- data/lib/thor/parser/argument.rb +74 -0
- data/lib/thor/parser/arguments.rb +171 -0
- data/lib/thor/parser/option.rb +121 -0
- data/lib/thor/parser/options.rb +218 -0
- data/lib/thor/rake_compat.rb +72 -0
- data/lib/thor/runner.rb +322 -0
- data/lib/thor/shell.rb +88 -0
- data/lib/thor/shell/basic.rb +393 -0
- data/lib/thor/shell/color.rb +148 -0
- data/lib/thor/shell/html.rb +127 -0
- data/lib/thor/util.rb +270 -0
- data/lib/thor/version.rb +3 -0
- data/spec/actions/create_file_spec.rb +170 -0
- data/spec/actions/create_link_spec.rb +95 -0
- data/spec/actions/directory_spec.rb +169 -0
- data/spec/actions/empty_directory_spec.rb +130 -0
- data/spec/actions/file_manipulation_spec.rb +382 -0
- data/spec/actions/inject_into_file_spec.rb +135 -0
- data/spec/actions_spec.rb +331 -0
- data/spec/base_spec.rb +294 -0
- data/spec/command_spec.rb +80 -0
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +48 -0
- data/spec/core_ext/ordered_hash_spec.rb +115 -0
- data/spec/exit_condition_spec.rb +19 -0
- data/spec/fixtures/application.rb +2 -0
- data/spec/fixtures/app{1}/README +3 -0
- data/spec/fixtures/bundle/execute.rb +6 -0
- data/spec/fixtures/bundle/main.thor +1 -0
- data/spec/fixtures/command.thor +10 -0
- data/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/spec/fixtures/doc/COMMENTER +11 -0
- data/spec/fixtures/doc/README +3 -0
- data/spec/fixtures/doc/block_helper.rb +3 -0
- data/spec/fixtures/doc/config.rb +1 -0
- data/spec/fixtures/doc/config.yaml.tt +1 -0
- data/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
- data/spec/fixtures/enum.thor +10 -0
- data/spec/fixtures/group.thor +128 -0
- data/spec/fixtures/invoke.thor +112 -0
- data/spec/fixtures/path with spaces b/data/spec/fixtures/path with → spaces +0 -0
- data/spec/fixtures/preserve/script.sh +3 -0
- data/spec/fixtures/script.thor +199 -0
- data/spec/fixtures/subcommand.thor +17 -0
- data/spec/group_spec.rb +216 -0
- data/spec/helper.rb +67 -0
- data/spec/invocation_spec.rb +100 -0
- data/spec/parser/argument_spec.rb +53 -0
- data/spec/parser/arguments_spec.rb +66 -0
- data/spec/parser/option_spec.rb +202 -0
- data/spec/parser/options_spec.rb +400 -0
- data/spec/rake_compat_spec.rb +72 -0
- data/spec/register_spec.rb +197 -0
- data/spec/runner_spec.rb +241 -0
- data/spec/sandbox/application.rb +2 -0
- data/spec/sandbox/app{1}/README +3 -0
- data/spec/sandbox/bundle/execute.rb +6 -0
- data/spec/sandbox/bundle/main.thor +1 -0
- data/spec/sandbox/command.thor +10 -0
- data/spec/sandbox/doc/%file_name%.rb.tt +1 -0
- data/spec/sandbox/doc/COMMENTER +11 -0
- data/spec/sandbox/doc/README +4 -0
- data/spec/sandbox/doc/block_helper.rb +3 -0
- data/spec/sandbox/doc/config.rb +1 -0
- data/spec/sandbox/doc/config.yaml.tt +1 -0
- data/spec/sandbox/doc/excluding/%file_name%.rb.tt +1 -0
- data/spec/sandbox/enum.thor +10 -0
- data/spec/sandbox/group.thor +128 -0
- data/spec/sandbox/invoke.thor +112 -0
- data/spec/sandbox/path with spaces b/data/spec/sandbox/path with → spaces +0 -0
- data/spec/sandbox/preserve/script.sh +3 -0
- data/spec/sandbox/script.thor +199 -0
- data/spec/sandbox/subcommand.thor +17 -0
- data/spec/shell/basic_spec.rb +311 -0
- data/spec/shell/color_spec.rb +95 -0
- data/spec/shell/html_spec.rb +32 -0
- data/spec/shell_spec.rb +47 -0
- data/spec/subcommand_spec.rb +30 -0
- data/spec/thor_spec.rb +469 -0
- data/spec/util_spec.rb +196 -0
- data/thor.gemspec +24 -0
- metadata +232 -0
@@ -0,0 +1,17 @@
|
|
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
|
@@ -0,0 +1,311 @@
|
|
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
|
+
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
22
|
+
$stdin.should_receive(:gets).and_return('Sure')
|
23
|
+
expect(shell.ask("Should I overwrite it?")).to eq("Sure")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "prints a message and returns nil if EOF is sent to stdin" do
|
27
|
+
$stdout.should_receive(:print).with(" ")
|
28
|
+
$stdin.should_receive(:gets).and_return(nil)
|
29
|
+
expect(shell.ask("")).to eq(nil)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
it "prints a message to the user with the available options and determines the correctness of the answer" do
|
34
|
+
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? ["strawberry", "chocolate", "vanilla"] ')
|
35
|
+
$stdin.should_receive(:gets).and_return('chocolate')
|
36
|
+
expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("chocolate")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "prints a message to the user with the available options and reasks the question after an incorrect repsonse" do
|
40
|
+
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? ["strawberry", "chocolate", "vanilla"] ').twice
|
41
|
+
$stdout.should_receive(:puts).with('Your response must be one of: ["strawberry", "chocolate", "vanilla"]. Please try again.')
|
42
|
+
$stdin.should_receive(:gets).and_return('moose tracks', 'chocolate')
|
43
|
+
expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("chocolate")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#yes?" do
|
48
|
+
it "asks the user and returns true if the user replies yes" do
|
49
|
+
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
50
|
+
$stdin.should_receive(:gets).and_return('y')
|
51
|
+
expect(shell.yes?("Should I overwrite it?")).to be_true
|
52
|
+
|
53
|
+
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
54
|
+
$stdin.should_receive(:gets).and_return('n')
|
55
|
+
expect(shell.yes?("Should I overwrite it?")).not_to be_true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#no?" do
|
60
|
+
it "asks the user and returns true if the user replies no" do
|
61
|
+
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
62
|
+
$stdin.should_receive(:gets).and_return('n')
|
63
|
+
expect(shell.no?("Should I overwrite it?")).to be_true
|
64
|
+
|
65
|
+
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
66
|
+
$stdin.should_receive(:gets).and_return('Yes')
|
67
|
+
expect(shell.no?("Should I overwrite it?")).to be_false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#say" do
|
72
|
+
it "prints a message to the user" do
|
73
|
+
$stdout.should_receive(:puts).with("Running...")
|
74
|
+
shell.say("Running...")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "prints a message to the user without new line if it ends with a whitespace" do
|
78
|
+
$stdout.should_receive(:print).with("Running... ")
|
79
|
+
shell.say("Running... ")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "does not use a new line with whitespace+newline embedded" do
|
83
|
+
$stdout.should_receive(:puts).with("It's \nRunning...")
|
84
|
+
shell.say("It's \nRunning...")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "prints a message to the user without new line" do
|
88
|
+
$stdout.should_receive(:print).with("Running...")
|
89
|
+
shell.say("Running...", nil, false)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#say_status" do
|
94
|
+
it "prints a message to the user with status" do
|
95
|
+
$stdout.should_receive(:puts).with(" create ~/.thor/command.thor")
|
96
|
+
shell.say_status(:create, "~/.thor/command.thor")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "always use new line" do
|
100
|
+
$stdout.should_receive(:puts).with(" create ")
|
101
|
+
shell.say_status(:create, "")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "does not print a message if base is muted" do
|
105
|
+
shell.should_receive(:mute?).and_return(true)
|
106
|
+
$stdout.should_not_receive(:puts)
|
107
|
+
|
108
|
+
shell.mute do
|
109
|
+
shell.say_status(:created, "~/.thor/command.thor")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
it "does not print a message if base is set to quiet" do
|
114
|
+
base = MyCounter.new [1,2]
|
115
|
+
base.should_receive(:options).and_return(:quiet => true)
|
116
|
+
|
117
|
+
$stdout.should_not_receive(:puts)
|
118
|
+
shell.base = base
|
119
|
+
shell.say_status(:created, "~/.thor/command.thor")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "does not print a message if log status is set to false" do
|
123
|
+
$stdout.should_not_receive(:puts)
|
124
|
+
shell.say_status(:created, "~/.thor/command.thor", false)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "uses padding to set messages left margin" do
|
128
|
+
shell.padding = 2
|
129
|
+
$stdout.should_receive(:puts).with(" create ~/.thor/command.thor")
|
130
|
+
shell.say_status(:create, "~/.thor/command.thor")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "#print_in_columns" do
|
135
|
+
before do
|
136
|
+
@array = [1234567890]
|
137
|
+
@array += ('a'..'e').to_a
|
138
|
+
end
|
139
|
+
|
140
|
+
it "prints in columns" do
|
141
|
+
content = capture(:stdout) { shell.print_in_columns(@array) }
|
142
|
+
expect(content.rstrip).to eq("1234567890 a b c d e")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "#print_table" do
|
147
|
+
before do
|
148
|
+
@table = []
|
149
|
+
@table << ["abc", "#123", "first three"]
|
150
|
+
@table << ["", "#0", "empty"]
|
151
|
+
@table << ["xyz", "#786", "last three"]
|
152
|
+
end
|
153
|
+
|
154
|
+
it "prints a table" do
|
155
|
+
content = capture(:stdout) { shell.print_table(@table) }
|
156
|
+
expect(content).to eq(<<-TABLE)
|
157
|
+
abc #123 first three
|
158
|
+
#0 empty
|
159
|
+
xyz #786 last three
|
160
|
+
TABLE
|
161
|
+
end
|
162
|
+
|
163
|
+
it "prints a table with indentation" do
|
164
|
+
content = capture(:stdout) { shell.print_table(@table, :indent => 2) }
|
165
|
+
expect(content).to eq(<<-TABLE)
|
166
|
+
abc #123 first three
|
167
|
+
#0 empty
|
168
|
+
xyz #786 last three
|
169
|
+
TABLE
|
170
|
+
end
|
171
|
+
|
172
|
+
it "uses maximum terminal width" do
|
173
|
+
@table << ["def", "#456", "Lançam foo bar"]
|
174
|
+
@table << ["ghi", "#789", "بالله عليكم"]
|
175
|
+
shell.should_receive(:terminal_width).and_return(20)
|
176
|
+
content = capture(:stdout) { shell.print_table(@table, :indent => 2, :truncate => true) }
|
177
|
+
expect(content).to eq(<<-TABLE)
|
178
|
+
abc #123 firs...
|
179
|
+
#0 empty
|
180
|
+
xyz #786 last...
|
181
|
+
def #456 Lanç...
|
182
|
+
ghi #789 بالل...
|
183
|
+
TABLE
|
184
|
+
end
|
185
|
+
|
186
|
+
it "honors the colwidth option" do
|
187
|
+
content = capture(:stdout) { shell.print_table(@table, :colwidth => 10)}
|
188
|
+
expect(content).to eq(<<-TABLE)
|
189
|
+
abc #123 first three
|
190
|
+
#0 empty
|
191
|
+
xyz #786 last three
|
192
|
+
TABLE
|
193
|
+
end
|
194
|
+
|
195
|
+
it "prints tables with implicit columns" do
|
196
|
+
2.times { @table.first.pop }
|
197
|
+
content = capture(:stdout) { shell.print_table(@table) }
|
198
|
+
expect(content).to eq(<<-TABLE)
|
199
|
+
abc
|
200
|
+
#0 empty
|
201
|
+
xyz #786 last three
|
202
|
+
TABLE
|
203
|
+
end
|
204
|
+
|
205
|
+
it "prints a table with small numbers and right-aligns them" do
|
206
|
+
table = [
|
207
|
+
["Name", "Number", "Color"],
|
208
|
+
["Erik", 1, "green"]
|
209
|
+
]
|
210
|
+
content = capture(:stdout) { shell.print_table(table) }
|
211
|
+
expect(content).to eq(<<-TABLE)
|
212
|
+
Name Number Color
|
213
|
+
Erik 1 green
|
214
|
+
TABLE
|
215
|
+
end
|
216
|
+
|
217
|
+
it "doesn't output extra spaces for right-aligned columns in the last column" do
|
218
|
+
table = [
|
219
|
+
["Name", "Number"],
|
220
|
+
["Erik", 1]
|
221
|
+
]
|
222
|
+
content = capture(:stdout) { shell.print_table(table) }
|
223
|
+
expect(content).to eq(<<-TABLE)
|
224
|
+
Name Number
|
225
|
+
Erik 1
|
226
|
+
TABLE
|
227
|
+
end
|
228
|
+
|
229
|
+
it "prints a table with big numbers" do
|
230
|
+
table = [
|
231
|
+
["Name", "Number", "Color"],
|
232
|
+
["Erik", 1234567890123, "green"]
|
233
|
+
]
|
234
|
+
content = capture(:stdout) { shell.print_table(table) }
|
235
|
+
expect(content).to eq(<<-TABLE)
|
236
|
+
Name Number Color
|
237
|
+
Erik 1234567890123 green
|
238
|
+
TABLE
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "#file_collision" do
|
243
|
+
it "shows a menu with options" do
|
244
|
+
$stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqh] ')
|
245
|
+
$stdin.should_receive(:gets).and_return('n')
|
246
|
+
shell.file_collision('foo')
|
247
|
+
end
|
248
|
+
|
249
|
+
it "returns true if the user choose default option" do
|
250
|
+
$stdout.stub!(:print)
|
251
|
+
$stdin.should_receive(:gets).and_return('')
|
252
|
+
expect(shell.file_collision('foo')).to be_true
|
253
|
+
end
|
254
|
+
|
255
|
+
it "returns false if the user choose no" do
|
256
|
+
$stdout.stub!(:print)
|
257
|
+
$stdin.should_receive(:gets).and_return('n')
|
258
|
+
expect(shell.file_collision('foo')).to be_false
|
259
|
+
end
|
260
|
+
|
261
|
+
it "returns true if the user choose yes" do
|
262
|
+
$stdout.stub!(:print)
|
263
|
+
$stdin.should_receive(:gets).and_return('y')
|
264
|
+
expect(shell.file_collision('foo')).to be_true
|
265
|
+
end
|
266
|
+
|
267
|
+
it "shows help usage if the user choose help" do
|
268
|
+
$stdout.stub!(:print)
|
269
|
+
$stdin.should_receive(:gets).and_return('h')
|
270
|
+
$stdin.should_receive(:gets).and_return('n')
|
271
|
+
help = capture(:stdout) { shell.file_collision('foo') }
|
272
|
+
expect(help).to match(/h \- help, show this help/)
|
273
|
+
end
|
274
|
+
|
275
|
+
it "quits if the user choose quit" do
|
276
|
+
$stdout.stub!(:print)
|
277
|
+
$stdout.should_receive(:puts).with('Aborting...')
|
278
|
+
$stdin.should_receive(:gets).and_return('q')
|
279
|
+
|
280
|
+
expect {
|
281
|
+
shell.file_collision('foo')
|
282
|
+
}.to raise_error(SystemExit)
|
283
|
+
end
|
284
|
+
|
285
|
+
it "always returns true if the user choose always" do
|
286
|
+
$stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqh] ')
|
287
|
+
$stdin.should_receive(:gets).and_return('a')
|
288
|
+
|
289
|
+
expect(shell.file_collision('foo')).to be_true
|
290
|
+
|
291
|
+
$stdout.should_not_receive(:print)
|
292
|
+
expect(shell.file_collision('foo')).to be_true
|
293
|
+
end
|
294
|
+
|
295
|
+
describe "when a block is given" do
|
296
|
+
it "displays diff options to the user" do
|
297
|
+
$stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqdh] ')
|
298
|
+
$stdin.should_receive(:gets).and_return('s')
|
299
|
+
shell.file_collision('foo'){ }
|
300
|
+
end
|
301
|
+
|
302
|
+
it "invokes the diff command" do
|
303
|
+
$stdout.stub!(:print)
|
304
|
+
$stdin.should_receive(:gets).and_return('d')
|
305
|
+
$stdin.should_receive(:gets).and_return('n')
|
306
|
+
shell.should_receive(:system).with(/diff -u/)
|
307
|
+
capture(:stdout) { shell.file_collision('foo'){ } }
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
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
|
+
StringIO.any_instance.stub(: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
|
+
$stdout.should_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
|
+
$stdout.stub!(:print)
|
84
|
+
$stdout.stub!(:tty?).and_return(true)
|
85
|
+
$stdin.should_receive(:gets).and_return('d')
|
86
|
+
$stdin.should_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,32 @@
|
|
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 "set 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
|
+
$stdout.should_receive(:puts).with('<span style="color: red; font-weight: bold;"> conflict</span> README')
|
28
|
+
shell.say_status :conflict, "README", :red
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|