From 193d4daac565111849e0ae3c8e3d625b2eccb2a7 Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Thu, 15 Aug 2024 14:32:04 -0700 Subject: [PATCH] Better advice for mocked base functions. If the function is used as an argument somewhere, binding NULL to it causes that call to fail. Instead bind the actual function, and then mock that. I think it might also be necessary to do the same for the other default packages, but I'm not certain. Will likely know better at the end of TDD! --- R/mock2.R | 4 ++-- man/local_mocked_bindings.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/mock2.R b/R/mock2.R index a351cb88e..2a3549a6d 100644 --- a/R/mock2.R +++ b/R/mock2.R @@ -48,12 +48,12 @@ #' #' To mock a function in the base package, you need to make sure that you #' have a binding for this function in your package. It's easiest to do this -#' by binding the value to `NULL`. For example, if you wanted to mock +#' by binding the name to the function. For example, if you wanted to mock #' `interactive()` in your package, you'd need to include this code somewhere #' in your package: #' #' ```R -#' interactive <- NULL +#' interactive <- interactive #' ``` #' #' Why is this necessary? `with_mocked_bindings()` and `local_mocked_bindings()` diff --git a/man/local_mocked_bindings.Rd b/man/local_mocked_bindings.Rd index d8df2b34f..fe679651e 100644 --- a/man/local_mocked_bindings.Rd +++ b/man/local_mocked_bindings.Rd @@ -70,11 +70,11 @@ you mock it the same way: To mock a function in the base package, you need to make sure that you have a binding for this function in your package. It's easiest to do this -by binding the value to \code{NULL}. For example, if you wanted to mock +by binding the name to the function. For example, if you wanted to mock \code{interactive()} in your package, you'd need to include this code somewhere in your package: -\if{html}{\out{
}}\preformatted{interactive <- NULL +\if{html}{\out{
}}\preformatted{interactive <- interactive }\if{html}{\out{
}} Why is this necessary? \code{with_mocked_bindings()} and \code{local_mocked_bindings()}