Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix unknown command handling when in a setup without thorfiles

  • Loading branch information...
commit b18a6cf181e06ff26c5749b220072f7d6b661ced 1 parent 0cfe4af
@cldwalker cldwalker authored
Showing with 20 additions and 0 deletions.
  1. +1 −0  lib/thor/runner.rb
  2. +19 −0 spec/runner_spec.rb
View
1  lib/thor/runner.rb
@@ -30,6 +30,7 @@ def method_missing(meth, *args)
meth = meth.to_s
initialize_thorfiles(meth)
klass, task = Thor::Util.find_class_and_task_by_namespace(meth)
+ raise UndefinedTaskError, "Could not find task #{task.inspect}" if klass.nil?
args.unshift(task) if task
klass.start(args, :shell => self.shell)
end
View
19 spec/runner_spec.rb
@@ -36,6 +36,16 @@
end
describe "#start" do
+ def when_no_thorfiles_exist
+ old_dir = Dir.pwd
+ Dir.chdir '..'
+ delete = Thor::Base.subclasses.select {|e| e.namespace == 'default' }
+ delete.each {|e| Thor::Base.subclasses.delete e }
+ yield
+ Thor::Base.subclasses.concat delete
+ Dir.chdir old_dir
+ end
+
it "invokes a task from Thor::Runner" do
ARGV.replace ["list"]
capture(:stdout){ Thor::Runner.start }.should =~ /my_counter N/
@@ -72,6 +82,15 @@
content.strip.should == 'Could not find task "unknown" in "default" namespace.'
end
+ it "raises an error if class/task can't be found in a setup without thorfiles" do
+ when_no_thorfiles_exist do
+ ARGV.replace ["unknown"]
+ Thor::Runner.should_receive :exit
+ content = capture(:stderr){ Thor::Runner.start }
+ content.strip.should == 'Could not find task "unknown"'
+ end
+ end
+
it "does not swallow NoMethodErrors that occur inside the called method" do
ARGV.replace ["my_script:call_unexistent_method"]
lambda { Thor::Runner.start }.should raise_error(NoMethodError)
Please sign in to comment.
Something went wrong with that request. Please try again.