{"id":33928931,"url":"https://github.com/pcsm/simulacrum","last_synced_at":"2026-03-17T20:03:11.693Z","repository":{"id":57667494,"uuid":"114521070","full_name":"pcsm/simulacrum","owner":"pcsm","description":"A small library for creating mock objects in Rust.","archived":false,"fork":false,"pushed_at":"2019-08-08T17:23:11.000Z","size":204,"stargazers_count":27,"open_issues_count":33,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-14T23:17:28.022Z","etag":null,"topics":["rust","rust-library"],"latest_commit_sha":null,"homepage":null,"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/pcsm.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":"2017-12-17T08:27:29.000Z","updated_at":"2025-10-19T02:40:01.000Z","dependencies_parsed_at":"2022-09-26T20:31:55.229Z","dependency_job_id":null,"html_url":"https://github.com/pcsm/simulacrum","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/pcsm/simulacrum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcsm%2Fsimulacrum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcsm%2Fsimulacrum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcsm%2Fsimulacrum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcsm%2Fsimulacrum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pcsm","download_url":"https://codeload.github.com/pcsm/simulacrum/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcsm%2Fsimulacrum/sbom","scorecard":{"id":725300,"data":{"date":"2025-08-11","repo":{"name":"github.com/pcsm/simulacrum","commit":"13416e94e6db264d607b00de634f13f8acddcc78"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":1,"reason":"Found 3/28 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 5 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-22T12:36:38.850Z","repository_id":57667494,"created_at":"2025-08-22T12:36:38.850Z","updated_at":"2025-08-22T12:36:38.850Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30630031,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T17:32:55.572Z","status":"ssl_error","status_checked_at":"2026-03-17T17:32:38.732Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["rust","rust-library"],"created_at":"2025-12-12T11:54:18.215Z","updated_at":"2026-03-17T20:03:11.688Z","avatar_url":"https://github.com/pcsm.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Simulacrum [![Docs](https://docs.rs/simulacrum/badge.svg)](https://docs.rs/simulacrum) [![Crates.io](https://img.shields.io/crates/v/simulacrum.svg)](https://crates.io/crates/simulacrum)\n==================================================================\n\nA minimal library for creating mock objects by hand using stable Rust.\n\nTo install, add this line to your Cargo.toml:\n\n```toml\n[dependencies]\nsimulacrum = \"0.3.0\"\n```\n\nNote that this crate has not yet reached version 1.0, so the API may change drastically between releases.\n\n## Using Mock Objects\n\nSimulacrum mock objects provide a consistent interface that features call counts, parameter matching, return values, and modifying parameters by mutable reference.\n\n```rust\n// Create a mock object\nlet mut mock = CoolTraitMock::new();\n\n// Set up expectations for it\nmock.expect_foo()\n    .called_once();\nmock.then()\n    .expect_goop()\n    .called_once()\n    .with(true)\n    .returning(|_| 5);\n\n// Execute test code\nm.foo();\nassert_eq!(m.goop(true), 5);\n\n// When the mock object is dropped, its expectations will be evaluated\n```\n\nSee [`macros_high.rs`](https://github.com/pcsm/simulacrum/blob/master/simulacrum/examples/macros_high.rs) for a full run-through of the mock object user API.\n\n## Creating Mock Objects\n\nSimulacrum provides several APIs at different levels of abstraction, so you can create mock objects with the level of control you desire. All mock objects created with Simulacrum expose the same user API, no matter which API level is used to create them.\n\nThe following examples all show how to mock this trait:\n\n```rust\ntrait CoolTrait {\n    fn foo(\u0026self);\n    fn goop(\u0026mut self, flag: bool) -\u003e u32;\n    fn store(\u0026self, val: \u0026i64);\n}\n```\n\nNote that the macro API only supports creating mocks from a trait, while the manual API allows you to create mock objects to stand in for structs as well.\n\n### High-Level Macro Example\n\nThe `create_mock!` macro creates a mock object from a trait. Just copy over the trait's interface and annotate it:\n\n```rust\nextern crate simulacrum;\n\nuse simulacrum::*;\n\ncreate_mock! {\n    impl CoolTrait for CoolTraitMock (self) {\n        expect_foo(\"foo\"):\n        fn foo(\u0026self);\n\n        expect_goop(\"goop\"):\n        fn goop(\u0026mut self, flag: bool) -\u003e u32;\n\n        // \u0026 params are mocked as *const and \u0026mut are mocked as *mut.\n        expect_store(\"store\"):\n        fn store(\u0026self, val: \u0026i64);\n    }\n}\n```\n\nSee [`macros_high.rs`](https://github.com/pcsm/simulacrum/blob/master/simulacrum/examples/macros_high.rs) for more examples of how to mock out different types of methods with `create_mock!`.\n\n### Mid-Level Macros Example\n\nIf you need more control than the high-level macro offers, you can use the `create_mock_struct!` and `was_called!` macros. This is useful if you'd like to create mock objects with features that the high-level macro doesn't support, like generic methods. Note that you can mix-and-match these macros with the manual interface as well.\n\n```rust\nextern crate simulacrum;\n\nuse simulacrum::*;\n\ncreate_mock_struct! {\n    struct CoolTraitMock: {\n        expect_foo(\"foo\");\n        expect_goop(\"goop\") bool =\u003e u32;\n        // Note that we've used *const instead of \u0026 for shared references.\n        expect_store(\"store\") *const i64;\n    }\n}\n\nimpl CoolTrait for CoolTraitMock {\n    fn foo(\u0026self) {\n        was_called!(self, \"foo\")\n    }\n\n    fn goop(\u0026mut self, flag: bool) -\u003e u32 {\n        was_called!(self, \"goop\", (flag: bool) -\u003e u32)\n    }\n\n    fn store(\u0026self, val: \u0026i64) {\n        // Again note the use of *const instead of \u0026 for shared references.\n        was_called!(self, \"store\", (val: *const i64))\n    }\n}\n\n```\n\nSee [`macros_mid.rs`](https://github.com/pcsm/simulacrum/blob/master/simulacrum/examples/macros_mid.rs) for more examples of how to mock out different types of methods with the Mid-Level Macros.\n\n## Manual Example\n\nCreate your mock objects manually for ultimate control. With this API, you can even create mocks to stand in for structs instead of traits. For a detailed example of the API, see the [`manual.rs`](https://github.com/pcsm/simulacrum/blob/master/simulacrum/examples/manual.rs) example.\n\n```rust\nextern crate simulacrum;\n\nuse simulacrum::*;\n\ntrait CoolTrait {\n    fn foo(\u0026self);\n    fn goop(\u0026mut self, flag: bool) -\u003e u32;\n}\n\npub struct CoolTraitMock {\n    e: Expectations\n}\n\nimpl CoolTraitMock {\n    pub fn new() -\u003e Self {\n        Self {\n            e: Expectations::new()\n        }\n    }\n\n    pub fn then(\u0026mut self) -\u003e \u0026mut Self {\n        self.e.then();\n        self\n    }\n\n    pub fn expect_foo(\u0026mut self) -\u003e Method\u003c(), ()\u003e {\n        self.e.expect::\u003c(), ()\u003e(\"foo\")\n    }\n\n    pub fn expect_goop(\u0026mut self) -\u003e Method\u003cbool, u32\u003e {\n        self.e.expect::\u003cbool, u32\u003e(\"goop\")\n    }\n}\n\nimpl CoolTrait for CoolTraitMock {\n    fn foo(\u0026self) {\n        self.e.was_called::\u003c(), ()\u003e(\"foo\", ())\n    }\n\n    fn goop(\u0026mut self, flag: bool) -\u003e u32 {\n        self.e.was_called_returning::\u003cbool, u32\u003e(\"goop\", flag)\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcsm%2Fsimulacrum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpcsm%2Fsimulacrum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcsm%2Fsimulacrum/lists"}