diff --git a/R/trace.R b/R/trace.R index 0395eb7..6e233bb 100644 --- a/R/trace.R +++ b/R/trace.R @@ -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", getNamespace("httr")) + safe_untrace("body_config", getNamespace("httr")) + safe_untrace("form_file", getNamespace("curl")) + invisible() } safe_untrace <- function(what, where = sys.frame()) { diff --git a/tests/testthat/.gitignore b/tests/testthat/.gitignore new file mode 100644 index 0000000..b49c113 --- /dev/null +++ b/tests/testthat/.gitignore @@ -0,0 +1 @@ +.httr-oauth diff --git a/tests/testthat/test-mock-api.R b/tests/testthat/test-mock-api.R index 85f9521..7709dfd 100644 --- a/tests/testthat/test-mock-api.R +++ b/tests/testthat/test-mock-api.R @@ -212,6 +212,7 @@ public({ ) }) }) + }) test_that("build_mock_url file path construction with character URL", { diff --git a/tests/testthat/test-trace.R b/tests/testthat/test-trace.R index 5ab4eac..4cc0d20 100644 --- a/tests/testthat/test-trace.R +++ b/tests/testthat/test-trace.R @@ -10,6 +10,32 @@ public({ expect_error(stop_capturing(), NA) expect_error(stop_capturing(), NA) }) + + FUNS <- list( + httr = c('request_perform', 'body_config'), + curl = c('form_file') + ) + + .are_pkgs_traced <- function() { + .process_fun <- function(fun, pkg) { + inherits(getFromNamespace(fun, pkg), "functionWithTrace") + } + .process_pkg <- function(pkg) { + sapply(FUNS[[pkg]], .process_fun, pkg = pkg) + } + unlist(lapply(names(FUNS), .process_pkg)) + } + + with_mock_api({ + test_that("curl/httr functions are properly traced", { + expect_true(all(.are_pkgs_traced())) + }) + }) + + test_that("curl/httr functions are properly untraced", { + expect_false(any(.are_pkgs_traced())) + }) + }) test_that("quietly muffles messages, conditional on httptest.debug", {