Attribute Macro stubr_attributes::record

source ·
#[record]
Expand description

Starts a Stubr recorder server and creates a recorder variable which can be used to call the server e.g. stubr.isahc_client().

Example

use asserhttp::*; // optional

#[test]
#[stubr::mock] // <- start a server to record, stubr itself for example
#[stubr::record] // <- spawns a recorder in a tokio runtime
fn simple_test() {
    recorder.isahc_client().get(stubr.uri()).expect_status_ok();
    // a recorded stub has been created under 'target/stubs'
}

// Works for async too
#[stubr::record] // <- spawns a recorder in a tokio runtime
#[stubr::mock] // <- start a server to record, stubr itself for example
#[test]
async fn async_simple_test() {
    recorder.isahc_client().get_async(stubr.uri()).await.expect_status_ok();
}

Configuration


// start recorder on a dedicated port
#[test]
#[stubr::record(port = 1234)]
fn port() {}