Skip to main content

assert_that

Function assert_that 

Source
pub fn assert_that<T>(actual: &T) -> AssertThat<'_, T, Panic>
๐Ÿ‘ŽDeprecated since 0.4.4:

Use the assert_that!() macro or the fluent .must() / .verify() entry points instead.

Expand description

The main entrypoint into an assertion context for borrowed values.

Borrows the value, allowing it to be used after the assertion.

ยงExample Usage
use assertr::prelude::*;

// This will panic with a descriptive message and a pointer to the actual line of the assertion.
assert_that(&3).is_equal_to(4);

// This instead captures the assertion failure for later inspection.
let failures = assert_that(&3)
    .with_capture()
    .is_equal_to(4) // This will collect a failure instead of panicking.
    .capture_failures();

assert_that(&failures)
    .has_length(1)
    .contains("");