diff --git a/lib/rake.rb b/lib/rake.rb index e8f380415..987d64dde 100755 --- a/lib/rake.rb +++ b/lib/rake.rb @@ -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? diff --git a/test/test_tasks.rb b/test/test_tasks.rb index 698211591..21f341b30 100644 --- a/test/test_tasks.rb +++ b/test/test_tasks.rb @@ -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