Skip to content

Commit

Permalink
Merge pull request #157 from jessebs/master
Browse files Browse the repository at this point in the history
#156 Remove arguments on clear
  • Loading branch information
hsbt authored Aug 26, 2016
2 parents 111f295 + 0f0a870 commit c3fbc13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/rake/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion test/test_rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c3fbc13

Please sign in to comment.