|
3 | 3 | #' @description |
4 | 4 | #' `r lifecycle::badge("superseded")` |
5 | 5 | #' |
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()]. |
9 | 8 | #' |
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. |
20 | 12 | #' |
21 | 13 | #' @section 3rd edition: |
22 | 14 | #' `r lifecycle::badge("deprecated")` |
|
34 | 26 | #' @return The result of the last unnamed parameter |
35 | 27 | #' @export |
36 | 28 | 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") |
40 | 30 |
|
41 | 31 | dots <- eval(substitute(alist(...))) |
42 | 32 | mock_qual_names <- names(dots) |
@@ -71,9 +61,7 @@ with_mock <- function(..., .env = topenv()) { |
71 | 61 | #' @export |
72 | 62 | #' @rdname with_mock |
73 | 63 | 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") |
77 | 65 |
|
78 | 66 | mocks <- extract_mocks(list(...), .env = .env) |
79 | 67 | on_exit <- bquote( |
|
0 commit comments