File tree Expand file tree Collapse file tree 4 files changed +21
-7
lines changed
Expand file tree Collapse file tree 4 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ Suggests:
4242 httr2,
4343 diffobj,
4444 withr
45+ Remotes: ropensci/crul@change-mocking, ropensci/vcr@remove-webmockr
4546RoxygenNote: 7.3.2
4647Config/testthat/edition: 3
4748X-schema.org-applicationCategory: Web
Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 11test_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
You can’t perform that action at this time.
0 commit comments