Skip to content

Commit

Permalink
Make with_mock()/local_mock() defunct (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored Jan 8, 2025
1 parent 853acc3 commit d555b97
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
4 changes: 2 additions & 2 deletions R/req-mock.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion revdep/cran.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/req-mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-req-mock.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down

0 comments on commit d555b97

Please sign in to comment.