Skip to content

Commit adb2ebf

Browse files
authored
Tweak how httr2 mocking function is set (#141)
There's no need to use `local_` here since you're not setting it locally and this avoids a slightly confusing message from withr: ```R webmockr::enable() #> CrulAdapter enabled! #> HttrAdapter enabled! #> Httr2Adapter enabled! #> Setting global deferred event(s). #> i These will be run: #> * Automatically, when the R session ends. #> * On demand, if you call `withr::deferred_run()`. #> i Use `withr::deferred_clear()` to clear them without executing. ``` (In principle, it would be better if webmockr could restore the previous state prior to its mocking, but it's not a big deal given that there are very few other tools that do web mocking).
1 parent ccd9398 commit adb2ebf

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

R/adapter-httr2.R

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,8 @@ build_httr2_request <- function(x) {
101101
httr2_mock <- function(on = TRUE) {
102102
check_installed("httr2")
103103
if (on) {
104-
httr2::local_mocked_responses(
105-
~ Httr2Adapter$new()$handle_request(.x),
106-
env = .GlobalEnv
107-
)
104+
options(httr2_mock = function(req) Httr2Adapter$new()$handle_request(req))
108105
} else {
109-
httr2::local_mocked_responses(NULL, env = .GlobalEnv)
110106
options(httr2_mock = NULL)
111107
}
112108
invisible(on)

0 commit comments

Comments
 (0)