Skip to content

Commit

Permalink
merged from main
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jan 16, 2024
2 parents b8008ad + b79cc58 commit a527d82
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 24 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Description: Record test suite 'HTTP' requests and replays them during
real 'HTTP' responses on disk in 'cassettes'. Subsequent 'HTTP' requests
matching any previous requests in the same 'cassette' use a cached
'HTTP' response.
Version: 1.2.2.92
Version: 1.2.2.93
Authors@R: c(person("Scott", "Chamberlain", role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID="0000-0003-1444-9135")),
Expand All @@ -21,6 +21,7 @@ Authors@R: c(person("Scott", "Chamberlain", role = c("aut", "cre"),
person("rOpenSci", role = "fnd", comment = "https://ropensci.org"))
URL: https://github.com/ropensci/vcr/ (devel)
https://books.ropensci.org/http-testing/ (user manual)
https://docs.ropensci.org/vcr/ (website)
BugReports: https://github.com/ropensci/vcr/issues
License: MIT + file LICENSE
Encoding: UTF-8
Expand Down Expand Up @@ -50,7 +51,8 @@ Suggests:
crayon,
cli,
curl,
withr
withr,
webfakes
Remotes: ropensci/webmockr@httr2
X-schema.org-applicationCategory: Web
X-schema.org-keywords: http, https, API, web-services, curl, mock, mocking, http-mocking, testing, testing-tools, tdd
Expand Down
3 changes: 2 additions & 1 deletion R/cassette_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ Cassette <- R6::R6Class(
x$request_headers
},
opts = self$cassette_opts,
disk = is_disk
disk = is_disk,
skip_port_stripping = TRUE
)

response <- VcrResponse$new(
Expand Down
9 changes: 5 additions & 4 deletions R/request_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Request <- R6::R6Class(
body = NULL,
#' @field headers (character) named list
headers = NULL,
#' @field skip_port_stripping (logical) whether to strip thhe port
#' @field skip_port_stripping (logical) whether to strip the port
skip_port_stripping = FALSE,
#' @field hash (character) a named list - internal use
hash = NULL,
Expand All @@ -65,10 +65,11 @@ Request <- R6::R6Class(
#' @param fields (various) post fields
#' @param output (various) output details
#' @param policies (various) http policies, used in httr2 only
#' @param skip_port_stripping (logical) whether to strip the port.
#' default: `FALSE`
#' @return A new `Request` object
initialize = function(method, uri, body, headers, opts, disk,
fields, output, policies) {

fields, output, policies, skip_port_stripping = FALSE) {
if (!missing(method)) self$method <- tolower(method)
if (!missing(body)) {
if (inherits(body, "list")) {
Expand All @@ -78,7 +79,7 @@ Request <- R6::R6Class(
}
if (!missing(headers)) self$headers <- headers
if (!missing(uri)) {
if (!self$skip_port_stripping) {
if (!skip_port_stripping) {
self$uri <- private$without_standard_port(uri)
} else {
self$uri <- uri
Expand Down
18 changes: 16 additions & 2 deletions man/Request.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 25 additions & 14 deletions revdep/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
# Platform

|field |value |
|:--------|:----------------------------|
|version |R version 4.1.0 (2021-05-18) |
|os |macOS Big Sur 10.16 |
|system |x86_64, darwin17.0 |
|ui |X11 |
|language |(EN) |
|collate |en_US.UTF-8 |
|ctype |en_US.UTF-8 |
|tz |US/Pacific |
|date |2021-05-31 |
|field |value |
|:--------|:-----------------------------------|
|version |R version 4.3.2 (2023-10-31) |
|os |macOS Ventura 13.6.3 |
|system |aarch64, darwin20 |
|ui |X11 |
|language |(EN) |
|collate |en_US.UTF-8 |
|ctype |en_US.UTF-8 |
|tz |America/Los_Angeles |
|date |2024-01-09 |
|pandoc |3.1.11.1 @ /opt/homebrew/bin/pandoc |

# Dependencies

|package |old |new |Δ |
|:-------|:-----|:-----|:--|
|vcr |1.0.0 |1.0.2 |* |
|package |old |new |Δ |
|:---------|:-----|:--------|:--|
|vcr |1.2.2 |1.2.2.91 |* |
|askpass |NA |1.2.0 |* |
|curl |NA |5.2.0 |* |
|httr |NA |1.4.7 |* |
|openssl |NA |2.1.1 |* |
|Rcpp |NA |1.0.11 |* |
|rprojroot |NA |2.0.4 |* |
|sys |NA |3.4.2 |* |
|triebeard |NA |0.4.1 |* |
|whisker |NA |0.4.1 |* |
|yaml |NA |2.3.8 |* |

# Revdeps

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 52 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package.
We checked 66 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package.

* We saw 0 new problems
* We failed to check 0 packages
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/helper-vcr.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,12 @@ codes <- vapply(out, "[[", 1, "status_code")
if (!any(codes == 200)) stop("all httpbin servers down")
base_url <- urls[codes == 200][1]
cat(paste0("using base url for tests: ", base_url), sep = "\n")

# httpbin local
local_httpbin_app <- function() {
check_for_a_pkg("webfakes")
webfakes::local_app_process(
webfakes::httpbin_app(),
.local_envir = testthat::teardown_env()
)
}
33 changes: 33 additions & 0 deletions tests/testthat/test-localhost_port.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# orginally via https://github.com/ropensci/vcr/issues/264

tmpdir <- tempdir()
vcr_configure(dir = tmpdir)

test_that("testing against localhost port works", {
# httpbin <- webfakes::local_app_process(webfakes::httpbin_app())
httpbin <- local_httpbin_app()
url <- httpbin$url("/status/404")
port <- httpbin$get_port()

# real request w/o vcr
resp <- httr::GET(url)
expect_s3_class(resp, "response")

# real request w/ vcr
use_cassette("localhost_port", {
resp <- httr::GET(url)
# check that response object is correct
expect_s3_class(resp, "response")
})

# check that the port is actually in the cassette file
path <- file.path(tmpdir, "localhost_port.yml")
file <- yaml::yaml.load_file(path)
url <- file$http_interactions[[1]]$request$uri
expect_is(url, "character")
expect_match(url, "http://.+:[0-9]+/")
expect_match(url, as.character(port))
})

# reset configuration
vcr_configure_reset()

0 comments on commit a527d82

Please sign in to comment.