Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#156 Remove arguments on clear #157

Merged
merged 1 commit into from
Aug 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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