module Test::Assertions
The assertions, for Test::Case and for a module of tests or helpers
that test classes include (module Sizes; include Test::Assertions).
<std:test>:24
Methods
def add_assertion -> Void
Counts one assertion made: each assertion calls it once, and
Test::Case counts its test's.
<std:test>:27
def assert(value: Object?, message: String? = …) -> Void
Passes when value is truthy (neither nil nor false).
<std:test>:30
def refute(value: Object?, message: String? = …) -> Void
Passes when value is nil or false.
<std:test>:35
def assert_true(value: Bool, message: String? = …) -> Void
Passes when value is true.
<std:test>:40
def assert_false(value: Bool, message: String? = …) -> Void
Passes when value is false.
<std:test>:45
def assert_equal[T](expected: T, actual: T?, message: String? = …) -> Void
Passes when expected == actual. T is fixed by expected, so
actual must be of its type or nil (a failure, not a type error):
assert_equal(1, "1") does not compile. The failure shows both values'
inspect, with a line diff when either is a string of several lines.
class DocEqual_Test < Test::Case
def test_lookup
h = {"k" => 1}
assert_equal(1, h["k"]?)
assert_equal([1, 2], [2, 1].sort, "sorted")
end
end
<std:test>:63
def refute_equal[T](expected: T, actual: T?, message: String? = …) -> Void
Passes when expected != actual; typed as #assert_equal.
<std:test>:68
def assert_nil(value: Object?, message: String? = …) -> Void
Passes when value is nil.
<std:test>:73
def refute_nil(value: Object?, message: String? = …) -> Void
Passes when value is not nil.
<std:test>:78
def assert_same(expected: Object, actual: Object, message: String? = …) -> Void
Passes when expected and actual are the same object (equal?).
<std:test>:83
def assert_in_delta(expected: Float, actual: Float, delta: Float = …, message: String? = …) -> Void
Passes when actual is within delta of expected.
<std:test>:88
def assert_in_epsilon(expected: Float, actual: Float, epsilon: Float = …, message: String? = …) -> Void
Passes when actual is within a relative error epsilon of
expected: their difference is at most epsilon times the smaller of
the two in magnitude.
<std:test>:97
def assert_match(pattern: Regexp, actual: String, message: String? = …) -> Void
Passes when actual matches pattern.
<std:test>:105
def refute_match(pattern: Regexp, actual: String, message: String? = …) -> Void
Passes when actual does not match pattern.
<std:test>:110
def assert_includes[T](collection: Enumerable[T], element: T, message: String? = …) -> Void
Passes when collection includes element (include?).
<std:test>:115
def refute_includes[T](collection: Enumerable[T], element: T, message: String? = …) -> Void
Passes when collection does not include element.
<std:test>:122
def assert_empty(collection: Enumerable[Object], message: String? = …) -> Void
Passes when collection has no element.
<std:test>:129
def assert_empty(text: String, message: String? = …) -> Void
Passes when text is the empty string.
<std:test>:134
def refute_empty(collection: Enumerable[Object], message: String? = …) -> Void
Passes when collection has an element.
<std:test>:139
def refute_empty(text: String, message: String? = …) -> Void
Passes when text is not the empty string.
<std:test>:144
def assert_compare[T <: Comparable[T]](lhs: T, op: Symbol, rhs: T, message: String? = …) -> Void
Passes when lhs compares to rhs as op says: op is one of
:<, :<=, :>, :>= and :==, applied to lhs <=> rhs.
assert_compare(1, :<, 2) passes; a failure shows both values
(<3> <= <2> should be true.).
Raises
ArgumentError for another op (an error of the test, not a
failure).
<std:test>:158
def assert_raise(klass: Type[Object], message: String? = …, &: () -> Void) -> Exception
The exception the block raises, an instance of klass or of a
subclass (with message, its message too).
<std:test>:173
def assert_raise_message(pattern: Regexp | String, &: () -> Void) -> Exception
The exception the block raises, whose message matches (or equals) pattern.
<std:test>:203
def assert_nothing_raised(message: String? = …, &: () -> Void) -> Void
Passes when the block raises nothing; an exception it raises is a failure (not an error), with its class and message.
<std:test>:231
def flunk(message: String = …) -> Nothing
Fails the test, with message.
<std:test>:250
def pend(message: String = …) -> Nothing
The test is pending: it ends here, counted as pending.
<std:test>:256
def pend(message: String = …, &: () -> Void) -> Void
The block is known to fail: pending when it does, a failure when it passes (the test can be un-pended).
<std:test>:262
def omit(message: String = …) -> Nothing
The test does not apply here: it ends, counted as omitted.
<std:test>:279
def omit_if(condition: Bool, message: String = …) -> Void
Omits the test (as #omit) when condition is true.
class DocOmit_Test < Test::Case
def test_unix_only
omit_if(File::SEPARATOR != "/", "needs a POSIX path")
assert_equal("a/b", File.join("a", "b"))
end
end
<std:test>:293
def omit_unless(condition: Bool, message: String = …) -> Void
Omits the test (as #omit) unless condition is true.
<std:test>:299
def check(ok: Bool, message: String?, &: () -> String) -> Void
Counts an assertion, and fails the test unless ok is true: the
failure's message is message (when given) followed by the block's
text, which the block builds only then.
The building block of the assertions, for assertions of one's own:
check(n.even?, msg) { "<#{n}> is not even." }.
<std:test>:311
def fail_with(message: String?, detail: String) -> Nothing
Fails the test: raises Test::AssertionFailed with message (when
given) and detail. For assertions of one's own, which call
add_assertion first.
<std:test>:320