{"id":19311879,"url":"https://github.com/eisberg-labs/actix-actor-expect","last_synced_at":"2025-04-22T15:31:25.879Z","repository":{"id":43338929,"uuid":"380931237","full_name":"eisberg-labs/actix-actor-expect","owner":"eisberg-labs","description":"Utility for unit testing actix actors, extension for `Mocker`","archived":false,"fork":false,"pushed_at":"2023-04-20T20:51:19.000Z","size":24,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-31T11:53:06.216Z","etag":null,"topics":["actix","actor","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eisberg-labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-28T06:39:10.000Z","updated_at":"2023-11-02T00:26:10.000Z","dependencies_parsed_at":"2022-09-17T04:42:15.546Z","dependency_job_id":null,"html_url":"https://github.com/eisberg-labs/actix-actor-expect","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eisberg-labs%2Factix-actor-expect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eisberg-labs%2Factix-actor-expect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eisberg-labs%2Factix-actor-expect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eisberg-labs%2Factix-actor-expect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eisberg-labs","download_url":"https://codeload.github.com/eisberg-labs/actix-actor-expect/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223900372,"owners_count":17222028,"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":["actix","actor","unit-testing"],"created_at":"2024-11-10T00:31:03.038Z","updated_at":"2024-11-10T00:32:05.538Z","avatar_url":"https://github.com/eisberg-labs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Actix Actor Expect [![Continuous Integration](https://github.com/eisberg-labs/actix-actor-expect/actions/workflows/ci.yml/badge.svg)](https://github.com/eisberg-labs/actix-actor-expect/actions/workflows/ci.yml) [![cargo-badge][]][cargo] [![license-badge][]][license]\n\nUtility for unit testing actix actors, extension for `Mocker`. I wrote a blog post [Mocking Actix Actor without getting a gray hair](https://amarjanica.com/mocking-actix-actor-without-getting-a-gray-hair/) a\nwhile ago, you might find it useful.\n\n# Usage\nDependencies:\n\n```toml\n[dev-dependencies]\nactix-actor-expect = \"0.1.0\"\n```\n\nCode:\n```rust\n\n#[derive(Clone, Debug, PartialEq, Message)]\n#[rtype(result = \"Result\u003cString, Error\u003e\")]\npub enum TestActorCommand {\n    Hello,\n    Dunno,\n    Echo(String),\n}\n\n#[derive(Debug, Default)]\npub struct TestActor {}\n\nimpl Actor for TestActor {\n    type Context = Context\u003cSelf\u003e;\n}\n\nimpl Handler\u003cTestActorCommand\u003e for TestActor {\n    type Result = Result\u003cString, Error\u003e;\n\n    fn handle(\u0026mut self, msg: TestActorCommand, _ctx: \u0026mut Self::Context) -\u003e Self::Result {\n        match msg {\n            TestActorCommand::Echo(message) =\u003e Ok(message),\n            rest =\u003e Ok(format!(\"{:?}\", rest)),\n        }\n    }\n}\n\n#[actix::test]\nasync fn sends_hello_back() {\n    let actor_expect = ActorExpect::\u003cTestActor, Error\u003e::expect_send(\n        TestActorCommand::Echo(\"Message\".to_string()),\n        \"Message\".to_string(),\n        None,\n    );\n    let actor = \u0026actor_expect.addr;\n\n    let _ = actor\n        .send(TestActorCommand::Echo(\"Message\".to_string()))\n        .await\n        .expect(\"Not able to process Echo\");\n    let _ = actor\n        .send(TestActorCommand::Hello)\n        .await\n        .expect(\"Not able to process Hello\");\n    let _ = actor\n        .send(TestActorCommand::Dunno)\n        .await\n        .expect(\"Not able to process Dunno\");\n\n    assert_eq!(actor_expect.total_calls(), 3_usize);\n    assert_eq!(\n        actor_expect.calls_of_variant(TestActorCommand::Echo(\"Message\".to_string())),\n        1_usize\n    );\n}\n```\n\nAlso take a look at [tests](./tests).\n\n# License\n\nDistributed under the terms of [MIT license](./LICENSE-MIT) and [Apache license](./LICENSE-APACHE).\n\n\n[cargo-badge]: https://img.shields.io/crates/v/actix-actor-expect.svg?style=flat-square\n[cargo]: https://crates.io/crates/actix-actor-expect\n[license-badge]: https://img.shields.io/badge/license-MIT/Apache--2.0-lightgray.svg?style=flat-square\n[license]: #license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feisberg-labs%2Factix-actor-expect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feisberg-labs%2Factix-actor-expect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feisberg-labs%2Factix-actor-expect/lists"}