tracing_mock::expect

Function event

Source
pub fn event() -> ExpectedEvent
Expand description

Create a new ExpectedEvent.

For details on how to add additional assertions to the expected event, see the event module and the ExpectedEvent struct.

§Examples

use tracing_mock::{expect, subscriber};

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

tracing::subscriber::with_default(subscriber, || {
    tracing::info!(field.name = "field_value");
});

handle.assert_finished();

If we expect an event and instead record something else, the test will fail:

use tracing_mock::{expect, subscriber};

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

tracing::subscriber::with_default(subscriber, || {
    let span = tracing::info_span!("span");
    let _guard = span.enter();
});

handle.assert_finished();