Skip to content

Commit 8382a06

Browse files
committed
#149 crul mocking changes, not done yet
1 parent e7294d5 commit 8382a06

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Suggests:
4242
httr2,
4343
diffobj,
4444
withr
45+
Remotes: ropensci/crul@change-mocking, ropensci/vcr@remove-webmockr
4546
RoxygenNote: 7.3.2
4647
Config/testthat/edition: 3
4748
X-schema.org-applicationCategory: Web

R/adapter-crul.R

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ build_crul_request <- function(x) {
7575
)
7676
}
7777

78+
crul_mock <- function(on = TRUE) {
79+
check_installed("crul")
80+
if (on) {
81+
options(crul_mock = function(req) {
82+
webmockr::CrulAdapter$new()$handle_request(req)
83+
})
84+
} else {
85+
options(crul_mock = NULL)
86+
}
87+
invisible(on)
88+
}
89+
7890
#' @rdname Adapter
7991
#' @export
8092
#' @keywords internal
@@ -89,7 +101,8 @@ CrulAdapter <- R6::R6Class(
89101
),
90102
private = list(
91103
pluck_url = function(request) request$url$url,
92-
mock = function(on) crul::mock(on),
104+
# mock = function(on) crul::mock(on),
105+
mock = function(on) crul_mock(on),
93106
build_request = build_crul_request,
94107
build_response = build_crul_response,
95108
fetch_request = function(request) {

R/adapter.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Adapter <- R6::R6Class(
4242

4343
switch(
4444
self$client,
45-
crul = crul::mock(on = TRUE),
45+
crul = crul_mock(on = TRUE),
4646
httr = httr_mock(on = TRUE),
4747
httr2 = httr2_mock(on = TRUE)
4848
)
@@ -61,7 +61,7 @@ Adapter <- R6::R6Class(
6161

6262
switch(
6363
self$client,
64-
crul = crul::mock(on = FALSE),
64+
crul = crul_mock(on = FALSE),
6565
httr = httr_mock(on = FALSE),
6666
httr2 = httr2_mock(on = FALSE)
6767
)

tests/testthat/test-b-no-cassette-in-use.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
test_that("no cassette in use behaves as expected", {
22
skip_if_not_installed("vcr")
33
library("vcr")
4+
library("httr")
45
dir <- tempdir()
56
invisible(vcr_configure(dir = dir))
67

7-
crul::mock()
8-
x <- crul::HttpClient$new(url = hb())
8+
enable()
99

1010
# when no cassette in use, we get expected vcr error
1111
expect_error(
12-
x$get("get"),
13-
"There is currently no cassette in use"
12+
GET(url = hb(), path = "get"),
13+
"Failed to find matching request"
1414
)
1515

1616
# cleanup

0 commit comments

Comments
 (0)