{"id":13400501,"url":"https://github.com/r-lib/mockery","last_synced_at":"2026-04-09T03:31:06.052Z","repository":{"id":12296674,"uuid":"63628772","full_name":"r-lib/mockery","owner":"r-lib","description":"A mocking library for R.","archived":false,"fork":false,"pushed_at":"2025-09-04T12:25:01.000Z","size":130,"stargazers_count":104,"open_issues_count":4,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-03-28T09:33:40.724Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/r-lib.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2016-07-18T18:54:06.000Z","updated_at":"2025-10-18T12:28:46.000Z","dependencies_parsed_at":"2024-01-18T11:03:39.634Z","dependency_job_id":"c892d9f6-fe06-40bb-a740-a2035110ffed","html_url":"https://github.com/r-lib/mockery","commit_stats":{"total_commits":140,"total_committers":12,"mean_commits":"11.666666666666666","dds":0.5428571428571429,"last_synced_commit":"764da9fa301ee1232d178ba845c65a51aacaf107"},"previous_names":["jfiksel/mockery"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/r-lib/mockery","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fmockery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fmockery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fmockery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fmockery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-lib","download_url":"https://codeload.github.com/r-lib/mockery/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fmockery/sbom","scorecard":{"id":756769,"data":{"date":"2025-08-11","repo":{"name":"github.com/r-lib/mockery","commit":"147de292dc35007f769fda38a3fb3f01b1643384"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Code-Review","score":0,"reason":"Found 2/30 approved changesets -- score normalized to 0","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":"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":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","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 1 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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/R-CMD-check.yaml:1","Warn: no topLevel permission defined: .github/workflows/test-coverage.yaml:1","Info: no jobLevel write permissions found"],"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":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/R-CMD-check.yaml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/r-lib/mockery/R-CMD-check.yaml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/R-CMD-check.yaml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/r-lib/mockery/R-CMD-check.yaml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/R-CMD-check.yaml:49: update your workflow using https://app.stepsecurity.io/secureworkflow/r-lib/mockery/R-CMD-check.yaml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/R-CMD-check.yaml:55: update your workflow using https://app.stepsecurity.io/secureworkflow/r-lib/mockery/R-CMD-check.yaml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/R-CMD-check.yaml:60: update your workflow using https://app.stepsecurity.io/secureworkflow/r-lib/mockery/R-CMD-check.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-coverage.yaml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/r-lib/mockery/test-coverage.yaml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test-coverage.yaml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/r-lib/mockery/test-coverage.yaml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test-coverage.yaml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/r-lib/mockery/test-coverage.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-coverage.yaml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/r-lib/mockery/test-coverage.yaml/main?enable=pin","Info:   0 out of   3 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   6 third-party GitHubAction dependencies pinned"],"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":"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":"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":"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":"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":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"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 'main'"],"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 3 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-22T21:53:58.833Z","repository_id":12296674,"created_at":"2025-08-22T21:53:58.833Z","updated_at":"2025-08-22T21:53:58.833Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31584567,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-07-30T19:00:52.697Z","updated_at":"2026-04-09T03:31:06.027Z","avatar_url":"https://github.com/r-lib.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"# mockery\n\u003c!-- badges: start --\u003e\n[![Lifecycle: superseded](https://img.shields.io/badge/lifecycle-superseded-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html#superseded)\n[![CRAN version](http://www.r-pkg.org/badges/version/mockery)](https://CRAN.r-project.org/package=mockery)\n[![R-CMD-check](https://github.com/r-lib/mockery/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/mockery/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/r-lib/mockery/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/mockery?branch=main)\n\u003c!-- badges: end --\u003e\n\nA mocking library for R.\n\nThis package is superseded and we no longer recommend that you use it for new tests. \nWe instead recommend `testthat::local_mocked_bindings()`.\n\n### Installation\n\nTo install the latest CRAN release:\n\n```R\ninstall.packages('mockery')\n```\n\nTo install directly from the source code in this GitHub repository:\n\n```R\n# install.packages('pak')\npak::pak('r-lib/mockery')\n```\n\n### Testing\n\nMockery provides the capacity for stubbing out functions and for verifying\nfunction calls during testing.\n\n#### Stubbing\n\nMockery's `stub` function will let you stub out a function with another\nfunction or simply a return value.  Note that if you choose to replace the\nfunction with another function, the signatures of the two functions should be\ncompatible.\n\n##### Examples\n\n```R\ng = function(y) y\nf = function(x) g(x) + 1\ntest_that('demonstrate stubbing', {\n    # replaces 'g' with a function that always returns 100\n    # but only when called from f\n    stub(f, 'g', 100)\n\n    # this can also be written\n    stub(f, 'g', function(...) 100)\n    expect_equal(f(1), 101)\n})\n```\n\nStubbing works with classes of all descriptions and namespaced functions:\n\n```R\n# this stubs the 'request_perform' function, but only\n# for httr::get, and only when it is called from within this\n# test function\nstub(httr::GET, 'request_perform', 'some html')\n        \n# it is also possible to stub out a namespaced function call\nstub(some_function, 'namespace::function', 'some return value')\n```\n\nThis also works with R6 classes and methods.\n\n###### Depth\n\nIt's possible to specify the depth of stubbing. This is useful if you\nwant to stub a function that isn't called directly by the function you call in\nyour test, but is instead called by a function that that function calls. \n\nIn the example below, the function `g` is both called directly from `r`, which\nwe call from the test, and from `f`, which `r` calls. By specifying a depth of\n2, we tell mockery to stub `g` in both places.\n\n```R\ng = function(y) y\nf = function(x) g(x) + 1\nr = function(x) g(x) + f(x)\ntest_that('demonstrate stubbing', {\n    stub(r, 'g', 100, depth=2)\n    expect_equal(r(1), 201)\n})\n```\n\nFor more examples, please see the test code contained in this repository.\n\n##### Comparison to with_mock\n\nMockery's `stub` function has similar functionality to testthat's `with_mock`.\n\nThere are several use cases in which mockery's `stub` function will work, but\ntestthat's `with_mock` will not.\n\nFirst, unlike `with_mock`, it seamlessly allows for mocking out primitives.\n\nSecond, it is easy to stub out functions from base R packages with mockery's `stub`.\nBecause of how `with_mock` works, you can get into trouble if you mock such functions \nthat the JIT compiler might try to use. These kinds of problems are avoided by `stub`'s\ndesign. As of version 2.0.0 of testthat, it will be impossible to mock functions from\nbase R packages `with_mock`.\n\nThe functionality of `stub` is just slightly different than that of `with_mock`. Instead\nof mocking out the object of interest for the duration of some code block, it mocks it\nout only when it is called from a specified function.\n\n#### Mocking\n\nMock objects allow you to specify the behavior of the function you've stubbed\nout while also verifying how that function was used. \n\n```R\ng = function(y) y\nf = function(x) g(x) + 1\ntest_that('demonstrate mock object usage', {\n    # mocks can specify behavior\n    mock = mock(100)\n    stub(f, 'g', mock)\n    result = f(5)\n    expect_equal(result, 101)\n\n    # and allow you to make assertions on the mock was treated\n    expect_called(mock, 1)\n    expect_args(mock, 1, 5)\n})\n```\n\nYou can also specify multiple return values\n\n```R\nmock = mock(1, \"a\", sqrt(3))\n```\n\nand access the arguments with which it was called.\n\n```R\nmock \u003c- mock()\nmock(x = 1)\nmock(y = 2)\n\nexpect_equal(length(mock), 2)\nargs \u003c- mock_args(mock)\n\nexpect_equal(args[[1]], list(x = 1))\nexpect_equal(args[[2]], list(y = 2))\n```\n\n---\n\nPlease report bugs and feature requests through github issues.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fmockery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-lib%2Fmockery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fmockery/lists"}