Using ruby-1.9.3…
I’ve read some of the canonical blog posts on the subject of blocks & Procs, but I don’t see why these two situations are different:
module TestHelpers
def bad_arg_helper(&scenario)
# this works fine, test passes (without the next line)
assert_raise ArgumentError, "wrong type of arguments, pass Fixnum or Range parameters", { Myclass.myfunc "bad" }
# even though the exception is correctly raised in myfunc, this assert does not see it and the test fails
assert_raise ArgumentError, "wrong type of arguments, pass Fixnum or Range parameters", scenario.call
end
end
class TestClass < Test::Unit::TestCase
include TestHelpers
def test_bad_args
bad_arg_helper { Myclass.myfunc "bad" }
end
end
How do you pass a block to a test helper in another module?
Please see the three variants in the code: