Skip to content

Commit

Permalink
Ensure that an error is raised even if all tasks were already invoked.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jun 23, 2009
1 parent 0350e09 commit 9ddba47
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
24 changes: 13 additions & 11 deletions lib/thor/invocation.rb
Expand Up @@ -80,29 +80,31 @@ def initialize(args=[], options={}, config={}, &block) #:nodoc:
#
def invoke(name, task=nil, method_args=nil)
task, method_args = nil, task if task.is_a?(Array)

object, task = _setup_for_invoke(name, task)
klass = object.is_a?(Class) ? object : object.class

current = @_invocations[klass]
return if current.include?("all")

if object.is_a?(Class)
klass = object
instance, trailing = @_initializer.call(klass, task, _overrides_config)
method_args ||= trailing
else
instance = object
klass, instance = object.class, object
end

method_args ||= []
current = @_invocations[klass]

iterator = lambda do |_, task|
unless current.include?(task.name)
current << task.name
task.run(instance, method_args)
end
end

if task
return if current.include?(task.name)
current << task.name
task.run(instance, method_args)
iterator.call(nil, task)
else
current << "all"
klass.all_tasks.collect { |_, task| task.run(instance) }
method_args = []
klass.all_tasks.map(&iterator)
end
end

Expand Down
9 changes: 9 additions & 0 deletions spec/invocation_spec.rb
Expand Up @@ -79,6 +79,15 @@
end.must raise_error(Thor::UndefinedTaskError)
end

it "raises Thor::UndefinedTaskError if the task can't be found even if all tasks where already executed" do
base = C.new
silence(:stdout){ base.invoke(:all) }

lambda do
base.invoke("foo:bar")
end.must raise_error(Thor::UndefinedTaskError)
end

it "raises an error if a non Thor class is given" do
lambda do
A.new.invoke(Object)
Expand Down

0 comments on commit 9ddba47

Please sign in to comment.