deprecated mockiato

A strict, yet friendly mocking library for Rust 2018

19 releases

0.9.6 May 31, 2024
0.9.5 Oct 12, 2019
0.9.3 Sep 30, 2019
0.9.0 Jul 12, 2019
0.3.0 Mar 22, 2019
Download history 52/week @ 2024-07-21 68/week @ 2024-07-28 49/week @ 2024-08-04 54/week @ 2024-08-11 47/week @ 2024-08-18 41/week @ 2024-08-25 46/week @ 2024-09-01 46/week @ 2024-09-08 49/week @ 2024-09-15 125/week @ 2024-09-22 57/week @ 2024-09-29 51/week @ 2024-10-06 52/week @ 2024-10-13 48/week @ 2024-10-20 44/week @ 2024-10-27 52/week @ 2024-11-03

205 downloads per month
Used in myelin-engine

MIT license

79KB
2K SLoC

Mockiato

[!WARNING] Mockiato is no longer maintained and thus the repository has been archived.

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.

Docs

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

~2MB
~42K SLoC