From d555b975e952a60175f22ad57534279a35d5fd20 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 8 Jan 2025 16:34:18 -0600 Subject: [PATCH] Make `with_mock()`/`local_mock()` defunct (#637) --- NEWS.md | 1 + R/req-mock.R | 4 ++-- revdep/cran.md | 2 +- tests/testthat/_snaps/req-mock.md | 6 +++--- tests/testthat/test-req-mock.R | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index f13e12ec..04753b9f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # httr2 (development version) +* `with_mock()` and `local_mock()` are now defunct and will be removed in the next release. * `req_auth_aws_v4()` correctly formats the Authorization header (#627). * `req_perform_stream()` is superseded and likely on track for deprecation; `req_perform_connection()` is no longer experimental (#625) * `req_retry()` now optionally implements "circuit breaking" so that if requests to the same server fail many times (i.e. because the server is down), you can choose to immediately error rather than waiting (#370). diff --git a/R/req-mock.R b/R/req-mock.R index 56d9be0c..b13b2862 100644 --- a/R/req-mock.R +++ b/R/req-mock.R @@ -40,7 +40,7 @@ with_mocked_responses <- function(mock, code) { #' @rdname with_mocked_responses #' @usage NULL with_mock <- function(mock, code) { - lifecycle::deprecate_warn("1.0.0", "with_mock()", "with_mocked_responses()") + lifecycle::deprecate_stop("1.1.0", "with_mock()", "with_mocked_responses()") with_mocked_responses(mock, code) } @@ -55,7 +55,7 @@ local_mocked_responses <- function(mock, env = caller_env()) { #' @rdname with_mocked_responses #' @usage NULL local_mock <- function(mock, env = caller_env()) { - lifecycle::deprecate_warn("1.0.0", "local_mock()", "local_mocked_responses()") + lifecycle::deprecate_warn("1.1.0", "local_mock()", "local_mocked_responses()") local_mocked_responses(mock, env) } diff --git a/revdep/cran.md b/revdep/cran.md index c5bf0bc8..ebc12d2c 100644 --- a/revdep/cran.md +++ b/revdep/cran.md @@ -1,6 +1,6 @@ ## revdepcheck results -We checked 171 reverse dependencies (170 from CRAN + 1 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package. +We checked 170 reverse dependencies (169 from CRAN + 1 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package. * We saw 5 new problems * We failed to check 0 packages diff --git a/tests/testthat/_snaps/req-mock.md b/tests/testthat/_snaps/req-mock.md index 6d0d4773..3b77c31a 100644 --- a/tests/testthat/_snaps/req-mock.md +++ b/tests/testthat/_snaps/req-mock.md @@ -4,13 +4,13 @@ local_mock(~ response(404)) Condition Warning: - `local_mock()` was deprecated in httr2 1.0.0. + `local_mock()` was deprecated in httr2 1.1.0. i Please use `local_mocked_responses()` instead. Code . <- with_mock(NULL, ~ response(404)) Condition - Warning: - `with_mock()` was deprecated in httr2 1.0.0. + Error: + ! `with_mock()` was deprecated in httr2 1.1.0 and is now defunct. i Please use `with_mocked_responses()` instead. # validates inputs diff --git a/tests/testthat/test-req-mock.R b/tests/testthat/test-req-mock.R index 457f7882..453caecd 100644 --- a/tests/testthat/test-req-mock.R +++ b/tests/testthat/test-req-mock.R @@ -16,7 +16,7 @@ test_that("can generate errors with mocking", { }) test_that("local_mock and with_mock are deprecated", { - expect_snapshot({ + expect_snapshot(error = TRUE, { local_mock(~ response(404)) . <- with_mock(NULL, ~ response(404)) })