{"id":15648145,"url":"https://github.com/nathanielsimard/mock-it","last_synced_at":"2025-07-11T06:34:53.941Z","repository":{"id":30310375,"uuid":"124328453","full_name":"nathanielsimard/mock-it","owner":"nathanielsimard","description":"This library aims to make mocking reliable","archived":false,"fork":false,"pushed_at":"2022-10-18T14:49:32.000Z","size":81,"stargazers_count":42,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-14T05:46:06.464Z","etag":null,"topics":["mock","rust","testing"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nathanielsimard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-08T03:01:51.000Z","updated_at":"2024-10-18T07:03:32.000Z","dependencies_parsed_at":"2022-07-15T00:00:45.681Z","dependency_job_id":null,"html_url":"https://github.com/nathanielsimard/mock-it","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/nathanielsimard/mock-it","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielsimard%2Fmock-it","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielsimard%2Fmock-it/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielsimard%2Fmock-it/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielsimard%2Fmock-it/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathanielsimard","download_url":"https://codeload.github.com/nathanielsimard/mock-it/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielsimard%2Fmock-it/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264747724,"owners_count":23657891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mock","rust","testing"],"created_at":"2024-10-03T12:23:43.300Z","updated_at":"2025-07-11T06:34:53.914Z","avatar_url":"https://github.com/nathanielsimard.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv style=\"display: flex; justify-content: left; align-items: center;\"\u003e\n    \u003cimg src=\"./assets/mock-it.svg\" width=\"100px\" /\u003e\n    \u003ch1\u003emock-it\u003c/h1\u003e\n\u003c/div\u003e\n\n\u003cbr/\u003e\n\n[![Current Crates.io Version](https://img.shields.io/crates/v/mock-it.svg)](https://crates.io/crates/mock-it)\n\n\u003e Mock it, don't mock all 🙃\n\nOur goal is to enhance the DX behind mocking your depedencies when you test.\nIt lets you use a syntax closer to `given` `when` `then` instead of having to\nassert your `then` **BEFORE** you call your function.\n\n## Features\n\n* Intuitive usage 😌\n* Mock your traits 🦾\n* Configure your mocks 👷‍♀️\n* Separate configuration from assertion 🕵️‍♀️\n\n## Example\n\n``` rust\n#[cfg_attr(test, mock_it::mock_it)]\ntrait Nurse {\n    fn heal(\u0026self, pokemon: Pokemon) -\u003e Result\u003cPokemon, String\u003e;\n}\n\n#[derive(Debug, PartialEq, Clone)]\npub struct Pokemon {\n    hp: i32,\n}\n\nstruct PokemonCenter {\n    nurse: Box\u003cdyn Nurse\u003e,\n    pokemons: Vec\u003cPokemon\u003e,\n}\n\nimpl PokemonCenter {\n    pub fn accept(\u0026mut self, pokemon: Pokemon) {\n        self.pokemons.push(pokemon);\n    }\n\n    pub fn collect(\u0026mut self) -\u003e Result\u003cPokemon, String\u003e {\n        let pokemon = match self.pokemons.pop() {\n            Some(val) =\u003e val,\n            None =\u003e return Err(\"No pokemon\".to_string()),\n        };\n        self.nurse.heal(pokemon)\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n    use mock_it::{any, eq};\n\n    #[test]\n    fn can_heal_pokemon() {\n        // given\n        let pikachu_no_hp = Pokemon { hp: 0 };\n        let pikachu_full_hp = Pokemon { hp: 100 };\n\n        let nurse_joy = NurseMock::new();\n        nurse_joy.when_heal(eq(pikachu_no_hp.clone()))\n            .will_return(Ok(pikachu_full_hp.clone()));\n\n        let mut pokemon_center = PokemonCenter {\n            nurse: Box::new(nurse_joy.clone()),\n            pokemons: vec![],\n        };\n\n        // when\n        pokemon_center.accept(pikachu_no_hp);\n        let healed_pikachu = pokemon_center.collect().unwrap();\n\n        //then\n        assert_eq!(healed_pikachu, pikachu_full_hp);\n        assert!(nurse_joy.expect_heal(any()).times(1).called());\n    }\n}\n```\n[Further use cases](/examples)\n\n## Constraints\n\n* Trait inputs must implement both PartialEq and Clone\n* Trait ouput must implement Clone\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanielsimard%2Fmock-it","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathanielsimard%2Fmock-it","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanielsimard%2Fmock-it/lists"}