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.
- checksums.yaml +4 -4
- data/ChangeLog.md +6 -0
- data/README.md +3 -0
- data/command_kit.gemspec +7 -2
- data/lib/command_kit/completion/install.rb +276 -0
- data/lib/command_kit/env/prefix.rb +41 -0
- data/lib/command_kit/env/shell.rb +58 -0
- data/lib/command_kit/version.rb +1 -1
- metadata +4 -64
- data/spec/arguments/argument_spec.rb +0 -133
- data/spec/arguments/argument_value_spec.rb +0 -66
- data/spec/arguments_spec.rb +0 -279
- data/spec/bug_report_spec.rb +0 -266
- data/spec/colors_spec.rb +0 -771
- data/spec/command_kit_spec.rb +0 -8
- data/spec/command_name_spec.rb +0 -130
- data/spec/command_spec.rb +0 -123
- data/spec/commands/auto_load/subcommand_spec.rb +0 -82
- data/spec/commands/auto_load_spec.rb +0 -159
- data/spec/commands/auto_require_spec.rb +0 -142
- data/spec/commands/fixtures/test_auto_load/cli/commands/test1.rb +0 -10
- data/spec/commands/fixtures/test_auto_load/cli/commands/test2.rb +0 -10
- data/spec/commands/fixtures/test_auto_require/lib/test_auto_require/cli/commands/test1.rb +0 -10
- data/spec/commands/help_spec.rb +0 -66
- data/spec/commands/parent_command_spec.rb +0 -40
- data/spec/commands/subcommand_spec.rb +0 -99
- data/spec/commands_spec.rb +0 -865
- data/spec/description_spec.rb +0 -179
- data/spec/edit_spec.rb +0 -72
- data/spec/env/home_spec.rb +0 -46
- data/spec/env/path_spec.rb +0 -84
- data/spec/env_spec.rb +0 -123
- data/spec/examples_spec.rb +0 -211
- data/spec/exception_handler_spec.rb +0 -103
- data/spec/file_utils_spec.rb +0 -59
- data/spec/fixtures/template.erb +0 -5
- data/spec/help/man_spec.rb +0 -345
- data/spec/help_spec.rb +0 -94
- data/spec/inflector_spec.rb +0 -166
- data/spec/interactive_spec.rb +0 -415
- data/spec/main_spec.rb +0 -179
- data/spec/man_spec.rb +0 -46
- data/spec/open_app_spec.rb +0 -85
- data/spec/options/option_spec.rb +0 -343
- data/spec/options/option_value_spec.rb +0 -171
- data/spec/options/parser_spec.rb +0 -274
- data/spec/options/quiet_spec.rb +0 -51
- data/spec/options/verbose_spec.rb +0 -51
- data/spec/options/version_spec.rb +0 -146
- data/spec/options_spec.rb +0 -465
- data/spec/os/linux_spec.rb +0 -164
- data/spec/os_spec.rb +0 -233
- data/spec/package_manager_spec.rb +0 -806
- data/spec/pager_spec.rb +0 -217
- data/spec/printing/fields_spec.rb +0 -167
- data/spec/printing/indent_spec.rb +0 -132
- data/spec/printing/lists_spec.rb +0 -99
- data/spec/printing/tables/border_style.rb +0 -43
- data/spec/printing/tables/cell_builer_spec.rb +0 -135
- data/spec/printing/tables/row_builder_spec.rb +0 -165
- data/spec/printing/tables/style_spec.rb +0 -377
- data/spec/printing/tables/table_builder_spec.rb +0 -252
- data/spec/printing/tables/table_formatter_spec.rb +0 -1190
- data/spec/printing/tables_spec.rb +0 -1069
- data/spec/printing_spec.rb +0 -106
- data/spec/program_name_spec.rb +0 -70
- data/spec/spec_helper.rb +0 -3
- data/spec/stdio_spec.rb +0 -264
- data/spec/sudo_spec.rb +0 -51
- data/spec/terminal_spec.rb +0 -231
- data/spec/usage_spec.rb +0 -237
- data/spec/xdg_spec.rb +0 -191
data/spec/options_spec.rb
DELETED
@@ -1,465 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'command_kit/options'
|
3
|
-
|
4
|
-
describe CommandKit::Options do
|
5
|
-
module TestOptions
|
6
|
-
class ImplicitCmd
|
7
|
-
include CommandKit::Options
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:command_class) { TestOptions::ImplicitCmd }
|
12
|
-
subject { command_class.new }
|
13
|
-
|
14
|
-
describe ".options" do
|
15
|
-
subject { TestOptions::ImplicitCmd }
|
16
|
-
|
17
|
-
context "when no options have been defined" do
|
18
|
-
it "should default to {}" do
|
19
|
-
expect(subject.options).to eq({})
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when a options is explicitly set" do
|
24
|
-
module TestOptions
|
25
|
-
class ExplicitCmd
|
26
|
-
include CommandKit::Options
|
27
|
-
option :foo, desc: 'Foo option'
|
28
|
-
option :bar, desc: 'Bar option'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
subject { TestOptions::ExplicitCmd }
|
33
|
-
|
34
|
-
it "must return the explicitly set options" do
|
35
|
-
expect(subject.options.keys).to eq([:foo, :bar])
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "when the command class inherites from another class" do
|
40
|
-
context "but no options are defined" do
|
41
|
-
module TestOptions
|
42
|
-
class BaseCmd
|
43
|
-
include CommandKit::Options
|
44
|
-
end
|
45
|
-
|
46
|
-
class InheritedCmd < BaseCmd
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
subject { TestOptions::InheritedCmd }
|
51
|
-
|
52
|
-
it "must search each class then return {}"do
|
53
|
-
expect(subject.options).to eq({})
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
module TestOptions
|
58
|
-
class ExplicitBaseCmd
|
59
|
-
include CommandKit::Options
|
60
|
-
option :foo, desc: 'Foo option'
|
61
|
-
option :bar, desc: 'Bar option'
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "when the superclass defines options" do
|
66
|
-
module TestOptions
|
67
|
-
class ImplicitInheritedCmd < ExplicitBaseCmd
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
let(:super_subject) { TestOptions::ExplicitBaseCmd }
|
72
|
-
subject { TestOptions::ImplicitInheritedCmd }
|
73
|
-
|
74
|
-
it "must inherit the superclass'es options" do
|
75
|
-
expect(subject.options).to eq(super_subject.options)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "must not change the superclass'es options" do
|
79
|
-
expect(super_subject.options.keys).to eq([:foo, :bar])
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "when the subclass defines options" do
|
84
|
-
module TestOptions
|
85
|
-
class ImplicitBaseCmd
|
86
|
-
include CommandKit::Options
|
87
|
-
end
|
88
|
-
|
89
|
-
class ExplicitInheritedCmd < ImplicitBaseCmd
|
90
|
-
option :baz, desc: 'Baz option'
|
91
|
-
option :qux, desc: 'Qux option'
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
let(:super_subject) { TestOptions::ImplicitBaseCmd }
|
96
|
-
subject { TestOptions::ExplicitInheritedCmd }
|
97
|
-
|
98
|
-
it "must return the subclass'es options" do
|
99
|
-
expect(subject.options.keys).to eq([:baz, :qux])
|
100
|
-
end
|
101
|
-
|
102
|
-
it "must not change the superclass'es options" do
|
103
|
-
expect(super_subject.options).to eq({})
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context "when subclass overrides the superclass's optionss" do
|
108
|
-
module TestOptions
|
109
|
-
class ExplicitOverridingInheritedCmd < ExplicitBaseCmd
|
110
|
-
option :foo, desc: "Overriden foo option"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
let(:super_subject) { TestOptions::ExplicitBaseCmd }
|
115
|
-
subject { TestOptions::ExplicitOverridingInheritedCmd }
|
116
|
-
|
117
|
-
it "must combine the superclass'es options with the subclass'es" do
|
118
|
-
expect(subject.options.keys).to eq([:foo, :bar])
|
119
|
-
expect(subject.options[:foo].desc).to eq("Overriden foo option")
|
120
|
-
expect(subject.options[:bar].desc).to eq("Bar option")
|
121
|
-
end
|
122
|
-
|
123
|
-
it "must not change the superclass'es options" do
|
124
|
-
expect(super_subject.options.keys).to eq([:foo, :bar])
|
125
|
-
expect(super_subject.options[:foo].desc).to eq("Foo option")
|
126
|
-
expect(super_subject.options[:bar].desc).to eq("Bar option")
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe "#initialize" do
|
133
|
-
it "must initialize #options" do
|
134
|
-
expect(subject.options).to eq({})
|
135
|
-
end
|
136
|
-
|
137
|
-
context "when options have default values" do
|
138
|
-
module TestOptions
|
139
|
-
class TestCommandWithDefaultValues
|
140
|
-
|
141
|
-
include CommandKit::Options
|
142
|
-
|
143
|
-
option :option1, value: {
|
144
|
-
required: true,
|
145
|
-
type: String
|
146
|
-
},
|
147
|
-
desc: 'Option 1'
|
148
|
-
|
149
|
-
option :option2, value: {
|
150
|
-
required: false,
|
151
|
-
type: String,
|
152
|
-
default: "foo"
|
153
|
-
},
|
154
|
-
desc: 'Option 2'
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
let(:command_class) { TestOptions::TestCommandWithDefaultValues }
|
159
|
-
|
160
|
-
it "must pre-populate #options with the default values" do
|
161
|
-
expect(subject.options).to_not have_key(:option1)
|
162
|
-
expect(subject.options).to have_key(:option2)
|
163
|
-
expect(subject.options[:option2]).to eq("foo")
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
module TestOptions
|
169
|
-
class TestCommandWithOptionsAndArguments
|
170
|
-
|
171
|
-
include CommandKit::Options
|
172
|
-
|
173
|
-
usage '[OPTIONS] ARG1 [ARG2]'
|
174
|
-
|
175
|
-
option :option1, short: '-a',
|
176
|
-
value: {
|
177
|
-
type: Integer,
|
178
|
-
default: 1
|
179
|
-
},
|
180
|
-
desc: "Option 1"
|
181
|
-
|
182
|
-
option :option2, short: '-b',
|
183
|
-
value: {
|
184
|
-
type: String,
|
185
|
-
usage: 'FILE'
|
186
|
-
},
|
187
|
-
desc: "Option 2"
|
188
|
-
|
189
|
-
argument :argument1, required: true,
|
190
|
-
usage: 'ARG1',
|
191
|
-
desc: "Argument 1"
|
192
|
-
|
193
|
-
argument :argument2, required: false,
|
194
|
-
usage: 'ARG2',
|
195
|
-
desc: "Argument 2"
|
196
|
-
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
describe "#option_parser" do
|
201
|
-
context "when an option does not accept a value" do
|
202
|
-
module TestOptions
|
203
|
-
class TestCommandWithOptionWithoutValue
|
204
|
-
|
205
|
-
include CommandKit::Options
|
206
|
-
|
207
|
-
option :opt, desc: "Option without a value"
|
208
|
-
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
let(:command_class) { TestOptions::TestCommandWithOptionWithoutValue }
|
213
|
-
|
214
|
-
context "but the option flag was not given" do
|
215
|
-
let(:argv) { [] }
|
216
|
-
|
217
|
-
before { subject.option_parser.parse(argv) }
|
218
|
-
|
219
|
-
it "must not populate #options with a value" do
|
220
|
-
expect(subject.options).to be_empty
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
context "and the option flag was given" do
|
225
|
-
let(:argv) { %w[--opt] }
|
226
|
-
|
227
|
-
before { subject.option_parser.parse(argv) }
|
228
|
-
|
229
|
-
it "must set a key in #options to true" do
|
230
|
-
expect(subject.options[:opt]).to be(true)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
context "when an option requires a value" do
|
236
|
-
module TestOptions
|
237
|
-
class TestCommandWithOptionWithRequiredValue
|
238
|
-
|
239
|
-
include CommandKit::Options
|
240
|
-
|
241
|
-
option :opt, value: {
|
242
|
-
required: true,
|
243
|
-
type: String
|
244
|
-
},
|
245
|
-
desc: "Option without a value"
|
246
|
-
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
let(:command_class) do
|
251
|
-
TestOptions::TestCommandWithOptionWithRequiredValue
|
252
|
-
end
|
253
|
-
|
254
|
-
context "but the option flag was not given" do
|
255
|
-
let(:argv) { [] }
|
256
|
-
|
257
|
-
before { subject.option_parser.parse(argv) }
|
258
|
-
|
259
|
-
it "must not populate #options with a value" do
|
260
|
-
expect(subject.options).to be_empty
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
context "and the option flag and value were given" do
|
265
|
-
let(:value) { 'foo' }
|
266
|
-
let(:argv) { ['--opt', value] }
|
267
|
-
|
268
|
-
before { subject.option_parser.parse(argv) }
|
269
|
-
|
270
|
-
it "must set a key in #options to the value" do
|
271
|
-
expect(subject.options[:opt]).to eq(value)
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
context "when an option does not require a value" do
|
277
|
-
module TestOptions
|
278
|
-
class TestCommandWithOptionWithOptionalValue
|
279
|
-
|
280
|
-
include CommandKit::Options
|
281
|
-
|
282
|
-
option :opt, value: {
|
283
|
-
required: false,
|
284
|
-
type: String
|
285
|
-
},
|
286
|
-
desc: "Option without a value"
|
287
|
-
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
let(:command_class) do
|
292
|
-
TestOptions::TestCommandWithOptionWithOptionalValue
|
293
|
-
end
|
294
|
-
|
295
|
-
context "but the option flag was not given" do
|
296
|
-
let(:argv) { [] }
|
297
|
-
|
298
|
-
before { subject.option_parser.parse(argv) }
|
299
|
-
|
300
|
-
it "must not populate #options with a value" do
|
301
|
-
expect(subject.options).to be_empty
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
context "and the option flag and value were given" do
|
306
|
-
let(:value) { 'foo' }
|
307
|
-
let(:argv) { ['--opt', value] }
|
308
|
-
|
309
|
-
before { subject.option_parser.parse(argv) }
|
310
|
-
|
311
|
-
it "must set a key in #options to the value" do
|
312
|
-
expect(subject.options[:opt]).to eq(value)
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
context "and the option has a default value" do
|
317
|
-
module TestOptions
|
318
|
-
class TestCommandWithOptionWithOptionalValueAndDefaultValue
|
319
|
-
|
320
|
-
include CommandKit::Options
|
321
|
-
|
322
|
-
option :opt, value: {
|
323
|
-
required: false,
|
324
|
-
type: String,
|
325
|
-
default: "bar"
|
326
|
-
},
|
327
|
-
desc: "Option without a value"
|
328
|
-
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
let(:command_class) do
|
333
|
-
TestOptions::TestCommandWithOptionWithOptionalValueAndDefaultValue
|
334
|
-
end
|
335
|
-
|
336
|
-
context "but the option flag was not given" do
|
337
|
-
let(:argv) { [] }
|
338
|
-
|
339
|
-
before { subject.option_parser.parse(argv) }
|
340
|
-
|
341
|
-
it "must set a key in #options to the default value" do
|
342
|
-
expect(subject.options[:opt]).to eq("bar")
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
context "and the option flag and value were given" do
|
347
|
-
let(:value) { 'foo' }
|
348
|
-
let(:argv) { ['--opt', value] }
|
349
|
-
|
350
|
-
before { subject.option_parser.parse(argv) }
|
351
|
-
|
352
|
-
it "must set a key in #options to the value" do
|
353
|
-
expect(subject.options[:opt]).to eq(value)
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
context "and the option flag but not the value are given" do
|
358
|
-
let(:argv) { ['--opt'] }
|
359
|
-
|
360
|
-
before { subject.option_parser.parse(argv) }
|
361
|
-
|
362
|
-
it "must set a key in #options to nil" do
|
363
|
-
expect(subject.options).to have_key(:opt)
|
364
|
-
expect(subject.options[:opt]).to be(nil)
|
365
|
-
end
|
366
|
-
end
|
367
|
-
end
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
describe "#main" do
|
372
|
-
let(:command_class) { TestOptions::TestCommandWithOptionsAndArguments }
|
373
|
-
|
374
|
-
let(:argv) { %w[-a 42 -b foo.txt arg1 arg2] }
|
375
|
-
|
376
|
-
it "must parse options before validating the number of arguments" do
|
377
|
-
expect {
|
378
|
-
expect(subject.main(argv)).to eq(0)
|
379
|
-
}.to_not output.to_stderr
|
380
|
-
end
|
381
|
-
|
382
|
-
context "but the wrong number of arguments are given" do
|
383
|
-
let(:argv) { %w[-a 42 -b foo.txt] }
|
384
|
-
|
385
|
-
it "must still validate the number of arguments" do
|
386
|
-
expect {
|
387
|
-
expect(subject.main(argv)).to eq(1)
|
388
|
-
}.to output("#{subject.command_name}: insufficient number of arguments.#{$/}").to_stderr
|
389
|
-
end
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
describe "#help" do
|
394
|
-
let(:command_class) { TestOptions::TestCommandWithOptionsAndArguments }
|
395
|
-
|
396
|
-
let(:option1) { command_class.options[:option1] }
|
397
|
-
let(:option2) { command_class.options[:option2] }
|
398
|
-
let(:argument1) { command_class.arguments[:argument1] }
|
399
|
-
let(:argument2) { command_class.arguments[:argument2] }
|
400
|
-
|
401
|
-
it "must print the usage, options and arguments" do
|
402
|
-
expect { subject.help }.to output(
|
403
|
-
[
|
404
|
-
"Usage: #{subject.usage}",
|
405
|
-
'',
|
406
|
-
'Options:',
|
407
|
-
" #{option1.usage.join(', ').ljust(33 - 1)} #{option1.desc}",
|
408
|
-
" #{option2.usage.join(', ').ljust(33 - 1)} #{option2.desc}",
|
409
|
-
' -h, --help Print help information',
|
410
|
-
'',
|
411
|
-
"Arguments:",
|
412
|
-
" #{argument1.usage.ljust(33)}#{argument1.desc}",
|
413
|
-
" #{argument2.usage.ljust(33)}#{argument2.desc}",
|
414
|
-
''
|
415
|
-
].join($/)
|
416
|
-
).to_stdout
|
417
|
-
end
|
418
|
-
|
419
|
-
context "but when the options are have categories" do
|
420
|
-
module TestOptions
|
421
|
-
class TestCommandWithOptionsAndCategories
|
422
|
-
|
423
|
-
include CommandKit::Options
|
424
|
-
|
425
|
-
option :opt1, short: '-a',
|
426
|
-
desc: "Option 1"
|
427
|
-
option :opt2, short: '-b',
|
428
|
-
desc: "Option 2"
|
429
|
-
|
430
|
-
option :opt3, short: '-c',
|
431
|
-
desc: "Option 3",
|
432
|
-
category: 'Other Options'
|
433
|
-
option :opt4, short: '-d',
|
434
|
-
desc: "Option 4",
|
435
|
-
category: 'Other Options'
|
436
|
-
end
|
437
|
-
end
|
438
|
-
|
439
|
-
let(:command_class) { TestOptions::TestCommandWithOptionsAndCategories }
|
440
|
-
|
441
|
-
let(:option1) { command_class.options[:opt1] }
|
442
|
-
let(:option2) { command_class.options[:opt2] }
|
443
|
-
let(:option3) { command_class.options[:opt3] }
|
444
|
-
let(:option4) { command_class.options[:opt4] }
|
445
|
-
|
446
|
-
it "must group the options by category" do
|
447
|
-
expect { subject.help }.to output(
|
448
|
-
[
|
449
|
-
"Usage: #{subject.usage}",
|
450
|
-
'',
|
451
|
-
'Other Options:',
|
452
|
-
" #{option3.usage.join(', ').ljust(33 - 1)} #{option3.desc}",
|
453
|
-
" #{option4.usage.join(', ').ljust(33 - 1)} #{option4.desc}",
|
454
|
-
'',
|
455
|
-
'Options:',
|
456
|
-
" #{option1.usage.join(', ').ljust(33 - 1)} #{option1.desc}",
|
457
|
-
" #{option2.usage.join(', ').ljust(33 - 1)} #{option2.desc}",
|
458
|
-
' -h, --help Print help information',
|
459
|
-
''
|
460
|
-
].join($/)
|
461
|
-
).to_stdout
|
462
|
-
end
|
463
|
-
end
|
464
|
-
end
|
465
|
-
end
|
data/spec/os/linux_spec.rb
DELETED
@@ -1,164 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'command_kit/os/linux'
|
3
|
-
|
4
|
-
describe CommandKit::OS::Linux do
|
5
|
-
module TestOSLinux
|
6
|
-
class TestCommand
|
7
|
-
include CommandKit::OS::Linux
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:command_class) { TestOSLinux::TestCommand }
|
12
|
-
|
13
|
-
describe ".linux_distro" do
|
14
|
-
subject { command_class }
|
15
|
-
|
16
|
-
context "and the /etc/fedora-release file exists" do
|
17
|
-
before do
|
18
|
-
expect(File).to receive(:file?).with("/etc/fedora-release").and_return(true)
|
19
|
-
end
|
20
|
-
|
21
|
-
it { expect(subject.linux_distro).to be(:fedora) }
|
22
|
-
end
|
23
|
-
|
24
|
-
context "and the /etc/redhat-release file exists" do
|
25
|
-
before do
|
26
|
-
allow(File).to receive(:file?).with("/etc/fedora-release").and_return(false)
|
27
|
-
expect(File).to receive(:file?).with("/etc/redhat-release").and_return(true)
|
28
|
-
end
|
29
|
-
|
30
|
-
it { expect(subject.linux_distro).to be(:redhat) }
|
31
|
-
end
|
32
|
-
|
33
|
-
context "and the /etc/debian_version file exists" do
|
34
|
-
before do
|
35
|
-
allow(File).to receive(:file?).with("/etc/fedora-release").and_return(false)
|
36
|
-
allow(File).to receive(:file?).with("/etc/redhat-release").and_return(false)
|
37
|
-
expect(File).to receive(:file?).with("/etc/debian_version").and_return(true)
|
38
|
-
end
|
39
|
-
|
40
|
-
it { expect(subject.linux_distro).to be(:debian) }
|
41
|
-
end
|
42
|
-
|
43
|
-
context "and the /etc/SuSE-release file exists" do
|
44
|
-
before do
|
45
|
-
allow(File).to receive(:file?).with("/etc/fedora-release").and_return(false)
|
46
|
-
allow(File).to receive(:file?).with("/etc/redhat-release").and_return(false)
|
47
|
-
allow(File).to receive(:file?).with("/etc/debian_version").and_return(false)
|
48
|
-
expect(File).to receive(:file?).with("/etc/SuSE-release").and_return(true)
|
49
|
-
end
|
50
|
-
|
51
|
-
it { expect(subject.linux_distro).to be(:suse) }
|
52
|
-
end
|
53
|
-
|
54
|
-
context "and the /etc/arch-release file exists" do
|
55
|
-
before do
|
56
|
-
allow(File).to receive(:file?).with("/etc/fedora-release").and_return(false)
|
57
|
-
allow(File).to receive(:file?).with("/etc/redhat-release").and_return(false)
|
58
|
-
allow(File).to receive(:file?).with("/etc/debian_version").and_return(false)
|
59
|
-
allow(File).to receive(:file?).with("/etc/SuSE-release").and_return(false)
|
60
|
-
expect(File).to receive(:file?).with("/etc/arch-release").and_return(true)
|
61
|
-
end
|
62
|
-
|
63
|
-
it { expect(subject.linux_distro).to be(:arch) }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
subject { command_class.new }
|
68
|
-
|
69
|
-
describe "#initialize" do
|
70
|
-
it "must default #linux_distro to self.class.linux_distro" do
|
71
|
-
expect(subject.linux_distro).to eq(command_class.linux_distro)
|
72
|
-
end
|
73
|
-
|
74
|
-
context "when the linux_distro: keyword is given" do
|
75
|
-
let(:linux_distro) { :suse }
|
76
|
-
|
77
|
-
subject { command_class.new(linux_distro: linux_distro) }
|
78
|
-
|
79
|
-
it "must set #linux_distro" do
|
80
|
-
expect(subject.linux_distro).to eq(linux_distro)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "#redhat_linux?" do
|
86
|
-
subject { command_class.new(linux_distro: linux_distro) }
|
87
|
-
|
88
|
-
context "when #linux_distro is :redhat" do
|
89
|
-
let(:linux_distro) { :redhat }
|
90
|
-
|
91
|
-
it { expect(subject.redhat_linux?).to be(true) }
|
92
|
-
end
|
93
|
-
|
94
|
-
context "when #linux_distro is not :redhat" do
|
95
|
-
let(:linux_distro) { :debian }
|
96
|
-
|
97
|
-
it { expect(subject.redhat_linux?).to be(false) }
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "#fedora_linux?" do
|
102
|
-
subject { command_class.new(linux_distro: linux_distro) }
|
103
|
-
|
104
|
-
context "when #linux_distro is :fedora" do
|
105
|
-
let(:linux_distro) { :fedora }
|
106
|
-
|
107
|
-
it { expect(subject.fedora_linux?).to be(true) }
|
108
|
-
end
|
109
|
-
|
110
|
-
context "when #linux_distro is not :fedora" do
|
111
|
-
let(:linux_distro) { :debian }
|
112
|
-
|
113
|
-
it { expect(subject.fedora_linux?).to be(false) }
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "#debian_linux?" do
|
118
|
-
subject { command_class.new(linux_distro: linux_distro) }
|
119
|
-
|
120
|
-
context "when #linux_distro is :debian" do
|
121
|
-
let(:linux_distro) { :debian }
|
122
|
-
|
123
|
-
it { expect(subject.debian_linux?).to be(true) }
|
124
|
-
end
|
125
|
-
|
126
|
-
context "when #linux_distro is not :fedora" do
|
127
|
-
let(:linux_distro) { :redhat }
|
128
|
-
|
129
|
-
it { expect(subject.debian_linux?).to be(false) }
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "#suse_linux?" do
|
134
|
-
subject { command_class.new(linux_distro: linux_distro) }
|
135
|
-
|
136
|
-
context "when #linux_distro is :suse" do
|
137
|
-
let(:linux_distro) { :suse }
|
138
|
-
|
139
|
-
it { expect(subject.suse_linux?).to be(true) }
|
140
|
-
end
|
141
|
-
|
142
|
-
context "when #linux_distro is not :suse" do
|
143
|
-
let(:linux_distro) { :debian }
|
144
|
-
|
145
|
-
it { expect(subject.suse_linux?).to be(false) }
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe "#arch_linux?" do
|
150
|
-
subject { command_class.new(linux_distro: linux_distro) }
|
151
|
-
|
152
|
-
context "when #linux_distro is :arch" do
|
153
|
-
let(:linux_distro) { :arch }
|
154
|
-
|
155
|
-
it { expect(subject.arch_linux?).to be(true) }
|
156
|
-
end
|
157
|
-
|
158
|
-
context "when #linux_distro is not :arch" do
|
159
|
-
let(:linux_distro) { :debian }
|
160
|
-
|
161
|
-
it { expect(subject.arch_linux?).to be(false) }
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|