Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop_mocking() should untrace all functions (closes #66, #78) #79

Merged
merged 4 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/trace.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ quietly <- function(expr) {
#' @return Nothing; called for its side effects
#' @export
stop_mocking <- function() {
safe_untrace(curl::form_file)
invisible(safe_untrace("request_perform", add_headers))
safe_untrace("request_perform", add_headers)
kforner marked this conversation as resolved.
Show resolved Hide resolved
safe_untrace("body_config", getNamespace("httr"))
safe_untrace("form_file", getNamespace("curl"))
invisible()
}

safe_untrace <- function(what, where = sys.frame()) {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.httr-oauth
11 changes: 11 additions & 0 deletions tests/testthat/test-mock-api.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ public({
)
})
})

# check that the functions are untraced
kforner marked this conversation as resolved.
Show resolved Hide resolved
expect_false(inherits(httr:::body_config, "functionWithTrace"))
expect_false(inherits(curl::form_file, "functionWithTrace"))
expect_false(inherits(httr:::request_perform, "functionWithTrace"))
for (verb in c("GET", "PUT", "POST", "PATCH", "DELETE", "VERB", "RETRY")) {
fun <- getFromNamespace(verb, 'httr')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that we don't have to use ::: to get them:

Suggested change
for (verb in c("GET", "PUT", "POST", "PATCH", "DELETE", "VERB", "RETRY")) {
fun <- getFromNamespace(verb, 'httr')
for (fun_name in c("GET", "PUT", "POST", "PATCH", "DELETE", "VERB", "RETRY", "body_config", "request_perform")) {
fun <- getFromNamespace(fun_name, "httr")

expect_false(inherits(fun, "functionWithTrace"))
}


})

test_that("build_mock_url file path construction with character URL", {
Expand Down