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 => error
extractor = ThrowTagExtractor.new(error)
tag = extractor.extract_tag
raise if tag.nil?
full_message = build_message(message,
"<?> was expected to be thrown but\n" +
"<?> was thrown.",
expected_object, tag)
flunk(full_message)
end
end
end