8 releases

Uses new Rust 2021

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

#5 in #contract

Download history 4/week @ 2022-03-03 1/week @ 2022-03-10 44/week @ 2022-03-17 7/week @ 2022-04-07 24/week @ 2022-04-14 2/week @ 2022-04-21 73/week @ 2022-04-28 55/week @ 2022-05-05 129/week @ 2022-05-12 34/week @ 2022-05-19 30/week @ 2022-05-26 65/week @ 2022-06-02 2/week @ 2022-06-16

105 downloads per month


110 lines


Build plugin for consuming stubs

One of the key benefit of relying upon json files for stubbing your web applications is that they are both portable and language agnostic.
This crates aims at introducing a 'producer-driven' way of testing your applications: a producer (which exposes the API) publishes its mocks ; consumer(s) app(s) pull them and can use those stubs in their tests, configuring their http clients to hit them.

as a producer

Currently, you just have to place your stubs in a 'stubs' directory at crate root, something like this:

├── src
├── stubs
    ├── get.json
    └── post.json
└── Cargo.toml

If you have some include or exclude in your Cargo.toml make sure it does not involve the stubs directory.

as a consumer

In your Cargo.toml use stubr-build in your build-dependencies and also add your producer apps. You also need to invoke it in a build.rs file.

build = "build.rs"

stubr-build = "0.5.0-rc.1"
producer-a = "<version>"
producer-b = "<version>"

Then in your build.rs:

fn main() { stubr_build::stubr_consumer() }

In order to extract stubs (invoke the build script), cargo build has to be invoked. So think about executing it before tests in your CI or locally.

To mount those stubs in a server you can then use a macro

#[stubr::apps("producer-a", "producer-b")]
fn my_test() {
    // local bindings with the name of each producer are created

Or without macros

fn my_test() {
    let apps = Stubr::apps_blocking(&["producer-a", "producer-b"]);
    let (producer_a, producer_b) = (apps.get(0).unwrap(), apps.get(1).unwrap());


~1M SLoC