clamp 1.3.2 → 1.3.3

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.
@@ -29,17 +29,27 @@ describe Clamp::Command do
29
29
 
30
30
  end
31
31
 
32
- it "delegates to sub-commands" do
32
+ describe "flip command" do
33
+ before do
34
+ command.run(["flip"])
35
+ end
33
36
 
34
- command.run(["flip"])
35
- expect(stdout).to match(/FLIPPED/)
37
+ it "delegates to sub-commands" do
38
+ expect(stdout).to match(/FLIPPED/)
39
+ end
40
+ end
36
41
 
37
- command.run(["flop"])
38
- expect(stdout).to match(/FLOPPED/)
42
+ describe "flop command" do
43
+ before do
44
+ command.run(["flop"])
45
+ end
39
46
 
47
+ it "delegates to sub-commands" do
48
+ expect(stdout).to match(/FLOPPED/)
49
+ end
40
50
  end
41
51
 
42
- context "executed with no subcommand" do
52
+ context "when executed with no subcommand" do
43
53
 
44
54
  it "triggers help" do
45
55
  expect do
@@ -56,10 +66,7 @@ describe Clamp::Command do
56
66
  end
57
67
 
58
68
  it "lists subcommands" do
59
- help = command.help
60
- expect(help).to match(/Subcommands:/)
61
- expect(help).to match(/flip +flip it/)
62
- expect(help).to match(/flop +flop it/)
69
+ expect(command.help).to match(/Subcommands:\n +flip +flip it\n +flop +flop it/)
63
70
  end
64
71
 
65
72
  it "handles new lines in subcommand descriptions" do
@@ -95,13 +102,27 @@ describe Clamp::Command do
95
102
 
96
103
  end
97
104
 
98
- it "responds to both aliases" do
105
+ describe "the first alias" do
106
+
107
+ before do
108
+ command.run(["say", "boo"])
109
+ end
110
+
111
+ it "responds to it" do
112
+ expect(stdout).to match(/boo/)
113
+ end
114
+
115
+ end
116
+
117
+ describe "the second alias" do
99
118
 
100
- command.run(["say", "boo"])
101
- expect(stdout).to match(/boo/)
119
+ before do
120
+ command.run(["talk", "jive"])
121
+ end
102
122
 
103
- command.run(["talk", "jive"])
104
- expect(stdout).to match(/jive/)
123
+ it "responds to it" do
124
+ expect(stdout).to match(/jive/)
125
+ end
105
126
 
106
127
  end
107
128
 
@@ -167,7 +188,7 @@ describe Clamp::Command do
167
188
 
168
189
  end
169
190
 
170
- context "executed with no subcommand" do
191
+ context "when executed with no subcommand" do
171
192
 
172
193
  it "invokes the default subcommand" do
173
194
  command.run([])
@@ -192,7 +213,7 @@ describe Clamp::Command do
192
213
 
193
214
  end
194
215
 
195
- context "executed with no subcommand" do
216
+ context "when executed with no subcommand" do
196
217
 
197
218
  it "invokes the default subcommand" do
198
219
  command.run([])
@@ -203,24 +224,26 @@ describe Clamp::Command do
203
224
 
204
225
  end
205
226
 
206
- context "declaring a default subcommand after subcommands" do
227
+ context "when declaring a default subcommand after subcommands" do
207
228
 
208
- it "is not supported" do
229
+ let(:command) do
230
+ Class.new(Clamp::Command) do
209
231
 
210
- expect do
211
- Class.new(Clamp::Command) do
232
+ subcommand "status", "Show status" do
212
233
 
213
- subcommand "status", "Show status" do
234
+ def execute
235
+ puts "All good!"
236
+ end
214
237
 
215
- def execute
216
- puts "All good!"
217
- end
238
+ end
218
239
 
219
- end
240
+ end
241
+ end
220
242
 
221
- self.default_subcommand = "status"
243
+ it "is not supported" do
222
244
 
223
- end
245
+ expect do
246
+ command.default_subcommand = "status"
224
247
  end.to raise_error(/default_subcommand must be defined before subcommands/)
225
248
 
226
249
  end
@@ -251,20 +274,18 @@ describe Clamp::Command do
251
274
 
252
275
  it "allows the parameter to be specified first" do
253
276
  command.run(["dummy", "spit"])
254
- expect(stdout.strip).to eql "spat the dummy"
277
+ expect(stdout.strip).to eq "spat the dummy"
255
278
  end
256
279
 
257
280
  it "passes the parameter down the stack" do
258
281
  command.run(["money", "say", "loud"])
259
- expect(stdout.strip).to eql "MONEY"
282
+ expect(stdout.strip).to eq "MONEY"
260
283
  end
261
284
 
262
285
  it "shows parameter in usage help" do
263
- begin
264
- command.run(["stuff", "say", "loud", "--help"])
265
- rescue Clamp::HelpWanted => e
266
- expect(e.command.invocation_path).to eql("with THING say loud")
267
- end
286
+ command.run(["stuff", "say", "loud", "--help"])
287
+ rescue Clamp::HelpWanted => e
288
+ expect(e.command.invocation_path).to eq "with THING say loud"
268
289
  end
269
290
 
270
291
  end
@@ -275,6 +296,7 @@ describe Clamp::Command do
275
296
 
276
297
  speed_options = Module.new do
277
298
  extend Clamp::Option::Declaration
299
+
278
300
  option "--speed", "SPEED", "how fast", default: "slowly"
279
301
  end
280
302
 
@@ -338,7 +360,7 @@ describe Clamp::Command do
338
360
 
339
361
  it "only parses options once" do
340
362
  command.run(["--json", '{"a":"b"}', "woohoohoo"])
341
- expect(stdout).to eql "parsing!"
363
+ expect(stdout).to eq "parsing!"
342
364
  end
343
365
 
344
366
  end
@@ -378,19 +400,16 @@ describe Clamp::Command do
378
400
  command_class.new("foo")
379
401
  end
380
402
 
381
- it "should signal no such subcommand usage error" do
382
- expect { command.run(["foo"]) }.to raise_error(Clamp::UsageError) do |exception|
383
- expect(exception.message).to eq "No such sub-command 'foo'"
384
- end
403
+ it "signals no such subcommand usage error" do
404
+ expect { command.run(["foo"]) }.to raise_error(Clamp::UsageError, "No such sub-command 'foo'")
385
405
  end
386
406
 
387
- it "should execute the subcommand missing method" do
407
+ it "executes the subcommand missing method" do
388
408
  command.extend subcommand_missing
389
- expect { command.run(["foo"]) }.to raise_error(SystemExit)
390
- expect(stderr).to match(/there is no such thing/)
409
+ expect { command.run(["foo"]) }.to raise_error(SystemExit, /there is no such thing/)
391
410
  end
392
411
 
393
- it "should use the subcommand class returned from subcommand_missing" do
412
+ it "uses the subcommand class returned from subcommand_missing" do
394
413
  command.extend subcommand_missing_with_return
395
414
  command.run(["foo"])
396
415
  expect(stdout).to match(/known subcommand/)
@@ -411,7 +430,7 @@ describe Clamp::Command do
411
430
 
412
431
  it "allows options after the subcommand" do
413
432
  command.run(%w[hop --direction south])
414
- expect(stdout).to eql "Hopping south\n"
433
+ expect(stdout).to eq "Hopping south\n"
415
434
  end
416
435
 
417
436
  end
@@ -12,6 +12,7 @@ describe Clamp::Command do
12
12
 
13
13
  shared_options = Module.new do
14
14
  extend Clamp::Option::Declaration
15
+
15
16
  option "--size", "SIZE", default: 4
16
17
  end
17
18
 
@@ -31,7 +32,7 @@ describe Clamp::Command do
31
32
 
32
33
  it "accepts options from included module" do
33
34
  command.run(["--size", "42"])
34
- expect(stdout).to eql "size = 42\n"
35
+ expect(stdout).to eq "size = 42\n"
35
36
  end
36
37
 
37
38
  end
@@ -40,17 +40,17 @@ describe Clamp::Command do
40
40
 
41
41
  it "still works" do
42
42
  command.run(%w[say foo])
43
- expect(stdout).to eql("foo\n")
43
+ expect(stdout).to eq "foo\n"
44
44
  end
45
45
 
46
46
  it "honours options after positional arguments" do
47
47
  command.run(%w[say blah --verbose])
48
- expect(stdout).to eql("blahblahblah\n")
48
+ expect(stdout).to eq "blahblahblah\n"
49
49
  end
50
50
 
51
51
  it "honours options declared on subcommands" do
52
52
  command.run(%w[say --loud blah])
53
- expect(stdout).to eql("BLAH\n")
53
+ expect(stdout).to eq "BLAH\n"
54
54
  end
55
55
 
56
56
  end