method

assert_raise_with_message

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 (v2_1_10) is shown here.

assert_raise_with_message(exception, expected, msg = nil, &block)
public

Tests if the given block raises an exception with the expected message.

assert_raise_with_message(RuntimeError, "foo") do
  nil #Fails, no Exceptions are raised
end

assert_raise_with_message(RuntimeError, "foo") do
  raise ArgumentError, "foo" #Fails, different Exception is raised
end

assert_raise_with_message(RuntimeError, "foo") do
  raise "bar" #Fails, RuntimeError is raised but the message differs
end

assert_raise_with_message(RuntimeError, "foo") do
  raise "foo" #Raises RuntimeError with the message, so assertion succeeds
end