{"id":14066351,"url":"https://github.com/krlmlr/mockr","last_synced_at":"2025-04-09T19:18:56.147Z","repository":{"id":14879304,"uuid":"77254235","full_name":"krlmlr/mockr","owner":"krlmlr","description":"Drop-in replacement for testthat::with_mock()","archived":false,"fork":false,"pushed_at":"2024-12-09T00:51:42.000Z","size":460,"stargazers_count":18,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T19:18:51.577Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://krlmlr.github.io/mockr/","language":"R","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/krlmlr.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-23T22:40:26.000Z","updated_at":"2024-12-09T00:51:45.000Z","dependencies_parsed_at":"2024-01-13T05:28:43.135Z","dependency_job_id":"d7ffa6ba-a5b9-4347-ad14-927c8216dcfa","html_url":"https://github.com/krlmlr/mockr","commit_stats":{"total_commits":280,"total_committers":6,"mean_commits":"46.666666666666664","dds":0.5,"last_synced_commit":"ecaf83c6a3454e5ebb644531be8e86a02507934c"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krlmlr%2Fmockr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krlmlr%2Fmockr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krlmlr%2Fmockr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krlmlr%2Fmockr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krlmlr","download_url":"https://codeload.github.com/krlmlr/mockr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094990,"owners_count":21046770,"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":[],"created_at":"2024-08-13T07:05:03.421Z","updated_at":"2025-04-09T19:18:56.127Z","avatar_url":"https://github.com/krlmlr.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: downlit::readme_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n\npkgload::load_all()\n```\n\n# mockr\n\n\u003c!-- badges: start --\u003e\n[![rcc](https://github.com/krlmlr/mockr/workflows/rcc/badge.svg)](https://github.com/krlmlr/mockr/actions)\n[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/mockr)](https://cran.r-project.org/package=mockr)\n[![Codecov test coverage](https://codecov.io/gh/krlmlr/mockr/branch/main/graph/badge.svg)](https://app.codecov.io/gh/krlmlr/mockr?branch=main)\n\u003c!-- badges: end --\u003e\n\n\nThe goal of mockr is to provide a drop-in replacement for `testthat::local_mock()` and `testthat::with_mock()` which is deprecated in testthat 3.0.0.\nThe functions `mockr::local_mock()` and `mockr::with_mock()` are modeled closely after the original implementation, but now only allow mocking functions in the package under test.\nIn contrast to the original implementation, no fiddling\nwith R's internals is needed, and the implementation plays well with byte-compiled code.\nThere are some caveats, though:\n\n1. Mocking external functions (in other packages) doesn't work anymore. This is by design.\n    - If you need to mock an external function, write a wrapper.\n    - If that external function is called by third-party code, you'll need to perhaps mock that third-party code, or look for a different way of implementing this test or organizing your code.\n2. You cannot refer to functions in your package via `your.package::` or `your.package:::` anymore.\n    - Remove the `your.package:::`, your code and tests should run just fine without that.\n\nIf you encounter other problems, please [file an issue](https://github.com/krlmlr/mockr/issues).\n\n## Example\n\n```{r example, error = TRUE}\nlibrary(mockr)\n\naccess_resource \u003c- function() {\n  message(\"Trying to access resource...\")\n  # For some reason we can't access the resource in our tests.\n  stop(\"Can't access resource now.\")\n}\n\nwork_with_resource \u003c- function() {\n  resource \u003c- access_resource()\n  message(\"Fetched resource: \", resource)\n  invisible(resource)\n}\n\n# Calling this function gives an error\nwork_with_resource()\n\nlocal({\n  # Here, we override the function that raises the error\n  local_mock(access_resource = function() 42)\n\n  # No error raised\n  work_with_resource()\n})\n```\n\n\n## Installation\n\nInstall from CRAN via\n\n```r\ninstall.packages(\"mockr\")\n```\n\n---\n\n## Code of Conduct\n\nPlease note that the mockr project is released with a [Contributor Code of Conduct](https://krlmlr.github.io/mockr/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrlmlr%2Fmockr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrlmlr%2Fmockr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrlmlr%2Fmockr/lists"}