diff --git a/lib/rake/task.rb b/lib/rake/task.rb index 1f4f591d5..b1356ed89 100644 --- a/lib/rake/task.rb +++ b/lib/rake/task.rb @@ -141,11 +141,12 @@ def reenable @already_invoked = false end - # Clear the existing prerequisites and actions of a rake task. + # Clear the existing prerequisites, actions, comments, and arguments of a rake task. def clear clear_prerequisites clear_actions clear_comments + clear_args self end @@ -167,6 +168,12 @@ def clear_comments self end + # Clear the existing arguments on a rake task. + def clear_args + @arg_names = nil + self + end + # Invoke the task if it is needed. Prerequisites are invoked first. def invoke(*args) task_args = TaskArguments.new(arg_names, args) diff --git a/test/test_rake_task.rb b/test/test_rake_task.rb index 9a4c3fc23..91185257c 100644 --- a/test/test_rake_task.rb +++ b/test/test_rake_task.rb @@ -112,11 +112,12 @@ def test_can_double_invoke_with_reenable def test_clear desc "a task" - t = task("t" => "a") { } + t = task("t", ["b"] => "a") { } t.clear assert t.prerequisites.empty?, "prerequisites should be empty" assert t.actions.empty?, "actions should be empty" assert_nil t.comment, "comments should be empty" + assert_empty t.arg_names, "arg names should be empty" end def test_clear_prerequisites @@ -148,6 +149,18 @@ def test_clear_comments assert_equal 1, task(:foo).actions.size end + def test_clear_args + task :foo, [:x] do + # Dummy action + end + + task(:foo).clear_args + + task :foo + + assert_empty task(:foo).arg_names + end + def test_find task :tfind assert_equal "tfind", Task[:tfind].name