Skip to content

Commit e724ec7

Browse files
authored
Mention new mocking functions where appropriate (#1768)
Fixes #1766
1 parent 95635f6 commit e724ec7

File tree

4 files changed

+18
-33
lines changed

4 files changed

+18
-33
lines changed

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
can more easily run BDD tests interactively (#1587)
1111

1212
* `with_mocked_bindings()` and `local_mocked_bindings()` can now bind in the
13-
imports namespace too.
13+
imports namespace too. This changes makes them very close in capability
14+
for `with_mock()` and `local_mock()` so those functions now recommend
15+
`with_mocked_bindings()` and `local_mocked_bindings()` rather than functions
16+
from the mockr/mockery packages.
1417

1518
# testthat 3.1.7
1619

R/mock.R

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,12 @@
33
#' @description
44
#' `r lifecycle::badge("superseded")`
55
#'
6-
#' `with_mock()` and `local_mock()` are superseded in favour of the more
7-
#' rigorous techniques found in the [mockr](https://krlmlr.github.io/mockr/)
8-
#' and [mockery](https://github.com/r-lib/mockery#mockery) packages.
6+
#' `with_mock()` and `local_mock()` are superseded in favour of
7+
#' [with_mocked_bindings()] and [local_mocked_bindings()].
98
#'
10-
#' Mocking allows you to temporary replace the implementation of functions
11-
#' within a package, which useful for testing code that relies on functions
12-
#' that are slow, have unintended side effects or access resources that may
13-
#' not be available when testing.
14-
#'
15-
#' This works by using some C code to temporarily modify the mocked function
16-
#' _in place_. On exit, all functions are restored to their previous state.
17-
#' This is somewhat abusive of R's internals so use with care. In particular,
18-
#' functions in base packages cannot be mocked; to work aroud you'll need to
19-
#' make a wrapper function in your own package..
9+
#' These works by using some C code to temporarily modify the mocked function
10+
#' _in place_. This is abusive of R's internals, which makes it dangerous, and
11+
#' no longer recommended.
2012
#'
2113
#' @section 3rd edition:
2214
#' `r lifecycle::badge("deprecated")`
@@ -34,9 +26,7 @@
3426
#' @return The result of the last unnamed parameter
3527
#' @export
3628
with_mock <- function(..., .env = topenv()) {
37-
edition_deprecate(3, "with_mock()",
38-
"Please use mockr or mockery packages instead"
39-
)
29+
edition_deprecate(3, "with_mock()", "Please use with_mocked_bindings() instead")
4030

4131
dots <- eval(substitute(alist(...)))
4232
mock_qual_names <- names(dots)
@@ -71,9 +61,7 @@ with_mock <- function(..., .env = topenv()) {
7161
#' @export
7262
#' @rdname with_mock
7363
local_mock <- function(..., .env = topenv(), .local_envir = parent.frame()) {
74-
edition_deprecate(3, "local_mock()",
75-
"Please use mockr or mockery packages instead"
76-
)
64+
edition_deprecate(3, "local_mock()", "Please use local_mocked_bindings() instead")
7765

7866
mocks <- extract_mocks(list(...), .env = .env)
7967
on_exit <- bquote(

man/with_mock.Rd

Lines changed: 5 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/third-edition.Rmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ Most of these functions have not been recommended for a number of years, but bef
8989

9090
- `expect_known_output()`, `expect_known_value()`, `expect_known_hash()`, and `expect_equal_to_reference()` are all deprecated in favour of `expect_snapshot_output()` and `expect_snapshot_value()`.
9191

92-
- `with_mock()` and `local_mock()` are deprecated; please use the [mockr](https://krlmlr.github.io/mockr/) or [mockery](https://github.com/r-lib/mockery#mockery) instead.
92+
- `with_mock()` and `local_mock()` are deprecated; please use
93+
`with_mocked_bindings()` or `local_mocked_bindings()` instead.
9394

9495
Fixing these deprecation warnings should be straightforward.
9596

0 commit comments

Comments
 (0)