{"id":15806196,"url":"https://github.com/qnighy/fakeenv","last_synced_at":"2025-07-25T00:06:56.477Z","repository":{"id":57627281,"uuid":"233536611","full_name":"qnighy/fakeenv","owner":"qnighy","description":"A simple wrapper of `std::env` which allows faking the environment in Rust","archived":false,"fork":false,"pushed_at":"2020-01-19T07:52:41.000Z","size":11,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T15:18:49.208Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qnighy.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":"2020-01-13T07:28:31.000Z","updated_at":"2023-07-25T17:19:40.000Z","dependencies_parsed_at":"2022-08-23T17:10:53.318Z","dependency_job_id":null,"html_url":"https://github.com/qnighy/fakeenv","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/qnighy%2Ffakeenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qnighy%2Ffakeenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qnighy%2Ffakeenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qnighy%2Ffakeenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qnighy","download_url":"https://codeload.github.com/qnighy/fakeenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250023466,"owners_count":21362406,"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-05T02:42:28.263Z","updated_at":"2025-04-21T08:31:26.741Z","avatar_url":"https://github.com/qnighy.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fakeenv\n\nA simple wrapper of `std::env` which allows faking the environment.\n\n[`std::env`]: https://doc.rust-lang.org/std/env/index.html\n\n# Example\n\n## Using the real environment\n\n```rust\nuse fakeenv::EnvStore;\n\nfn answer(env: \u0026EnvStore) -\u003e i32 {\n    env.var(\"THE_ANSWER\").unwrap().parse().unwrap()\n}\n\nfn main() {\n    std::env::set_var(\"THE_ANSWER\", \"42\");\n\n    let env = EnvStore::real();\n    assert_eq!(answer(\u0026env), 42);\n}\n```\n\n## Making a fake environment\n\nFake is only turned on when the `fake` feature is enabled.\n\nAs this is mostly for testing purpose, you might want to enable\nthe feature like this:\n\n```toml\n[dependencies]\nfakeenv = \"0.1.0\"\n\n[dev-dependencies]\nfakeenv = { version = \"0.1.0\", features = [\"fake\"] }\n```\n\nThen you can generate a fake environment using [`EnvStore::fake`]:\n\n[`EnvStore::fake`]: struct.EnvStore.html#method.fake\n\n```rust\nuse fakeenv::EnvStore;\n\nfn answer(env: \u0026EnvStore) -\u003e i32 {\n    env.var(\"THE_ANSWER\").unwrap().parse().unwrap()\n}\n\nfn main() {\n    let env = EnvStore::fake();\n    env.set_var(\"THE_ANSWER\", \"42\");\n    assert_eq!(answer(\u0026env), 42);\n}\n```\n\n## Faking user directories\n\nThe `dirs` feature enables faking the [`dirs`] functions.\n\n[`dirs`]: https://docs.rs/dirs/2.*/dirs/index.html\n\n```toml\n[dependencies]\nfakeenv = { version = \"0.1.0\", features = [\"dirs\"] }\n```\n\n```rust\nlet env = EnvStore::real();\nprintln!(\"home directory = {:?}\", env.home_dir());\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqnighy%2Ffakeenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqnighy%2Ffakeenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqnighy%2Ffakeenv/lists"}