🛈 Note: This is pre-release documentation for the upcoming tracing 0.2.0 ecosystem.

For the release documentation, please see docs.rs, instead.

tracing_mock::expect

Function msg

Source
pub fn msg(message: impl Display) -> ExpectedField
Expand description

Construct a new message ExpectedField.

For details on how to set the value of the message field and how to expect multiple fields, see the field module and the ExpectedField and ExpectedFields structs.

This is equivalent to expect::field("message").with_value(message).

§Examples

use tracing_mock::{collector, expect};

let event = expect::event().with_fields(
    expect::msg("message"));

let (collector, handle) = collector::mock()
    .event(event)
    .run_with_handle();

tracing::collect::with_default(collector, || {
    tracing::info!("message");
});

handle.assert_finished();

A different message value will cause the test to fail:

use tracing_mock::{collector, expect};

let event = expect::event().with_fields(
    expect::msg("message"));

let (collector, handle) = collector::mock()
    .event(event)
    .run_with_handle();

tracing::collect::with_default(collector, || {
    tracing::info!("different message");
});

handle.assert_finished();