webmockr icon indicating copy to clipboard operation
webmockr copied to clipboard

Fixes needed for v2 vcr

Open sckott opened this issue 10 months ago • 0 comments

e.g., need to fix

test output

ℹ Testing webmockr
✔ | F W  S  OK | Context
✔ |          3 | Adapter class
✔ |          6 | auth_handling
✔ |          1 | no_cassette_in_use
✖ | 1       17 | CrulAdapter
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Error (test-CrulAdapter.R:61:3): CrulAdapter: works when vcr is loaded but no cassette is inserted
Error in `vcr::eject_cassette("empty")`: unused argument ("empty")
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✖ | 2       32 | CrulAdapter - with real data
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Failure (test-CrulAdapter.R:84:3): CrulAdapter works
`res$handle_request(crul_obj)` threw an error with unexpected message.
Expected match: "Real HTTP connections are disabled"
Actual message: "Could not connect to server [localhost]: Failed to connect to localhost port 9000 after 0 ms: Could not connect to server"
Backtrace:
     ▆
  1. ├─testthat::expect_error(res$handle_request(crul_obj), "Real HTTP connections are disabled") at test-CrulAdapter.R:84:3
  2. │ └─testthat:::quasi_capture(...)
  3. │   ├─testthat (local) .capture(...)
  4. │   │ └─base::withCallingHandlers(...)
  5. │   └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
  6. ├─res$handle_request(crul_obj)
  7. │ └─private$fetch_request(req) at webmockr/R/adapter.R:193:11
  8. │   ├─private$build_response(request, webmockr_crul_fetch(request)) at webmockr/R/adapter-crul.R:94:7
  9. │   │ ├─base::grepl("^ftp://", resp$url %||% "") at webmockr/R/adapter-crul.R:8:3
 10. │   │ │ └─base::is.factor(x)
 11. │   │ └─resp$url %||% ""
 12. │   └─webmockr::webmockr_crul_fetch(request) at webmockr/R/zzz.R:151:3
 13. │     └─curl::curl_fetch_memory(x$url$url, handle = x$url$handle) at webmockr/R/zzz.R:239:5
 14. └─curl:::raise_libcurl_error(...)

Failure (test-CrulAdapter.R:200:3): crul requests with JSON-encoded bodies work
`cli$post("post", body = list(foo = "bar1"), encode = "json")` did not throw an error.
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔ |         28 | flipswitch (enable/disable)
✔ |         16 | HashCounter
✔ |         24 | HttpLibAdapaterRegistry
✖ | 1       17 | Httr2Adapter
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Error (test-Httr2Adapter.R:62:3): Httr2Adapter: works when vcr is loaded but no cassette is inserted
Error in `vcr::eject_cassette("empty")`: unused argument ("empty")
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✖ | 1        2 | Httr2Adapter: date slot
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Error (test-Httr2Adapter.R:86:3): Httr2Adapter date slot works
Error in `vcr::eject_cassette("test-date")`: unused argument ("test-date")
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✖ | 3       33 | Httr2Adapter: works with real data
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Failure (test-Httr2Adapter.R:109:3): Httr2Adapter works
`res$handle_request(httr2_obj)` threw an error with unexpected message.
Expected match: "There is currently no cassette in use"
Actual message: "`status_code` must be a whole number, not `NULL`."
Backtrace:
     ▆
  1. ├─testthat::expect_error(res$handle_request(httr2_obj), "There is currently no cassette in use") at test-Httr2Adapter.R:109:3
  2. │ └─testthat:::quasi_capture(...)
  3. │   ├─testthat (local) .capture(...)
  4. │   │ └─base::withCallingHandlers(...)
  5. │   └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
  6. └─res$handle_request(httr2_obj)
  7.   └─private$request_handler(req)$handle() at webmockr/R/adapter.R:128:11
  8.     └─private$on_stubbed_by_vcr_request()
  9.       └─httr2::response(status_code = vcr_response$status)
 10.         └─httr2:::check_number_whole(status_code, min = 100, max = 700)
 11.           └─httr2:::.stop_not_number(...)
 12.             └─httr2:::stop_input_type(...)
 13.               └─rlang::abort(message, ..., call = call, arg = arg)

Failure (test-Httr2Adapter.R:117:3): Httr2Adapter works
`res$handle_request(httr2_obj)` did not throw an error.

Failure (test-Httr2Adapter.R:201:3): Httr2Adapter works with req_auth_basic
jsonlite::fromJSON(rawToChar(x$body)) not equal to list(authenticated = TRUE, user = "foo").
Names: 1 string mismatch
Length mismatch: comparison on first 1 components
Component 1: Modes: character, logical
Component 1: target is character, current is logical
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✖ | 1       17 | HttrAdapter
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Error (test-HttrAdapter.R:62:3): HttrAdapter: works when vcr is loaded but no cassette is inserted
Error in `vcr::eject_cassette("empty")`: unused argument ("empty")
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✖ | 1        5 | HttrAdapter: date slot
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Error (test-HttrAdapter.R:95:3): HttrAdapter date slot works
Error in `vcr::eject_cassette("test-date")`: unused argument ("test-date")
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✖ | 2        5 | HttrAdapter: date slot
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Error (test-HttrAdapter.R:95:3): HttrAdapter date slot works
Error in `vcr::eject_cassette("test-date")`: unused argument ("test-date")

Error (test-HttrAdapter.R:102:1): (code run outside of `test_that()`)
<testthat_abort_reporter/rlang_error/error/condition>
Error: Maximum number of failures exceeded; quitting at end of file.
ℹ Increase this number with (e.g.) `testthat::set_max_fails(Inf)`
Backtrace:
     ▆
  1. └─testthat::context("HttrAdapter: insensitive headers, webmockr flow") at test-HttrAdapter.R:102:1
  2.   └─testthat:::context_start(desc)
  3.     └─get_reporter()$.start_context(desc)
  4.       └─self$end_context(self$.context)
  5.         └─testthat:::o_apply(self$reporters, "end_context", context)
  6.           └─base::lapply(objects, f)
  7.             └─testthat (local) FUN(X[[i]], ...)
  8.               └─x$end_context(...)
  9.                 └─testthat:::stop_reporter(...)
 10.                   └─cli::cli_abort(message, class = "testthat_abort_reporter", call = NULL)
 11.                     └─rlang::abort(...)
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Maximum number of failures exceeded; quitting at end of file.
ℹ Increase this number with (e.g.) `testthat::set_max_fails(Inf)`

sckott avatar Apr 29 '25 17:04 sckott