command_kit 0.1.0.pre2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +15 -0
  3. data/.rubocop.yml +141 -0
  4. data/ChangeLog.md +98 -2
  5. data/Gemfile +3 -0
  6. data/README.md +189 -117
  7. data/Rakefile +3 -2
  8. data/command_kit.gemspec +4 -4
  9. data/examples/command.rb +1 -1
  10. data/gemspec.yml +10 -2
  11. data/lib/command_kit/arguments/argument.rb +2 -0
  12. data/lib/command_kit/arguments/argument_value.rb +2 -0
  13. data/lib/command_kit/arguments.rb +23 -4
  14. data/lib/command_kit/colors.rb +253 -45
  15. data/lib/command_kit/command.rb +6 -1
  16. data/lib/command_kit/command_name.rb +9 -0
  17. data/lib/command_kit/commands/auto_load.rb +24 -1
  18. data/lib/command_kit/commands/auto_require.rb +16 -0
  19. data/lib/command_kit/commands/command.rb +3 -0
  20. data/lib/command_kit/commands/help.rb +5 -2
  21. data/lib/command_kit/commands/parent_command.rb +7 -0
  22. data/lib/command_kit/commands/subcommand.rb +13 -1
  23. data/lib/command_kit/commands.rb +54 -9
  24. data/lib/command_kit/description.rb +12 -1
  25. data/lib/command_kit/env/home.rb +9 -0
  26. data/lib/command_kit/env/path.rb +16 -1
  27. data/lib/command_kit/env.rb +4 -0
  28. data/lib/command_kit/examples.rb +12 -1
  29. data/lib/command_kit/exception_handler.rb +4 -0
  30. data/lib/command_kit/help/man.rb +26 -30
  31. data/lib/command_kit/help.rb +7 -1
  32. data/lib/command_kit/inflector.rb +49 -17
  33. data/lib/command_kit/interactive.rb +248 -0
  34. data/lib/command_kit/main.rb +18 -9
  35. data/lib/command_kit/man.rb +44 -0
  36. data/lib/command_kit/open_app.rb +69 -0
  37. data/lib/command_kit/options/option.rb +3 -6
  38. data/lib/command_kit/options/option_value.rb +5 -2
  39. data/lib/command_kit/options/parser.rb +46 -19
  40. data/lib/command_kit/options/quiet.rb +3 -0
  41. data/lib/command_kit/options/verbose.rb +5 -0
  42. data/lib/command_kit/options/version.rb +6 -0
  43. data/lib/command_kit/options.rb +32 -7
  44. data/lib/command_kit/os/linux.rb +157 -0
  45. data/lib/command_kit/os.rb +165 -11
  46. data/lib/command_kit/package_manager.rb +200 -0
  47. data/lib/command_kit/pager.rb +80 -11
  48. data/lib/command_kit/printing/indent.rb +27 -4
  49. data/lib/command_kit/printing.rb +35 -1
  50. data/lib/command_kit/program_name.rb +7 -0
  51. data/lib/command_kit/stdio.rb +24 -0
  52. data/lib/command_kit/sudo.rb +40 -0
  53. data/lib/command_kit/terminal.rb +159 -0
  54. data/lib/command_kit/usage.rb +14 -0
  55. data/lib/command_kit/version.rb +1 -1
  56. data/lib/command_kit/xdg.rb +13 -0
  57. data/lib/command_kit.rb +1 -0
  58. data/spec/arguments/argument_spec.rb +2 -2
  59. data/spec/arguments_spec.rb +53 -27
  60. data/spec/colors_spec.rb +277 -13
  61. data/spec/command_name_spec.rb +1 -1
  62. data/spec/command_spec.rb +79 -5
  63. data/spec/commands/auto_load/subcommand_spec.rb +1 -1
  64. data/spec/commands/auto_load_spec.rb +34 -3
  65. data/spec/commands/auto_require_spec.rb +2 -2
  66. data/spec/commands/help_spec.rb +1 -1
  67. data/spec/commands/parent_command_spec.rb +1 -1
  68. data/spec/commands/subcommand_spec.rb +1 -1
  69. data/spec/commands_spec.rb +103 -29
  70. data/spec/description_spec.rb +1 -25
  71. data/spec/env/home_spec.rb +1 -1
  72. data/spec/env/path_spec.rb +7 -1
  73. data/spec/examples_spec.rb +1 -25
  74. data/spec/exception_handler_spec.rb +1 -1
  75. data/spec/help/man_spec.rb +45 -58
  76. data/spec/help_spec.rb +0 -25
  77. data/spec/inflector_spec.rb +71 -9
  78. data/spec/interactive_spec.rb +415 -0
  79. data/spec/main_spec.rb +7 -7
  80. data/spec/man_spec.rb +46 -0
  81. data/spec/open_app_spec.rb +85 -0
  82. data/spec/options/option_spec.rb +5 -5
  83. data/spec/options/option_value_spec.rb +56 -1
  84. data/spec/options_spec.rb +283 -1
  85. data/spec/os/linux_spec.rb +164 -0
  86. data/spec/os_spec.rb +201 -14
  87. data/spec/package_manager_spec.rb +806 -0
  88. data/spec/pager_spec.rb +76 -11
  89. data/spec/printing/indent_spec.rb +8 -6
  90. data/spec/printing_spec.rb +33 -3
  91. data/spec/program_name_spec.rb +1 -1
  92. data/spec/spec_helper.rb +0 -3
  93. data/spec/sudo_spec.rb +51 -0
  94. data/spec/{console_spec.rb → terminal_spec.rb} +65 -35
  95. data/spec/usage_spec.rb +2 -2
  96. data/spec/xdg_spec.rb +1 -1
  97. metadata +26 -8
  98. data/lib/command_kit/console.rb +0 -141
data/spec/options_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/options'
3
3
 
4
- describe Options do
4
+ describe CommandKit::Options do
5
5
  module TestOptions
6
6
  class ImplicitCmd
7
7
  include CommandKit::Options
@@ -133,5 +133,287 @@ describe Options do
133
133
  it "must initialize #options" do
134
134
  expect(subject.options).to eq({})
135
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
136
418
  end
137
419
  end
@@ -0,0 +1,164 @@
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
data/spec/os_spec.rb CHANGED
@@ -1,46 +1,233 @@
1
1
  require 'spec_helper'
2
2
  require 'command_kit/os'
3
3
 
4
- describe OS do
5
- class TestOS
6
- include CommandKit::OS
4
+ describe CommandKit::OS do
5
+ module TestOS
6
+ class TestCommand
7
+ include CommandKit::OS
8
+ end
7
9
  end
8
10
 
9
- subject { TestOS.new }
11
+ let(:command_class) { TestOS::TestCommand }
12
+ subject { command_class.new }
13
+
14
+ describe ".os" do
15
+ subject { command_class }
10
16
 
11
- describe "#linux?" do
12
17
  context "when RUBY_PLATFORM contains 'linux'" do
13
18
  before { stub_const('RUBY_PLATFORM','x86_64-linux') }
14
19
 
15
- it { expect(subject.linux?).to be(true) }
20
+ it { expect(subject.os).to be(:linux) }
16
21
  end
17
22
 
18
- context "when RUBY_PLATFORM does not contain 'linux'" do
23
+ context "when RUBY_PLATFORM contains 'darwin'" do
19
24
  before { stub_const('RUBY_PLATFORM','aarch64-darwin') }
20
25
 
26
+ it { expect(subject.os).to be(:macos) }
27
+ end
28
+
29
+ context "when RUBY_PLATFORM contains 'freebsd'" do
30
+ before { stub_const('RUBY_PLATFORM','x86_64-freebsd') }
31
+
32
+ it { expect(subject.os).to be(:freebsd) }
33
+ end
34
+
35
+ context "when RUBY_PLATFORM contains 'openbsd'" do
36
+ before { stub_const('RUBY_PLATFORM','x86_64-openbsd') }
37
+
38
+ it { expect(subject.os).to be(:openbsd) }
39
+ end
40
+
41
+ context "when RUBY_PLATFORM contains 'netbsd'" do
42
+ before { stub_const('RUBY_PLATFORM','x86_64-netbsd') }
43
+
44
+ it { expect(subject.os).to be(:netbsd) }
45
+ end
46
+
47
+ context "when Gem.win_platform? returns true" do
48
+ before do
49
+ stub_const('RUBY_PLATFORM','x86_64-mswin')
50
+
51
+ expect(Gem).to receive(:win_platform?).and_return(true)
52
+ end
53
+
54
+ it { expect(subject.os).to be(:windows) }
55
+ end
56
+ end
57
+
58
+ describe "#initialize" do
59
+ it "must default #os to self.class.os" do
60
+ expect(subject.os).to eq(command_class.os)
61
+ end
62
+
63
+ context "when initialized with the os: keyword" do
64
+ let(:os) { :netbsd }
65
+
66
+ subject { command_class.new(os: os) }
67
+
68
+ it "must set #os" do
69
+ expect(subject.os).to eq(os)
70
+ end
71
+ end
72
+ end
73
+
74
+ describe "#linux?" do
75
+ context "when #os is :linux" do
76
+ subject { command_class.new(os: :linux) }
77
+
78
+ it { expect(subject.linux?).to be(true) }
79
+ end
80
+
81
+ context "when #os is not :linux" do
82
+ subject { command_class.new(os: :windows) }
83
+
21
84
  it { expect(subject.linux?).to be(false) }
22
85
  end
23
86
  end
24
87
 
25
88
  describe "#macos?" do
26
- context "when RUBY_PLATFORM contains 'darwin'" do
27
- before { stub_const('RUBY_PLATFORM','aarch64-darwin') }
89
+ context "when #os is :macos" do
90
+ subject { command_class.new(os: :macos) }
28
91
 
29
92
  it { expect(subject.macos?).to be(true) }
30
93
  end
31
94
 
32
- context "when RUBY_PLATFORM does not contain 'darwin'" do
33
- before { stub_const('RUBY_PLATFORM','mswin') }
95
+ context "when #os is not :macos" do
96
+ subject { command_class.new(os: :windows) }
34
97
 
35
98
  it { expect(subject.macos?).to be(false) }
36
99
  end
37
100
  end
38
101
 
102
+ describe "#freebsd?" do
103
+ context "when #os is :freebsd" do
104
+ subject { command_class.new(os: :freebsd) }
105
+
106
+ it { expect(subject.freebsd?).to be(true) }
107
+ end
108
+
109
+ context "when #os is not :freebsd" do
110
+ subject { command_class.new(os: :windows) }
111
+
112
+ it { expect(subject.freebsd?).to be(false) }
113
+ end
114
+ end
115
+
116
+ describe "#openbsd?" do
117
+ context "when #os is :openbsd" do
118
+ subject { command_class.new(os: :openbsd) }
119
+
120
+ it { expect(subject.openbsd?).to be(true) }
121
+ end
122
+
123
+ context "when #os is not :openbsd" do
124
+ subject { command_class.new(os: :windows) }
125
+
126
+ it { expect(subject.openbsd?).to be(false) }
127
+ end
128
+ end
129
+
130
+ describe "#netbsd?" do
131
+ context "when #os is :netbsd" do
132
+ subject { command_class.new(os: :netbsd) }
133
+
134
+ it { expect(subject.netbsd?).to be(true) }
135
+ end
136
+
137
+ context "when #os is not :netbsd" do
138
+ subject { command_class.new(os: :windows) }
139
+
140
+ it { expect(subject.netbsd?).to be(false) }
141
+ end
142
+ end
143
+
144
+ describe "#bsd?" do
145
+ context "when #os is :freebsd" do
146
+ subject { command_class.new(os: :freebsd) }
147
+
148
+ it { expect(subject.bsd?).to be(true) }
149
+ end
150
+
151
+ context "when #os is :openbsd" do
152
+ subject { command_class.new(os: :openbsd) }
153
+
154
+ it { expect(subject.bsd?).to be(true) }
155
+ end
156
+
157
+ context "when #os is :netbsd" do
158
+ subject { command_class.new(os: :netbsd) }
159
+
160
+ it { expect(subject.bsd?).to be(true) }
161
+ end
162
+
163
+ context "when #os is :macos" do
164
+ subject { command_class.new(os: :macos) }
165
+
166
+ it { expect(subject.bsd?).to be(false) }
167
+ end
168
+
169
+ context "when #os is :linux" do
170
+ subject { command_class.new(os: :linux) }
171
+
172
+ it { expect(subject.bsd?).to be(false) }
173
+ end
174
+
175
+ context "when #os is :windows" do
176
+ subject { command_class.new(os: :windows) }
177
+
178
+ it { expect(subject.bsd?).to be(false) }
179
+ end
180
+ end
181
+
182
+ describe "#unix?" do
183
+ context "when #os is :freebsd" do
184
+ subject { command_class.new(os: :freebsd) }
185
+
186
+ it { expect(subject.unix?).to be(true) }
187
+ end
188
+
189
+ context "when #os is :openbsd" do
190
+ subject { command_class.new(os: :openbsd) }
191
+
192
+ it { expect(subject.unix?).to be(true) }
193
+ end
194
+
195
+ context "when #os is :netbsd" do
196
+ subject { command_class.new(os: :netbsd) }
197
+
198
+ it { expect(subject.unix?).to be(true) }
199
+ end
200
+
201
+ context "when #os is :macos" do
202
+ subject { command_class.new(os: :macos) }
203
+
204
+ it { expect(subject.unix?).to be(true) }
205
+ end
206
+
207
+ context "when #os is :linux" do
208
+ subject { command_class.new(os: :linux) }
209
+
210
+ it { expect(subject.unix?).to be(true) }
211
+ end
212
+
213
+ context "when #os is :windows" do
214
+ subject { command_class.new(os: :windows) }
215
+
216
+ it { expect(subject.unix?).to be(false) }
217
+ end
218
+ end
219
+
39
220
  describe "#windows?" do
40
- it "must call Gem.win_platform?" do
41
- expect(Gem).to receive(:win_platform?)
221
+ context "when #os is :windows" do
222
+ subject { command_class.new(os: :windows) }
223
+
224
+ it { expect(subject.windows?).to be(true) }
225
+ end
226
+
227
+ context "when #os is not :windows" do
228
+ subject { command_class.new(os: :linux) }
42
229
 
43
- subject.windows?
230
+ it { expect(subject.windows?).to be(false) }
44
231
  end
45
232
  end
46
233
  end