11 releases

Uses new Rust 2021

0.5.0-rc.1 Apr 14, 2022
0.4.14 Feb 22, 2022
0.4.13 Jan 12, 2022
0.4.12 Dec 20, 2021
0.4.8 Jul 20, 2021

#4 in #contract

Download history 12/week @ 2022-04-20 111/week @ 2022-04-27 82/week @ 2022-05-04 184/week @ 2022-05-11 67/week @ 2022-05-18 80/week @ 2022-05-25 111/week @ 2022-06-01 60/week @ 2022-06-08 70/week @ 2022-06-15 34/week @ 2022-06-22 69/week @ 2022-06-29 17/week @ 2022-07-06 55/week @ 2022-07-13 85/week @ 2022-07-20 56/week @ 2022-07-27 45/week @ 2022-08-03

248 downloads per month
Used in stubr

Apache-2.0

28KB
569 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 stubr_attributes as stubr;
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 stubr_attributes as stubr;
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'
}

#[stubr::apps]

Starts a Stubr server for each remote app name supplied.
Those remote apps' stubs are imported by stubr-build and will help you test your app's dependencies over other apps/microservices using http.

# use stubr_attributes as stubr;
use isahc;
use asserhttp::*; // optional

#[test]
#[stubr::apps("producer-a", "producer-b")] // <- start a server for each app
fn using_producers() {
    // a binding is created for each app supplied with the name of the app
    isahc::get(producer_a.uri()).expect_status_ok();
    isahc::get(producer_b.uri()).expect_status_ok();
}

Dependencies

~0.5–1MB
~21K SLoC