command_kit 0.4.1 → 0.5.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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +6 -0
  3. data/README.md +3 -0
  4. data/command_kit.gemspec +7 -2
  5. data/lib/command_kit/completion/install.rb +276 -0
  6. data/lib/command_kit/env/prefix.rb +41 -0
  7. data/lib/command_kit/env/shell.rb +58 -0
  8. data/lib/command_kit/version.rb +1 -1
  9. metadata +4 -64
  10. data/spec/arguments/argument_spec.rb +0 -133
  11. data/spec/arguments/argument_value_spec.rb +0 -66
  12. data/spec/arguments_spec.rb +0 -279
  13. data/spec/bug_report_spec.rb +0 -266
  14. data/spec/colors_spec.rb +0 -771
  15. data/spec/command_kit_spec.rb +0 -8
  16. data/spec/command_name_spec.rb +0 -130
  17. data/spec/command_spec.rb +0 -123
  18. data/spec/commands/auto_load/subcommand_spec.rb +0 -82
  19. data/spec/commands/auto_load_spec.rb +0 -159
  20. data/spec/commands/auto_require_spec.rb +0 -142
  21. data/spec/commands/fixtures/test_auto_load/cli/commands/test1.rb +0 -10
  22. data/spec/commands/fixtures/test_auto_load/cli/commands/test2.rb +0 -10
  23. data/spec/commands/fixtures/test_auto_require/lib/test_auto_require/cli/commands/test1.rb +0 -10
  24. data/spec/commands/help_spec.rb +0 -66
  25. data/spec/commands/parent_command_spec.rb +0 -40
  26. data/spec/commands/subcommand_spec.rb +0 -99
  27. data/spec/commands_spec.rb +0 -865
  28. data/spec/description_spec.rb +0 -179
  29. data/spec/edit_spec.rb +0 -72
  30. data/spec/env/home_spec.rb +0 -46
  31. data/spec/env/path_spec.rb +0 -84
  32. data/spec/env_spec.rb +0 -123
  33. data/spec/examples_spec.rb +0 -211
  34. data/spec/exception_handler_spec.rb +0 -103
  35. data/spec/file_utils_spec.rb +0 -59
  36. data/spec/fixtures/template.erb +0 -5
  37. data/spec/help/man_spec.rb +0 -345
  38. data/spec/help_spec.rb +0 -94
  39. data/spec/inflector_spec.rb +0 -166
  40. data/spec/interactive_spec.rb +0 -415
  41. data/spec/main_spec.rb +0 -179
  42. data/spec/man_spec.rb +0 -46
  43. data/spec/open_app_spec.rb +0 -85
  44. data/spec/options/option_spec.rb +0 -343
  45. data/spec/options/option_value_spec.rb +0 -171
  46. data/spec/options/parser_spec.rb +0 -274
  47. data/spec/options/quiet_spec.rb +0 -51
  48. data/spec/options/verbose_spec.rb +0 -51
  49. data/spec/options/version_spec.rb +0 -146
  50. data/spec/options_spec.rb +0 -465
  51. data/spec/os/linux_spec.rb +0 -164
  52. data/spec/os_spec.rb +0 -233
  53. data/spec/package_manager_spec.rb +0 -806
  54. data/spec/pager_spec.rb +0 -217
  55. data/spec/printing/fields_spec.rb +0 -167
  56. data/spec/printing/indent_spec.rb +0 -132
  57. data/spec/printing/lists_spec.rb +0 -99
  58. data/spec/printing/tables/border_style.rb +0 -43
  59. data/spec/printing/tables/cell_builer_spec.rb +0 -135
  60. data/spec/printing/tables/row_builder_spec.rb +0 -165
  61. data/spec/printing/tables/style_spec.rb +0 -377
  62. data/spec/printing/tables/table_builder_spec.rb +0 -252
  63. data/spec/printing/tables/table_formatter_spec.rb +0 -1190
  64. data/spec/printing/tables_spec.rb +0 -1069
  65. data/spec/printing_spec.rb +0 -106
  66. data/spec/program_name_spec.rb +0 -70
  67. data/spec/spec_helper.rb +0 -3
  68. data/spec/stdio_spec.rb +0 -264
  69. data/spec/sudo_spec.rb +0 -51
  70. data/spec/terminal_spec.rb +0 -231
  71. data/spec/usage_spec.rb +0 -237
  72. data/spec/xdg_spec.rb +0 -191
data/spec/colors_spec.rb DELETED
@@ -1,771 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/colors'
3
-
4
- describe CommandKit::Colors do
5
- module TestColors
6
- class TestCommand
7
- include CommandKit::Colors
8
- end
9
- end
10
-
11
- let(:command_class) { TestColors::TestCommand }
12
- subject { command_class.new }
13
-
14
- it { expect(described_class).to include(CommandKit::Stdio) }
15
- it { expect(described_class).to include(CommandKit::Env) }
16
-
17
- describe CommandKit::Colors::ANSI do
18
- subject { described_class }
19
-
20
- describe "RESET" do
21
- it { expect(subject::RESET).to eq("\e[0m") }
22
- end
23
-
24
- describe "CLEAR" do
25
- it { expect(subject::CLEAR).to eq("\e[0m") }
26
- end
27
-
28
- describe "BOLD" do
29
- it { expect(subject::BOLD).to eq("\e[1m") }
30
- end
31
-
32
- describe "RESET_INTENSITY" do
33
- it { expect(subject::RESET_INTENSITY).to eq("\e[22m") }
34
- end
35
-
36
- describe "BLACK" do
37
- it { expect(subject::BLACK).to eq("\e[30m") }
38
- end
39
-
40
- describe "RED" do
41
- it { expect(subject::RED).to eq("\e[31m") }
42
- end
43
-
44
- describe "GREEN" do
45
- it { expect(subject::GREEN).to eq("\e[32m") }
46
- end
47
-
48
- describe "YELLOW" do
49
- it { expect(subject::YELLOW).to eq("\e[33m") }
50
- end
51
-
52
- describe "BLUE" do
53
- it { expect(subject::BLUE).to eq("\e[34m") }
54
- end
55
-
56
- describe "MAGENTA" do
57
- it { expect(subject::MAGENTA).to eq("\e[35m") }
58
- end
59
-
60
- describe "CYAN" do
61
- it { expect(subject::CYAN).to eq("\e[36m") }
62
- end
63
-
64
- describe "WHITE" do
65
- it { expect(subject::WHITE).to eq("\e[37m") }
66
- end
67
-
68
- describe "BRIGHT_BLACK" do
69
- it { expect(subject::BRIGHT_BLACK).to eq("\e[90m") }
70
- end
71
-
72
- describe "BRIGHT_RED" do
73
- it { expect(subject::BRIGHT_RED).to eq("\e[91m") }
74
- end
75
-
76
- describe "BRIGHT_GREEN" do
77
- it { expect(subject::BRIGHT_GREEN).to eq("\e[92m") }
78
- end
79
-
80
- describe "BRIGHT_YELLOW" do
81
- it { expect(subject::BRIGHT_YELLOW).to eq("\e[93m") }
82
- end
83
-
84
- describe "BRIGHT_BLUE" do
85
- it { expect(subject::BRIGHT_BLUE).to eq("\e[94m") }
86
- end
87
-
88
- describe "BRIGHT_MAGENTA" do
89
- it { expect(subject::BRIGHT_MAGENTA).to eq("\e[95m") }
90
- end
91
-
92
- describe "BRIGHT_CYAN" do
93
- it { expect(subject::BRIGHT_CYAN).to eq("\e[96m") }
94
- end
95
-
96
- describe "BRIGHT_WHITE" do
97
- it { expect(subject::BRIGHT_WHITE).to eq("\e[97m") }
98
- end
99
-
100
- describe "ON_BLACK" do
101
- it { expect(subject::ON_BLACK).to eq("\e[40m") }
102
- end
103
-
104
- describe "ON_RED" do
105
- it { expect(subject::ON_RED).to eq("\e[41m") }
106
- end
107
-
108
- describe "ON_GREEN" do
109
- it { expect(subject::ON_GREEN).to eq("\e[42m") }
110
- end
111
-
112
- describe "ON_YELLOW" do
113
- it { expect(subject::ON_YELLOW).to eq("\e[43m") }
114
- end
115
-
116
- describe "ON_BLUE" do
117
- it { expect(subject::ON_BLUE).to eq("\e[44m") }
118
- end
119
-
120
- describe "ON_MAGENTA" do
121
- it { expect(subject::ON_MAGENTA).to eq("\e[45m") }
122
- end
123
-
124
- describe "ON_CYAN" do
125
- it { expect(subject::ON_CYAN).to eq("\e[46m") }
126
- end
127
-
128
- describe "ON_WHITE" do
129
- it { expect(subject::ON_WHITE).to eq("\e[47m") }
130
- end
131
-
132
- describe "ON_BRIGHT_BLACK" do
133
- it { expect(subject::ON_BRIGHT_BLACK).to eq("\e[100m") }
134
- end
135
-
136
- describe "ON_BRIGHT_RED" do
137
- it { expect(subject::ON_BRIGHT_RED).to eq("\e[101m") }
138
- end
139
-
140
- describe "ON_BRIGHT_GREEN" do
141
- it { expect(subject::ON_BRIGHT_GREEN).to eq("\e[102m") }
142
- end
143
-
144
- describe "ON_BRIGHT_YELLOW" do
145
- it { expect(subject::ON_BRIGHT_YELLOW).to eq("\e[103m") }
146
- end
147
-
148
- describe "ON_BRIGHT_BLUE" do
149
- it { expect(subject::ON_BRIGHT_BLUE).to eq("\e[104m") }
150
- end
151
-
152
- describe "ON_BRIGHT_MAGENTA" do
153
- it { expect(subject::ON_BRIGHT_MAGENTA).to eq("\e[105m") }
154
- end
155
-
156
- describe "ON_BRIGHT_CYAN" do
157
- it { expect(subject::ON_BRIGHT_CYAN).to eq("\e[106m") }
158
- end
159
-
160
- describe "ON_BRIGHT_WHITE" do
161
- it { expect(subject::ON_BRIGHT_WHITE).to eq("\e[107m") }
162
- end
163
-
164
- describe "RESET_FG" do
165
- it { expect(subject::RESET_FG).to eq("\e[39m") }
166
- end
167
-
168
- describe "RESET_COLOR" do
169
- it { expect(subject::RESET_COLOR).to eq("\e[39m") }
170
- end
171
-
172
- let(:str) { 'foo' }
173
-
174
- describe ".reset" do
175
- it { expect(subject.reset).to eq(described_class::RESET) }
176
- end
177
-
178
- describe ".clear" do
179
- it { expect(subject.clear).to eq(described_class::CLEAR) }
180
- end
181
-
182
- describe ".bold" do
183
- context "when given a string" do
184
- it "must wrap the string with \\e[1m and \\e[22m" do
185
- expect(subject.bold(str)).to eq("\e[1m#{str}\e[22m")
186
- end
187
- end
188
-
189
- context "when given no arguments" do
190
- it { expect(subject.bold).to eq("\e[1m") }
191
- end
192
- end
193
-
194
- describe ".black" do
195
- context "when given a string" do
196
- it "must wrap the string with \\e[30m and \\e[39m" do
197
- expect(subject.black(str)).to eq("\e[30m#{str}\e[39m")
198
- end
199
- end
200
-
201
- context "when given no arguments" do
202
- it { expect(subject.black).to eq("\e[30m") }
203
- end
204
- end
205
-
206
- describe ".red" do
207
- context "when given a string" do
208
- it "must wrap the string with \\e[31m and \\e[39m" do
209
- expect(subject.red(str)).to eq("\e[31m#{str}\e[39m")
210
- end
211
- end
212
-
213
- context "when given no arguments" do
214
- it { expect(subject.red).to eq("\e[31m") }
215
- end
216
- end
217
-
218
- describe ".green" do
219
- context "when given a string" do
220
- it "must wrap the string with \\e[32m and \\e[39m" do
221
- expect(subject.green(str)).to eq("\e[32m#{str}\e[39m")
222
- end
223
- end
224
-
225
- context "when given no arguments" do
226
- it { expect(subject.green).to eq("\e[32m") }
227
- end
228
- end
229
-
230
- describe ".yellow" do
231
- context "when given a string" do
232
- it "must wrap the string with \\e[33m and \\e[39m" do
233
- expect(subject.yellow(str)).to eq("\e[33m#{str}\e[39m")
234
- end
235
- end
236
-
237
- context "when given no arguments" do
238
- it { expect(subject.yellow).to eq("\e[33m") }
239
- end
240
- end
241
-
242
- describe ".blue" do
243
- context "when given a string" do
244
- it "must wrap the string with \\e[34m and \\e[39m" do
245
- expect(subject.blue(str)).to eq("\e[34m#{str}\e[39m")
246
- end
247
- end
248
-
249
- context "when given no arguments" do
250
- it { expect(subject.blue).to eq("\e[34m") }
251
- end
252
- end
253
-
254
- describe ".magenta" do
255
- context "when given a string" do
256
- it "must wrap the string with \\e[35m and \\e[39m" do
257
- expect(subject.magenta(str)).to eq("\e[35m#{str}\e[39m")
258
- end
259
- end
260
-
261
- context "when given no arguments" do
262
- it { expect(subject.magenta).to eq("\e[35m") }
263
- end
264
- end
265
-
266
- describe ".cyan" do
267
- context "when given a string" do
268
- it "must wrap the string with \\e[36m and \\e[39m" do
269
- expect(subject.cyan(str)).to eq("\e[36m#{str}\e[39m")
270
- end
271
- end
272
-
273
- context "when given no arguments" do
274
- it { expect(subject.cyan).to eq("\e[36m") }
275
- end
276
- end
277
-
278
- describe ".white" do
279
- context "when given a string" do
280
- it "must wrap the string with \\e[37m and \\e[39m" do
281
- expect(subject.white(str)).to eq("\e[37m#{str}\e[39m")
282
- end
283
- end
284
-
285
- context "when given no arguments" do
286
- it { expect(subject.white).to eq("\e[37m") }
287
- end
288
- end
289
-
290
- describe ".bright_black" do
291
- context "when given a string" do
292
- it "must wrap the string with \\e[90m and \\e[39m" do
293
- expect(subject.bright_black(str)).to eq("\e[90m#{str}\e[39m")
294
- end
295
- end
296
-
297
- context "when given no arguments" do
298
- it { expect(subject.bright_black).to eq("\e[90m") }
299
- end
300
- end
301
-
302
- describe ".gray" do
303
- context "when given a string" do
304
- it "must wrap the string with \\e[90m and \\e[39m" do
305
- expect(subject.gray(str)).to eq("\e[90m#{str}\e[39m")
306
- end
307
- end
308
-
309
- context "when given no arguments" do
310
- it { expect(subject.gray).to eq("\e[90m") }
311
- end
312
- end
313
-
314
- describe ".bright_red" do
315
- context "when given a string" do
316
- it "must wrap the string with \\e[91m and \\e[39m" do
317
- expect(subject.bright_red(str)).to eq("\e[91m#{str}\e[39m")
318
- end
319
- end
320
-
321
- context "when given no arguments" do
322
- it { expect(subject.bright_red).to eq("\e[91m") }
323
- end
324
- end
325
-
326
- describe ".bright_green" do
327
- context "when given a string" do
328
- it "must wrap the string with \\e[92m and \\e[39m" do
329
- expect(subject.bright_green(str)).to eq("\e[92m#{str}\e[39m")
330
- end
331
- end
332
-
333
- context "when given no arguments" do
334
- it { expect(subject.bright_green).to eq("\e[92m") }
335
- end
336
- end
337
-
338
- describe ".bright_yellow" do
339
- context "when given a string" do
340
- it "must wrap the string with \\e[93m and \\e[39m" do
341
- expect(subject.bright_yellow(str)).to eq("\e[93m#{str}\e[39m")
342
- end
343
- end
344
-
345
- context "when given no arguments" do
346
- it { expect(subject.bright_yellow).to eq("\e[93m") }
347
- end
348
- end
349
-
350
- describe ".bright_blue" do
351
- context "when given a string" do
352
- it "must wrap the string with \\e[94m and \\e[39m" do
353
- expect(subject.bright_blue(str)).to eq("\e[94m#{str}\e[39m")
354
- end
355
- end
356
-
357
- context "when given no arguments" do
358
- it { expect(subject.bright_blue).to eq("\e[94m") }
359
- end
360
- end
361
-
362
- describe ".bright_magenta" do
363
- context "when given a string" do
364
- it "must wrap the string with \\e[95m and \\e[39m" do
365
- expect(subject.bright_magenta(str)).to eq("\e[95m#{str}\e[39m")
366
- end
367
- end
368
-
369
- context "when given no arguments" do
370
- it { expect(subject.bright_magenta).to eq("\e[95m") }
371
- end
372
- end
373
-
374
- describe ".bright_cyan" do
375
- context "when given a string" do
376
- it "must wrap the string with \\e[96m and \\e[39m" do
377
- expect(subject.bright_cyan(str)).to eq("\e[96m#{str}\e[39m")
378
- end
379
- end
380
-
381
- context "when given no arguments" do
382
- it { expect(subject.bright_cyan).to eq("\e[96m") }
383
- end
384
- end
385
-
386
- describe ".bright_white" do
387
- context "when given a string" do
388
- it "must wrap the string with \\e[97m and \\e[39m" do
389
- expect(subject.bright_white(str)).to eq("\e[97m#{str}\e[39m")
390
- end
391
- end
392
-
393
- context "when given no arguments" do
394
- it { expect(subject.bright_white).to eq("\e[97m") }
395
- end
396
- end
397
-
398
- describe ".on_black" do
399
- context "when given a string" do
400
- it "must wrap the string with \\e[40m and \\e[39m" do
401
- expect(subject.on_black(str)).to eq("\e[40m#{str}\e[49m")
402
- end
403
- end
404
-
405
- context "when given no arguments" do
406
- it { expect(subject.on_black).to eq("\e[40m") }
407
- end
408
- end
409
-
410
- describe ".on_red" do
411
- context "when given a string" do
412
- it "must wrap the string with \\e[41m and \\e[39m" do
413
- expect(subject.on_red(str)).to eq("\e[41m#{str}\e[49m")
414
- end
415
- end
416
-
417
- context "when given no arguments" do
418
- it { expect(subject.on_red).to eq("\e[41m") }
419
- end
420
- end
421
-
422
- describe ".on_green" do
423
- context "when given a string" do
424
- it "must wrap the string with \\e[42m and \\e[39m" do
425
- expect(subject.on_green(str)).to eq("\e[42m#{str}\e[49m")
426
- end
427
- end
428
-
429
- context "when given no arguments" do
430
- it { expect(subject.on_green).to eq("\e[42m") }
431
- end
432
- end
433
-
434
- describe ".on_yellow" do
435
- context "when given a string" do
436
- it "must wrap the string with \\e[43m and \\e[39m" do
437
- expect(subject.on_yellow(str)).to eq("\e[43m#{str}\e[49m")
438
- end
439
- end
440
-
441
- context "when given no arguments" do
442
- it { expect(subject.on_yellow).to eq("\e[43m") }
443
- end
444
- end
445
-
446
- describe ".on_blue" do
447
- context "when given a string" do
448
- it "must wrap the string with \\e[44m and \\e[39m" do
449
- expect(subject.on_blue(str)).to eq("\e[44m#{str}\e[49m")
450
- end
451
- end
452
-
453
- context "when given no arguments" do
454
- it { expect(subject.on_blue).to eq("\e[44m") }
455
- end
456
- end
457
-
458
- describe ".on_magenta" do
459
- context "when given a string" do
460
- it "must wrap the string with \\e[45m and \\e[39m" do
461
- expect(subject.on_magenta(str)).to eq("\e[45m#{str}\e[49m")
462
- end
463
- end
464
-
465
- context "when given no arguments" do
466
- it { expect(subject.on_magenta).to eq("\e[45m") }
467
- end
468
- end
469
-
470
- describe ".on_cyan" do
471
- context "when given a string" do
472
- it "must wrap the string with \\e[46m and \\e[39m" do
473
- expect(subject.on_cyan(str)).to eq("\e[46m#{str}\e[49m")
474
- end
475
- end
476
-
477
- context "when given no arguments" do
478
- it { expect(subject.on_cyan).to eq("\e[46m") }
479
- end
480
- end
481
-
482
- describe ".on_white" do
483
- context "when given a string" do
484
- it "must wrap the string with \\e[47m and \\e[39m" do
485
- expect(subject.on_white(str)).to eq("\e[47m#{str}\e[49m")
486
- end
487
- end
488
-
489
- context "when given no arguments" do
490
- it { expect(subject.on_white).to eq("\e[47m") }
491
- end
492
- end
493
-
494
- describe ".on_bright_black" do
495
- context "when given a string" do
496
- it "must wrap the string with \\e[100m and \\e[39m" do
497
- expect(subject.on_bright_black(str)).to eq("\e[100m#{str}\e[49m")
498
- end
499
- end
500
-
501
- context "when given no arguments" do
502
- it { expect(subject.on_bright_black).to eq("\e[100m") }
503
- end
504
- end
505
-
506
- describe ".on_gray" do
507
- context "when given a string" do
508
- it "must wrap the string with \\e[100m and \\e[39m" do
509
- expect(subject.on_gray(str)).to eq("\e[100m#{str}\e[49m")
510
- end
511
- end
512
-
513
- context "when given no arguments" do
514
- it { expect(subject.on_gray).to eq("\e[100m") }
515
- end
516
- end
517
-
518
- describe ".on_bright_red" do
519
- context "when given a string" do
520
- it "must wrap the string with \\e[101m and \\e[39m" do
521
- expect(subject.on_bright_red(str)).to eq("\e[101m#{str}\e[49m")
522
- end
523
- end
524
-
525
- context "when given no arguments" do
526
- it { expect(subject.on_bright_red).to eq("\e[101m") }
527
- end
528
- end
529
-
530
- describe ".on_bright_green" do
531
- context "when given a string" do
532
- it "must wrap the string with \\e[102m and \\e[39m" do
533
- expect(subject.on_bright_green(str)).to eq("\e[102m#{str}\e[49m")
534
- end
535
- end
536
-
537
- context "when given no arguments" do
538
- it { expect(subject.on_bright_green).to eq("\e[102m") }
539
- end
540
- end
541
-
542
- describe ".on_bright_yellow" do
543
- context "when given a string" do
544
- it "must wrap the string with \\e[103m and \\e[39m" do
545
- expect(subject.on_bright_yellow(str)).to eq("\e[103m#{str}\e[49m")
546
- end
547
- end
548
-
549
- context "when given no arguments" do
550
- it { expect(subject.on_bright_yellow).to eq("\e[103m") }
551
- end
552
- end
553
-
554
- describe ".on_bright_blue" do
555
- context "when given a string" do
556
- it "must wrap the string with \\e[104m and \\e[39m" do
557
- expect(subject.on_bright_blue(str)).to eq("\e[104m#{str}\e[49m")
558
- end
559
- end
560
-
561
- context "when given no arguments" do
562
- it { expect(subject.on_bright_blue).to eq("\e[104m") }
563
- end
564
- end
565
-
566
- describe ".on_bright_magenta" do
567
- context "when given a string" do
568
- it "must wrap the string with \\e[105m and \\e[39m" do
569
- expect(subject.on_bright_magenta(str)).to eq("\e[105m#{str}\e[49m")
570
- end
571
- end
572
-
573
- context "when given no arguments" do
574
- it { expect(subject.on_bright_magenta).to eq("\e[105m") }
575
- end
576
- end
577
-
578
- describe ".on_bright_cyan" do
579
- context "when given a string" do
580
- it "must wrap the string with \\e[106m and \\e[39m" do
581
- expect(subject.on_bright_cyan(str)).to eq("\e[106m#{str}\e[49m")
582
- end
583
- end
584
-
585
- context "when given no arguments" do
586
- it { expect(subject.on_bright_cyan).to eq("\e[106m") }
587
- end
588
- end
589
-
590
- describe ".on_bright_white" do
591
- context "when given a string" do
592
- it "must wrap the string with \\e[107m and \\e[39m" do
593
- expect(subject.on_bright_white(str)).to eq("\e[107m#{str}\e[49m")
594
- end
595
- end
596
-
597
- context "when given no arguments" do
598
- it { expect(subject.on_bright_white).to eq("\e[107m") }
599
- end
600
- end
601
- end
602
-
603
- describe CommandKit::Colors::PlainText do
604
- subject { described_class }
605
-
606
- let(:str) { 'foo' }
607
-
608
- [
609
- :RESET, :CLEAR,
610
- :BOLD, :RESET_INTENSITY,
611
- :BLACK, :RED, :GREEN, :YELLOW, :BLUE, :MAGENTA, :CYAN, :WHITE,
612
- :BRIGHT_BLACK, :BRIGHT_RED, :BRIGHT_GREEN, :BRIGHT_YELLOW, :BRIGHT_BLUE, :BRIGHT_MAGENTA, :BRIGHT_CYAN, :BRIGHT_WHITE,
613
- :RESET_FG, :RESET_COLOR,
614
- :ON_BLACK, :ON_RED, :ON_GREEN, :ON_YELLOW, :ON_BLUE, :ON_MAGENTA, :ON_CYAN, :ON_WHITE,
615
- :ON_BRIGHT_BLACK, :ON_BRIGHT_RED, :ON_BRIGHT_GREEN, :ON_BRIGHT_YELLOW, :ON_BRIGHT_BLUE, :ON_BRIGHT_MAGENTA, :ON_BRIGHT_CYAN, :ON_BRIGHT_WHITE,
616
- :RESET_BG
617
- ].each do |const_name|
618
- describe const_name.to_s do
619
- it { expect(subject.const_get(const_name)).to eq('') }
620
- end
621
- end
622
-
623
- describe ".reset" do
624
- it { expect(subject.reset).to eq('') }
625
- end
626
-
627
- describe ".clear" do
628
- it { expect(subject.clear).to eq('') }
629
- end
630
-
631
- [
632
- :bold,
633
- :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white,
634
- :bright_black, :gray, :bright_red, :bright_green, :bright_yellow, :bright_blue, :bright_magenta, :bright_cyan, :bright_white,
635
- :on_black, :on_red, :on_green, :on_yellow, :on_blue, :on_magenta, :on_cyan, :on_white,
636
- :on_bright_black, :on_gray, :on_bright_red, :on_bright_green, :on_bright_yellow, :on_bright_blue, :on_bright_magenta, :on_bright_cyan, :on_bright_white
637
- ].each do |method_name|
638
- describe ".#{method_name}" do
639
- context "when given a string" do
640
- it "must return that string" do
641
- expect(subject.send(method_name,str)).to eq(str)
642
- end
643
- end
644
-
645
- context "when given no arguments" do
646
- it { expect(subject.send(method_name)).to eq('') }
647
- end
648
- end
649
- end
650
- end
651
-
652
- describe "#ansi?" do
653
- context "when TERM='dumb'" do
654
- subject { command_class.new(env: {'TERM' => 'dumb'}) }
655
-
656
- it { expect(subject.ansi?).to be(false) }
657
- end
658
-
659
- context "when NO_COLOR is set" do
660
- subject { command_class.new(env: {'NO_COLOR' => 'true'}) }
661
-
662
- it { expect(subject.ansi?).to be(false) }
663
- end
664
-
665
- context "when stdout is a TTY" do
666
- let(:stdout) { StringIO.new }
667
- subject { command_class.new(stdout: stdout) }
668
-
669
- before { allow(stdout).to receive(:tty?).and_return(true) }
670
-
671
- it { expect(subject.ansi?).to be(true) }
672
- end
673
-
674
- context "when stdout is not a TTY" do
675
- let(:stdout) { StringIO.new }
676
- subject { command_class.new(stdout: stdout) }
677
-
678
- it { expect(subject.ansi?).to be(false) }
679
- end
680
-
681
- context "when given an alternate stream" do
682
- context "and the alternate stream is a TTY" do
683
- let(:stream) { StringIO.new }
684
-
685
- before { allow(stream).to receive(:tty?).and_return(true) }
686
-
687
- it { expect(subject.ansi?(stream)).to be(true) }
688
- end
689
-
690
- context "but the alternate stream is not a TTY" do
691
- let(:stream) { StringIO.new }
692
-
693
- it { expect(subject.ansi?(stream)).to be(false) }
694
- end
695
- end
696
- end
697
-
698
- describe "#colors" do
699
- context "when stdout supports ANSI" do
700
- let(:stdout) { StringIO.new }
701
- subject { command_class.new(stdout: stdout) }
702
-
703
- before { allow(stdout).to receive(:tty?).and_return(true) }
704
-
705
- it do
706
- expect(subject.colors).to be(described_class::ANSI)
707
- end
708
-
709
- context "when a block is given" do
710
- it do
711
- expect { |b|
712
- subject.colors(&b)
713
- }.to yield_with_args(described_class::ANSI)
714
- end
715
- end
716
- end
717
-
718
- context "when stdout does not support ANSI" do
719
- let(:stdout) { StringIO.new }
720
- subject { command_class.new(stdout: stdout) }
721
-
722
- it do
723
- expect(subject.colors).to be(described_class::PlainText)
724
- end
725
-
726
- context "when a block is given" do
727
- it do
728
- expect { |b|
729
- subject.colors(&b)
730
- }.to yield_with_args(described_class::PlainText)
731
- end
732
- end
733
- end
734
-
735
- context "when given an alternate stream" do
736
- context "and the alternate stream supports ANSI" do
737
- let(:stream) { StringIO.new }
738
-
739
- before { allow(stream).to receive(:tty?).and_return(true) }
740
-
741
- it do
742
- expect(subject.colors(stream)).to be(described_class::ANSI)
743
- end
744
-
745
- context "when a block is given" do
746
- it do
747
- expect { |b|
748
- subject.colors(stream,&b)
749
- }.to yield_with_args(described_class::ANSI)
750
- end
751
- end
752
- end
753
-
754
- context "but the alternate stream does not support ANSI" do
755
- let(:stream) { StringIO.new }
756
-
757
- it do
758
- expect(subject.colors(stream)).to be(described_class::PlainText)
759
- end
760
-
761
- context "when a block is given" do
762
- it do
763
- expect { |b|
764
- subject.colors(stream,&b)
765
- }.to yield_with_args(described_class::PlainText)
766
- end
767
- end
768
- end
769
- end
770
- end
771
- end