method
assert_raises
v1_9_3_125 -
Show latest stable
- Class:
MiniTest::Assertions
assert_raises(*exp)public
Fails unless the block raises one of exp
# File lib/minitest/unit.rb, line 325
def assert_raises *exp
msg = "#{exp.pop}\n" if String === exp.last
should_raise = false
begin
yield
should_raise = true
rescue MiniTest::Skip => e
details = "#{msg}#{mu_pp(exp)} exception expected, not"
if exp.include? MiniTest::Skip then
return e
else
raise e
end
rescue Exception => e
details = "#{msg}#{mu_pp(exp)} exception expected, not"
assert(exp.any? { |ex|
ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
}, exception_details(e, details))
return e
end
exp = exp.first if exp.size == 1
flunk "#{msg}#{mu_pp(exp)} expected but nothing was raised." if
should_raise
end Related methods
- Instance methods
- _assertions
- _assertions=
- assert
- assert_block
- assert_empty
- assert_equal
- assert_in_delta
- assert_in_epsilon
- assert_includes
- assert_instance_of
- assert_kind_of
- assert_match
- assert_nil
- assert_operator
- assert_output
- assert_raises
- assert_respond_to
- assert_same
- assert_send
- assert_silent
- assert_throws
- capture_io
- diff
- exception_details
- flunk
- message
- mu_pp
- mu_pp_for_diff
- pass
- refute
- refute_empty
- refute_equal
- refute_in_delta
- refute_in_epsilon
- refute_includes
- refute_instance_of
- refute_kind_of
- refute_match
- refute_nil
- refute_operator
- refute_respond_to
- refute_same
- skip
- Class methods
- diff
- diff=