{"id":13503159,"url":"https://github.com/kriomant/mockers","last_synced_at":"2025-03-29T13:30:55.066Z","repository":{"id":57639636,"uuid":"55594397","full_name":"kriomant/mockers","owner":"kriomant","description":"Mocking library for Rust","archived":false,"fork":false,"pushed_at":"2022-10-25T16:00:11.000Z","size":541,"stargazers_count":269,"open_issues_count":6,"forks_count":16,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-31T22:34:27.377Z","etag":null,"topics":["mock-library","rust","testing"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kriomant.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-06T09:47:24.000Z","updated_at":"2024-09-15T20:36:01.000Z","dependencies_parsed_at":"2022-08-27T19:51:38.980Z","dependency_job_id":null,"html_url":"https://github.com/kriomant/mockers","commit_stats":null,"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriomant%2Fmockers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriomant%2Fmockers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriomant%2Fmockers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriomant%2Fmockers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kriomant","download_url":"https://codeload.github.com/kriomant/mockers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246190251,"owners_count":20738000,"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-library","rust","testing"],"created_at":"2024-07-31T22:02:39.499Z","updated_at":"2025-03-29T13:30:54.666Z","avatar_url":"https://github.com/kriomant.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"\n| master | 0.22.0 |\n| ------ | ----- |\n| [![Build Status](https://travis-ci.org/kriomant/mockers.svg?branch=master)](https://travis-ci.org/kriomant/mockers) [![Coverage Status](https://coveralls.io/repos/github/kriomant/mockers/badge.svg?branch=master)](https://coveralls.io/github/kriomant/mockers?branch=master) | [![Build Status](https://travis-ci.org/kriomant/mockers.svg?branch=0.22.0)](https://travis-ci.org/kriomant/mockers) |\n\n\n\n# Mockers\n\nMocking library for Rust. Both stable and nightly Rust are supported.\n\nInspired by Google Mock library for C++.\n\n**Warning**: There are breaking changes in 0.22.0 release, read What's New for details.\n\n[What's New]\n[User Guide]\n\n## Limitations \nFor now it is not a full-featured mocking library, but just\na prototype to gather feedback. For example, only methods with\nfour or fewer arguments are supported, non-'static lifetimes are not\nsupported and so on.\n\nFeatures are added on demand, so feel free to contact me and explain your\nneeds.\n\n## Usage at a glance\n\nThis is a very short introduction to show what is possible and\nhow it looks. Read [User Guide] for details.\n\nWe will use nightly Rust in this example for simplicity.\n\nFor multirust, run the following command:\n```\n$ multirust override nightly\n```\n\nOr if you're using rustup:\n\n```\n$ rustup override set nightly\n```\n\nCargo.toml:\n\n```toml\n[dev-dependencies]\nmockers = \"0.22.0\"\nmockers_derive = \"0.22.0\"\n```\n\nsrc/lib.rs:\n\n```rust\n#![feature(use_extern_macros)]\n\n#[cfg(test)] extern crate mockers_derive;\n\n#[cfg(test)] use mockers_derive::mocked;\n\n#[cfg_attr(test, mocked)]\npub trait AirConditioner {\n    fn make_hotter(\u0026mut self, by: i16);\n    fn make_cooler(\u0026mut self, by: i16);\n    fn get_temperature(\u0026self) -\u003e i16;\n}\n\npub fn set_temperature_20(cond: \u0026mut AirConditioner) {\n    let t = cond.get_temperature();\n    if t \u003c 20 {\n        cond.make_hotter(20 + t);\n    } else {\n        cond.make_cooler(t - 20);\n    }\n}\n\n#[cfg(test)]\nmod test {\n  use super::*;\n  use mockers::Scenario;\n\n  #[test]\n  fn test_set_temperature_20() {\n      let scenario = Scenario::new();\n      let (mut cond, cond_handle) = scenario.create_mock_for::\u003cAirConditioner\u003e();\n\n      scenario.expect(cond_handle.get_temperature().and_return(16));\n      scenario.expect(cond_handle.make_hotter(4).and_return(()));\n\n      set_temperature_20(\u0026mut cond);\n  }\n}\n```\n\nAnd if you're using `2018` edition:\n\n```rust\n#[cfg(test)] use mockers_derive::mocked;\n\n#[cfg_attr(test, mocked)]\npub trait AirConditioner {\n    fn make_hotter(\u0026mut self, by: i16);\n    fn make_cooler(\u0026mut self, by: i16);\n    fn get_temperature(\u0026self) -\u003e i16;\n}\n```\n\nRun tests:\n\n```\n$ cargo test\n   Compiling air v0.1.0 (file:///Users/kriomant/Temp/air)\n     Running target/debug/air-b2c5f8b6920cb30a\n\nrunning 1 test\ntest test::test_set_temperature_20 ... FAILED\n\nfailures:\n\n---- test::test_set_temperature_20 stdout ----\n\tthread 'test::test_set_temperature_20' panicked at '\n\nerror: unexpected call to `AirConditioner#0.make_hotter(36)`\n\nnote: here are active expectations for AirConditioner#0.make_hotter\n\n  expectation `AirConditioner#0.make_hotter(4)`:\n    arg #0: 36 is not equal to 4\n\n'\nnote: Run with `RUST_BACKTRACE=1` for a backtrace.\n\n\nfailures:\n    test::test_set_temperature_20\n\ntest result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured\n\nerror: test failed\n```\n\n## License\n\nCopyright © 2016 Mikhail Trishchenkov\n\nDistributed under the [MIT License](LICENSE).\n\n[User Guide]: doc/guide.md\n[What's New]: doc/whats-new.md\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkriomant%2Fmockers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkriomant%2Fmockers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkriomant%2Fmockers/lists"}