def assert_throw(expected_object, message="", &proc)
_wrap_assertion do
begin
catch([]) {}
rescue TypeError
assert_instance_of(Symbol, expected_object,
"assert_throws expects the symbol that should be thrown for its first argument")
end
assert_block("Should have passed a block to assert_throw.") do
block_given?
end
caught = true
begin
catch(expected_object) do
proc.call
caught = false
end
full_message = build_message(message,
"<?> should have been thrown.",
expected_object)
assert_block(full_message) {caught}
rescue NameError, ArgumentError, ThreadError => error
raise unless UncaughtThrow[error.class] =~ error.message
tag = $1
tag = tag[1..-1].intern if tag[0, 1] == ":"
full_message = build_message(message,
"<?> expected to be thrown but\n" +
"<?> was thrown.",
expected_object, tag)
flunk(full_message)
end
end
end