Thursday, January 29, 2009

assert_yields

I got sick of writing longhand assertions around yields so I whipped up this little function:

  
def assert_yields(something_callable, arg)
yielded = false
something_callable.call(arg) do
yielded = true
end
assert yielded
end

# Called like:
assert_yields(some_obj.method(:do_something), my_arg)


One could easily make it handle a variable number of arguments.

No comments:

Post a Comment