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

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

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::{collector, expect};

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

tracing::collect::with_default(collector, || {
    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::{collector, expect};

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

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

handle.assert_finished();