A strict, yet friendly mocking library for Rust 2018

Overview

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
You might also like...
A Rust library for calculating sun positions

sun A rust port of the JS library suncalc. Install Add the following to your Cargo.toml [dependencies] sun = "0.2" Usage pub fn main() { let unixti

A cross-platform serial port library in Rust.

Introduction serialport-rs is a general-purpose cross-platform serial port library for Rust. It provides a blocking I/O interface and port enumeration

A high level diffing library for rust based on diffs
A high level diffing library for rust based on diffs

Similar: A Diffing Library Similar is a dependency free crate for Rust that implements different diffing algorithms and high level interfaces for it.

A reactive DOM library for Rust in WASM

maple A VDOM-less web library with fine-grained reactivity. Getting started The recommended build tool is Trunk. Start by adding maple-core to your Ca

transmute-free Rust library to work with the Arrow format

Arrow2: Transmute-free Arrow This repository contains a Rust library to work with the Arrow format. It is a re-write of the official Arrow crate using

Cross-platform Window library in Rust for Tauri. [WIP]

Cross-platform application window creation library in Rust that supports all major platforms like Windows, macOS, Linux, iOS and Android. Built for you, maintained for Tauri.

A library in Rust for theorem proving with Intuitionistic Propositional Logic.

Prop Propositional logic with types in Rust. A library in Rust for theorem proving with Intuitionistic Propositional Logic. Supports theorem proving i

A Rust library for constructing tilings of regular polygons
A Rust library for constructing tilings of regular polygons

tiling tiling is a library for constructing tilings of regular polygons and their dual tilings. Resources Documentation Tilings by regular polygons Li

miette is a diagnostic library for Rust. It includes a series of traits/protocols that allow you to hook into its error reporting facilities, and even write your own error reports!
miette is a diagnostic library for Rust. It includes a series of traits/protocols that allow you to hook into its error reporting facilities, and even write your own error reports!

miette is a diagnostic library for Rust. It includes a series of traits/protocols that allow you to hook into its error reporting facilities, and even write your own error reports!

Comments
  • Support mocking foreign-defined traits

    Support mocking foreign-defined traits

    Seems pretty easy-- probably just an extra annotation to indicate that the trait definition itself should be omitted from the generated code, and only the mocks should be kept.

    effort-13 feature 
    opened by cramertj 6
  • Release 0.4.0

    Release 0.4.0

    Prepare the release

    • [x] Bump the version numbers
    • [x] Update dependency versions for neighbouring crates
    • [x] Create a pull request

    Perform the release

    • [x] Merge the pull request
    • [x] Run cargo publish
    • [x] Tag the merge commit (e.g. '0.1.2')
    opened by jeremystucki 1
  • Make mocks cloneable

    Make mocks cloneable

    We should make mocks cloneable to allow traits like the following to be mocked.

     pub trait Greeter: GreeterClone {
        fn greeter(&self, name: &str) -> String;
     }
    
     pub trait GreeterClone {
         fn clone_box(&self) -> Box<dyn Greeter>;
     }
    
     impl<T> GreeterClone for T
     where
         T: Greeter + Clone + 'static,
     {
         default fn clone_box(&self) -> Box<dyn Greeter> {
             Box::new(self.clone())
         }
     }
    

    It might make sense to put everything in the mock inside an Rc. This would mean that the method calls of the cloned instances are shared and are verified only once the last instance is dropped.

    enhancement effort-5 
    opened by bash 1
  • Allow references to generics

    Allow references to generics

    The current implementation of generics on traits (PR #118) explicitly disallows this due to issues with the generic type parameter outliving the reference.

    The current Arguments / ArgumentsMatcher setup doesn't allow this as far as I can tell, so we might need to rethink that.

    enhancement on hold 
    opened by bash 1
Releases(0.9.5)
Owner
Mockiato
A strict, yet friendly mocking library for Rust 2018
Mockiato
This library provides a stable polyfill for Rust's Strict Provenance experiment.

This library provides a stable polyfill for Rust's Strict Provenance experiment.

Aria Beingessner 57 Nov 15, 2022
Watches changes in a rust project, runs test and shows friendly notification

Cargo testify Automatically runs tests on your Rust project and notifies about the result. Install Install prerequisites (for Debian/Ubuntu): apt-get

Sergey Potapov 77 May 16, 2022
🐦 Friendly little instrumentation profiler for Rust 🦀

?? puffin The friendly little instrumentation profiler for Rust How to use fn my_function() { puffin::profile_function!(); ... if ... {

Embark 848 Dec 29, 2022
Rust Util Collection, a simple and friendly error-chain

RUC Rust Util Collection, a simple and friendly error-chain, with many useful utils as an addition. The painful experience of using error-chain gave b

漢 8 Dec 8, 2022
Rust Util Collection, a simple and friendly error-chain, with many useful utils as an addition.

RUC Rust Util Collection, a simple and friendly error-chain, with many useful utils as an addition. The painful experience of using error-chain gave b

漢 6 Mar 27, 2022
Minimal, flexible & user-friendly X and Wayland tiling window manager with rust

SSWM Minimal, flexible & user-friendly X and Wayland tiling window manager but with rust. Feel free to open issues and make pull requests. [Overview]

Linus Walker 19 Aug 28, 2023
Byte is a blazingly fast🚀 Discord Bot with a user-friendly design using twilight written in rust🦀.

Byte Byte is a blazingly fast?? Discord Bot with a user-friendly design using twilight written in rust??. How To Run There is a public version of the

TakoTheDev 3 Nov 15, 2023
Yet another geter/setter derive macro.

Gusket Gusket is a getter/setter derive macro. Comparison with getset: gusket only exposes one derive macro. No need to derive(Getters, MutGetters, Se

Jonathan Chan Kwan Yin 2 Apr 12, 2022
dbt Cloud™️ infrastructure-as-code that is friendly to analysts

dbterra dbt Cloud ™️ infrastructure-as-code that is friendly to analysts, bizops, etc Motivation While there are Terraform ™️ plugins that can be used

Instawork 6 May 2, 2023
A library to compile USDT probes into a Rust library

sonde sonde is a library to compile USDT probes into a Rust library, and to generate a friendly Rust idiomatic API around it. Userland Statically Defi

Ivan Enderlin 40 Jan 7, 2023