tracing_mock::expect

Function span

Source
pub fn span() -> ExpectedSpan
Expand description

Construct a new ExpectedSpan.

For details on how to add additional assertions to the expected span, see the span module and the ExpectedSpan and NewSpan structs.

§Examples

use tracing_mock::{expect, subscriber};

let (subscriber, handle) = subscriber::mock()
    .new_span(expect::span())
    .enter(expect::span())
    .run_with_handle();

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

handle.assert_finished();

If we expect to enter a span and instead record something else, the test will fail:

use tracing_mock::{expect, subscriber};

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

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

handle.assert_finished();