@@ -29,17 +29,27 @@ def message
2929
3030 end
3131
32- it "delegates to sub-commands" do
32+ describe "flip command" do
33+ before do
34+ command . run ( [ "flip" ] )
35+ end
3336
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
3641
37- command . run ( [ "flop" ] )
38- expect ( stdout ) . to match ( /FLOPPED/ )
42+ describe "flop command" do
43+ before do
44+ command . run ( [ "flop" ] )
45+ end
3946
47+ it "delegates to sub-commands" do
48+ expect ( stdout ) . to match ( /FLOPPED/ )
49+ end
4050 end
4151
42- context "executed with no subcommand" do
52+ context "when executed with no subcommand" do
4353
4454 it "triggers help" do
4555 expect do
@@ -56,10 +66,7 @@ def message
5666 end
5767
5868 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/ )
6370 end
6471
6572 it "handles new lines in subcommand descriptions" do
@@ -95,13 +102,27 @@ def execute
95102
96103 end
97104
98- it "responds to both aliases " do
105+ describe "the first alias " do
99106
100- command . run ( [ "say" , "boo" ] )
101- expect ( stdout ) . to match ( /boo/ )
107+ before do
108+ command . run ( [ "say" , "boo" ] )
109+ end
102110
103- command . run ( [ "talk" , "jive" ] )
104- expect ( stdout ) . to match ( /jive/ )
111+ it "responds to it" do
112+ expect ( stdout ) . to match ( /boo/ )
113+ end
114+
115+ end
116+
117+ describe "the second alias" do
118+
119+ before do
120+ command . run ( [ "talk" , "jive" ] )
121+ end
122+
123+ it "responds to it" do
124+ expect ( stdout ) . to match ( /jive/ )
125+ end
105126
106127 end
107128
@@ -167,7 +188,7 @@ def execute
167188
168189 end
169190
170- context "executed with no subcommand" do
191+ context "when executed with no subcommand" do
171192
172193 it "invokes the default subcommand" do
173194 command . run ( [ ] )
@@ -192,7 +213,7 @@ def execute
192213
193214 end
194215
195- context "executed with no subcommand" do
216+ context "when executed with no subcommand" do
196217
197218 it "invokes the default subcommand" do
198219 command . run ( [ ] )
@@ -203,24 +224,26 @@ def execute
203224
204225 end
205226
206- context "declaring a default subcommand after subcommands" do
227+ context "when declaring a default subcommand after subcommands" do
207228
208- it "is not supported" do
229+ let ( :command ) do
230+ Class . new ( Clamp ::Command ) do
209231
210- expect do
211- Class . new ( Clamp ::Command ) do
232+ subcommand "status" , "Show status" do
212233
213- subcommand "status" , "Show status" do
234+ def execute
235+ puts "All good!"
236+ end
214237
215- def execute
216- puts "All good!"
217- end
238+ end
218239
219- end
240+ end
241+ end
220242
221- self . default_subcommand = "status"
243+ it "is not supported" do
222244
223- end
245+ expect do
246+ command . default_subcommand = "status"
224247 end . to raise_error ( /default_subcommand must be defined before subcommands/ )
225248
226249 end
@@ -251,18 +274,18 @@ def execute
251274
252275 it "allows the parameter to be specified first" do
253276 command . run ( [ "dummy" , "spit" ] )
254- expect ( stdout . strip ) . to eql "spat the dummy"
277+ expect ( stdout . strip ) . to eq "spat the dummy"
255278 end
256279
257280 it "passes the parameter down the stack" do
258281 command . run ( [ "money" , "say" , "loud" ] )
259- expect ( stdout . strip ) . to eql "MONEY"
282+ expect ( stdout . strip ) . to eq "MONEY"
260283 end
261284
262285 it "shows parameter in usage help" do
263286 command . run ( [ "stuff" , "say" , "loud" , "--help" ] )
264287 rescue Clamp ::HelpWanted => e
265- expect ( e . command . invocation_path ) . to eql ( "with THING say loud" )
288+ expect ( e . command . invocation_path ) . to eq "with THING say loud"
266289 end
267290
268291 end
@@ -336,7 +359,7 @@ def execute; end
336359
337360 it "only parses options once" do
338361 command . run ( [ "--json" , '{"a":"b"}' , "woohoohoo" ] )
339- expect ( stdout ) . to eql "parsing!"
362+ expect ( stdout ) . to eq "parsing!"
340363 end
341364
342365 end
@@ -376,19 +399,16 @@ def execute; end
376399 command_class . new ( "foo" )
377400 end
378401
379- it "should signal no such subcommand usage error" do
380- expect { command . run ( [ "foo" ] ) } . to raise_error ( Clamp ::UsageError ) do |exception |
381- expect ( exception . message ) . to eq "No such sub-command 'foo'"
382- end
402+ it "signals no such subcommand usage error" do
403+ expect { command . run ( [ "foo" ] ) } . to raise_error ( Clamp ::UsageError , "No such sub-command 'foo'" )
383404 end
384405
385- it "should execute the subcommand missing method" do
406+ it "executes the subcommand missing method" do
386407 command . extend subcommand_missing
387- expect { command . run ( [ "foo" ] ) } . to raise_error ( SystemExit )
388- expect ( stderr ) . to match ( /there is no such thing/ )
408+ expect { command . run ( [ "foo" ] ) } . to raise_error ( SystemExit , /there is no such thing/ )
389409 end
390410
391- it "should use the subcommand class returned from subcommand_missing" do
411+ it "uses the subcommand class returned from subcommand_missing" do
392412 command . extend subcommand_missing_with_return
393413 command . run ( [ "foo" ] )
394414 expect ( stdout ) . to match ( /known subcommand/ )
@@ -409,7 +429,7 @@ def execute
409429
410430 it "allows options after the subcommand" do
411431 command . run ( %w[ hop --direction south ] )
412- expect ( stdout ) . to eql "Hopping south\n "
432+ expect ( stdout ) . to eq "Hopping south\n "
413433 end
414434
415435 end
0 commit comments