Skip to content

Commit

Permalink
task(name).clear clears description/comment
Browse files Browse the repository at this point in the history
The test_clear_comments test case is due to David Chelimsky
(#88).
  • Loading branch information
rctay committed Dec 12, 2011
1 parent 47c6d8a commit 82f3a6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/rake/task.rb
Expand Up @@ -123,6 +123,7 @@ def reenable
def clear
clear_prerequisites
clear_actions
clear_comments
self
end

Expand All @@ -138,6 +139,13 @@ def clear_actions
self
end

# Clear the existing comments on a rake task.
def clear_comments
@full_comment = nil
@comment = 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
16 changes: 16 additions & 0 deletions test/test_rake_task.rb
Expand Up @@ -104,10 +104,12 @@ def test_can_double_invoke_with_reenable
end

def test_clear
desc "a task"
t = task("t" => "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"
end

def test_clear_prerequisites
Expand All @@ -123,6 +125,20 @@ def test_clear_actions
assert t.actions.empty?, "actions should be empty"
end

def test_clear_comments
desc "the original foo"
task :foo do
end

task(:foo).clear_comments

desc "a slightly different foo"
task :foo do
end

assert_equal "a slightly different foo", task(:foo).comment
end

def test_find
task :tfind
assert_equal "tfind", Task[:tfind].name
Expand Down

0 comments on commit 82f3a6e

Please sign in to comment.