Skip to content

Commit

Permalink
task args are now passed as block parameters
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/rake/trunk@589 5af023f1-ac1a-0410-98d6-829a145c37ef
  • Loading branch information
jimweirich committed Apr 28, 2007
1 parent 8b42242 commit 925fbb8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,16 @@ def execute
puts "** Execute #{name}"
end
application.enhance_with_matching_rule(name) if @actions.empty?
@actions.each { |act| result = act.call(self) }
@actions.each { |act|
case act.arity
when 0
act.call
when 1
act.call(self)
else
act.call(self, *args)
end
}
end

# Is this task needed?
Expand Down
56 changes: 56 additions & 0 deletions test/test_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,62 @@ def test_tasks_can_access_arguments
t.args = [1, 2, 3]
t.invoke
end

def test_arguments_are_passed_to_block
t = intern(:t).enhance { |t, a|
assert_equal 1, a
}
t.args = [1]
t.invoke
end

def test_extra_arguments_are_ignored
t = intern(:t).enhance { |t, a|
assert_equal 1, a
}
t.args = [1, 2]
t.invoke
end

def test_extra_parameters_are_nil
t = intern(:t).enhance { |t, a, b, c|
assert_equal 1, a
assert_equal 2, b
assert_nil c
}
t.args = [1, 2]
t.invoke
end

def test_extra_arguments_can_be_splat_captured
t = intern(:t).enhance { |t, a, *b|
assert_equal 1, a
assert_equal [2, 3], b
}
t.args = [1, 2, 3]
t.invoke
end

def test_arguments_are_passed_to_all_blocks
counter = 0
t = intern(:t).enhance { |t, a|
assert_equal 1, a
counter += 1
}
intern(:t).enhance { |t, a|
assert_equal 1, a
counter += 1
}
t.args = [1]
t.invoke
assert_equal 2, counter
end

def test_block_with_no_parameters_is_ok
t = intern(:t).enhance { }
t.args = [1,2]
t.invoke
end

private

Expand Down

0 comments on commit 925fbb8

Please sign in to comment.