9 releases

Uses new Rust 2021

new 0.4.13 Jan 12, 2022
0.4.12 Dec 20, 2021
0.4.11 Nov 23, 2021
0.4.10 Oct 27, 2021
0.4.5 Jun 20, 2021

#5 in #contract

Download history 6/week @ 2021-09-27 10/week @ 2021-10-04 14/week @ 2021-10-11 3/week @ 2021-10-18 26/week @ 2021-10-25 14/week @ 2021-11-01 7/week @ 2021-11-08 4/week @ 2021-11-15 29/week @ 2021-11-22 23/week @ 2021-11-29 6/week @ 2021-12-06 7/week @ 2021-12-13 26/week @ 2021-12-20 11/week @ 2021-12-27 13/week @ 2022-01-03 42/week @ 2022-01-10

92 downloads per month
Used in stubr

Apache-2.0

26KB
571 lines

stubr-attributes

Macros for stubr


#[stubr::mock]

Starts a Stubr mock server and creates a stubr variable which can be used to call the server e.g. stubr.uri(). It supports both standard and async test functions.

use isahc;
use asserhttp::*; // optional

#[test]
#[stubr::mock] // <- takes stubs under crate's "tests/stubs" by default
fn simple_test() {
    isahc::get(stubr.uri()).expect_status_ok();
}

#[stubr::record]

Can also be used for recording with #[stubr::record]. It will spawn a standalone proxy which will record all http exchanges.
A recorder variable is created so that you can interact with the proxy. You then need to configure your http client to use this proxy. With record-isahc or record-reqwest features you can get an http client configured to hit the recorder proxy. It supports both standard and async test functions.

use isahc;
use asserhttp::*; // optional

#[stubr::mock]
#[stubr::record] // <- takes stubs under crate's "tests/stubs" by default
#[test]
fn simple_test() {
    recorder.isahc_client().get(stubr.uri()).expect_status_ok();
    // a recorded stub has been created under 'target/stubs'
}

Dependencies

~0.6–1MB
~24K SLoC