File tree Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -421,7 +421,7 @@ def normalize_command_name(meth) #:nodoc:
421
421
422
422
possibilities = find_command_possibilities ( meth )
423
423
if possibilities . size > 1
424
- raise ArgumentError , "Ambiguous command #{ meth } matches [#{ possibilities . join ( ', ' ) } ]"
424
+ raise AmbiguousTaskError , "Ambiguous command #{ meth } matches [#{ possibilities . join ( ', ' ) } ]"
425
425
elsif possibilities . size < 1
426
426
meth = meth || default_command
427
427
elsif map [ meth ]
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ class UndefinedCommandError < Error
13
13
end
14
14
UndefinedTaskError = UndefinedCommandError
15
15
16
+ class AmbiguousCommandError < Error
17
+ end
18
+ AmbiguousTaskError = AmbiguousCommandError
19
+
16
20
# Raised when a command was found, but not invoked properly.
17
21
class InvocationError < Error
18
22
end
Original file line number Diff line number Diff line change @@ -303,12 +303,16 @@ def boring(*args)
303
303
end
304
304
305
305
context "when the user enters an ambiguous substring of a command" do
306
- it "raises an exception that explains the ambiguity" do
307
- expect { MyScript . start ( [ "call" ] ) } . to raise_error ( ArgumentError , 'Ambiguous command call matches [call_myself_with_wrong_arity, call_unexistent_method]' )
306
+ it "raises an exception and displays a message that explains the ambiguity" do
307
+ shell = Thor ::Base . shell . new
308
+ expect ( shell ) . to receive ( :error ) . with ( 'Ambiguous command call matches [call_myself_with_wrong_arity, call_unexistent_method]' )
309
+ MyScript . start ( [ "call" ] , :shell => shell )
308
310
end
309
311
310
312
it "raises an exception when there is an alias" do
311
- expect { MyScript . start ( [ "f" ] ) } . to raise_error ( ArgumentError , 'Ambiguous command f matches [foo, fu]' )
313
+ shell = Thor ::Base . shell . new
314
+ expect ( shell ) . to receive ( :error ) . with ( 'Ambiguous command f matches [foo, fu]' )
315
+ MyScript . start ( [ "f" ] , :shell => shell )
312
316
end
313
317
end
314
318
You can’t perform that action at this time.
0 commit comments