stubr-attributes

Macros for stubr


docs.rs docs coverage


#[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.

```rust, no_run

use stubr_attributes as stubr;

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

[test]

[stubr::mock] // <- takes stubs under crate's "tests/stubs" by default

fn simpletest() { isahc::get(stubr.uri()).expectstatus_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.

```rust, no_run

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 simpletest() { recorder.isahcclient().get(stubr.uri()).expectstatusok(); // 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.

```rust, no_run

use stubr_attributes as stubr;

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

[test]

[stubr::apps("producer-a", "producer-b")] // <- start a server for each app

fn usingproducers() { // a binding is created for each app supplied with the name of the app isahc::get(producera.uri()).expectstatusok(); isahc::get(producerb.uri()).expectstatus_ok(); } ```