Trait AssertHasError

Source
pub trait AssertHasError<E> {
    // Required method
    fn has_error(self, expected: E) -> Self;
}
Expand description

Assert that a subject of some container type holds an error value that is equal to the expected one.

This assertion is implemented for the Result type. It compares the value in Err(value) with the expected one. The error type in the Result must implement PartialEq<E> where E is the type of the expected error value.

To assert the ok value of a Result use AssertHasValue::has_value.

§Examples

use asserting::prelude::*;

let subject: Result<(), String> = Err("labore gubergren ut ipsum".to_string());
assert_that!(subject).has_error("labore gubergren ut ipsum");

Required Methods§

Source

fn has_error(self, expected: E) -> Self

Verifies that the subject holds an error value that is equal to the expected one.

For Result it compares the value in Err(value). If the Result holds an Ok(value), the assertion fails.

§Examples
use asserting::prelude::*;

let subject: Result<(), String> = Err("labore gubergren ut ipsum".to_string());
assert_that!(subject).has_error("labore gubergren ut ipsum");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T, E, X, R> AssertHasError<X> for Spec<'_, Result<T, E>, R>
where T: Debug, E: PartialEq<X> + Debug, X: Debug, R: FailingStrategy,