18 releases (8 breaking)

0.9.5 Oct 12, 2019
0.9.3 Sep 30, 2019
0.9.0 Jul 12, 2019
0.3.0 Mar 22, 2019

#46 in Testing

Download history 43/week @ 2020-12-25 87/week @ 2021-01-01 614/week @ 2021-01-08 226/week @ 2021-01-15 333/week @ 2021-01-22 446/week @ 2021-01-29 204/week @ 2021-02-05 227/week @ 2021-02-12 532/week @ 2021-02-19 639/week @ 2021-02-26 538/week @ 2021-03-05 916/week @ 2021-03-12 1183/week @ 2021-03-19 394/week @ 2021-03-26 322/week @ 2021-04-02 268/week @ 2021-04-09

1,335 downloads per month
Used in myelin-engine

MIT license

79KB
2K SLoC

Mockiato

Build Status Latest Version Documentation dependency status Changelog

A strict, yet friendly mocking library for Rust 2018

⚠️ Disclaimer for working with stable rust

Mockiato relies on the unstable proc_macro_diagnostics API to print helpful messages and the unstable specialization feature to be able to print expected calls.

Mocks work as expected on stable rust, but diagnostics are very limited.
We recommend re-running failing tests using nighly rust in order to pin-point the issue.

Quickstart

#[cfg(test)]
use mockiato::mockable;

#[cfg_attr(test, mockable)]
trait Greeter {
    fn greet(&self, name: &str) -> String;
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn greet_the_world() {
        let mut greeter = GreeterMock::new();

        greeter
            .expect_greet(|arg| arg.partial_eq("world"))
            .times(1..2)
            .returns(String::from("Hello world"));

        assert_eq!("Hello world", greeter.greet("world"));
    }
}

Trait Bounds

Trait bounds are currently not supported meaning that the supertraits will not be implemented for mocks.

The following traits are always implemented for mocks:

Downcasting

An example of how to use downcasting with mockiato can be found in the downcasting example.

Contributing

Enable debug impls in codegen

cargo test --features mockiato-codegen/debug-impls

Dependencies

~0.8–1.3MB
~26K SLoC