Google

"DTD/xhtml1-strict.dtd">
Module Test::Unit::Assertions
In: test/unit/assertions.rb

Contains all of the standard Test::Unit assertions. Mixed in to Test::Unit::TestCase. To mix it in and use its functionality, you simply need to rescue Test::Unit::AssertionFailedError, and you can additionally override add_assertion to be notified whenever an assertion is made.

Notes:

  • The message to each assertion, if given, will be propagated with the failure.
  • It's easy to add your own assertions based on assert_block().
Methods
Public Instance methods
assert_block(message="") {|| ...}

The assertion upon which all other assertions are based. Passes if the block yields true.

assert(boolean, message="")

Passes if boolean is true.

assert_equal(expected, actual, message=nil)

Passes if expected == actual. Note that the ordering of arguments is important, since a helpful error message is generated when this one fails that tells you the values of expected and actual.

assert_raises(expected_exception_klass, message="") {|| ...}

Passes if block raises exception.

assert_instance_of(klass, object, message="")

Passes if object.class == klass.

assert_nil(object, message="")

Passes if object.nil?.

assert_kind_of(klass, object, message="")

Passes if object.kind_of?(klass).

assert_respond_to(object, method, message="")

Passes if object.respond_to?(method) is true.

assert_match(regexp, string, message="")

Passes if string =~ regularExpression.

assert_same(expected, actual, message="")

Passes if actual.equal?(expected) (i.e. they are the same instance).

assert_operator(object1, operator, object2, message="")

Compares the two objects based on the passed operator. Passes if object1.send(operator, object2) is true.

assert_nothing_raised(*args) {|| ...}

Passes if block does not raise an exception.

flunk(message="")

Always fails.

assert_not_same(expected, actual, message="")

Passes if !actual.equal?(expected).

assert_not_equal(expected, actual, message="")

Passes if expected != actual.

assert_not_nil(object, message="")

Passes if !object.nil?.

assert_no_match(regexp, string, message="")

Passes if string !~ regularExpression.

assert_throws(expected_symbol, message="", &proc)

Passes if block throws symbol.

assert_nothing_thrown(message="", &proc)

Passes if block does not throw anything.

assert_in_delta(expected_float, actual_float, delta, message="")

Passes if expected_float and actual_float are equal within delta tolerance.

assert_send(send_array, message="")

Passes if the method sent returns a true value.

Private Instance methods
add_assertion()

Called whenever an assertion is made.