method
assert_throws
ruby latest stable - Class:
Test::Unit::Assertions
Method deprecated or moved
This method is deprecated or moved on the latest stable version. The last existing version (v1_8_7_330) is shown here.
assert_throws(expected_symbol, message="", &proc)public
# File lib/test/unit/assertions.rb, line 390
def assert_throws(expected_symbol, message="", &proc)
_wrap_assertion do
assert_instance_of(Symbol, expected_symbol, "assert_throws expects the symbol that should be thrown for its first argument")
assert_block("Should have passed a block to assert_throws."){block_given?}
caught = true
begin
catch(expected_symbol) do
proc.call
caught = false
end
full_message = build_message(message, "<?> should have been thrown.", expected_symbol)
assert_block(full_message){caught}
rescue NameError, ThreadError => error
if UncaughtThrow[error.class] !~ error.message
raise error
end
full_message = build_message(message, "<?> expected to be thrown but\n<?> was thrown.", expected_symbol, $1.intern)
flunk(full_message)
end
end
end Related methods
- Instance methods
- assert
- assert_block
- assert_equal
- assert_in_delta
- assert_instance_of
- assert_kind_of
- assert_match
- assert_nil
- assert_no_match
- assert_not_equal
- assert_not_nil
- assert_not_same
- assert_nothing_raised
- assert_nothing_thrown
- assert_operator
- assert_raise
- assert_raises
- assert_respond_to
- assert_same
- assert_send
- assert_throws
- build_message
- flunk
- Class methods
- use_pp=
- Private methods
-
_check_exception_class -
_expected_exception? -
_wrap_assertion -
add_assertion