Skip to content

Add an example filter to vcr_configure#299

Open
RichardLitt wants to merge 1 commit into
ropensci:mainfrom
RichardLitt:patch-1
Open

Add an example filter to vcr_configure#299
RichardLitt wants to merge 1 commit into
ropensci:mainfrom
RichardLitt:patch-1

Conversation

@RichardLitt
Copy link
Copy Markdown

Description

This adds a simple example to the help docs that shows how to use regex to filter data, using vcr_configure.

Related Issue

See #272 (comment).

@sckott
Copy link
Copy Markdown
Collaborator

sckott commented Apr 12, 2025

Thanks I'll have a look soon

@RichardLitt
Copy link
Copy Markdown
Author

No rush at all.

@sckott sckott added this to the v2.0 milestone Apr 13, 2025
@sckott sckott added the docs label Apr 13, 2025
@sckott
Copy link
Copy Markdown
Collaborator

sckott commented May 13, 2025

@RichardLitt sorry, holding off on this for now because looks like we'll deprecate the regex option but have a new way to do it #481 #482

@RichardLitt
Copy link
Copy Markdown
Author

All good, I'm not tied to it.

@sckott
Copy link
Copy Markdown
Collaborator

sckott commented Jun 11, 2025

@RichardLitt Hey, can you install vcr from main and see if the example you added works for you with rebird? If not, i'll help figure out what to change

@RichardLitt
Copy link
Copy Markdown
Author

I am not sure that it does. It worked for v1.7.0. Now, however:

> remotes::install_github("ropensci/vcr@main")
Using GitHub PAT from the git credential store.
Downloading GitHub repo ropensci/vcr@main
These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?

1: All                               
2: CRAN packages only                
3: None                              
4: urltools (1.7.3 -> 1.7.3.1) [CRAN]
5: curl     (6.2.2 -> 6.3.0  ) [CRAN]
6: cli      (3.6.4 -> 3.6.5  ) [CRAN]
7: diffobj  (0.3.5 -> 0.3.6  ) [CRAN]
8: webmockr (1.0.0 -> 2.0.0  ) [CRAN]

Enter one or more numbers, or an empty line to skip updates: 1
urltools (1.7.3 -> 1.7.3.1) [CRAN]
curl     (6.2.2 -> 6.3.0  ) [CRAN]
cli      (3.6.4 -> 3.6.5  ) [CRAN]
diffobj  (0.3.5 -> 0.3.6  ) [CRAN]
webmockr (1.0.0 -> 2.0.0  ) [CRAN]
Installing 5 packages: urltools, curl, cli, diffobj, webmockr
trying URL 'https://cloud.r-project.org/bin/macosx/big-sur-x86_64/contrib/4.4/urltools_1.7.3.tgz'
Content type 'application/x-gzip' length 987162 bytes (964 KB)
==================================================
downloaded 964 KB

trying URL 'https://cloud.r-project.org/bin/macosx/big-sur-x86_64/contrib/4.4/curl_6.2.3.tgz'
Content type 'application/x-gzip' length 3354278 bytes (3.2 MB)
==================================================
downloaded 3.2 MB

trying URL 'https://cloud.r-project.org/bin/macosx/big-sur-x86_64/contrib/4.4/cli_3.6.5.tgz'
Content type 'application/x-gzip' length 1465223 bytes (1.4 MB)
==================================================
downloaded 1.4 MB

trying URL 'https://cloud.r-project.org/bin/macosx/big-sur-x86_64/contrib/4.4/diffobj_0.3.6.tgz'
Content type 'application/x-gzip' length 1028991 bytes (1004 KB)
==================================================
downloaded 1004 KB

trying URL 'https://cloud.r-project.org/bin/macosx/big-sur-x86_64/contrib/4.4/webmockr_2.0.0.tgz'
Content type 'application/x-gzip' length 791261 bytes (772 KB)
==================================================
downloaded 772 KB


The downloaded binary packages are in
	/var/folders/vp/bfx6rdf97lj71rj8720bb7qr0000gn/T//RtmpWSGMit/downloaded_packages
── R CMD build ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔  checking for file ‘/private/var/folders/vp/bfx6rdf97lj71rj8720bb7qr0000gn/T/RtmpWSGMit/remotes112e9328c9b17/ropensci-vcr-dd9c3fe/DESCRIPTION’ ...
─  preparing ‘vcr’:
✔  checking DESCRIPTION meta-information ...
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘vcr_1.7.0.91.tar.gz’
   
* installing *source* package ‘vcr’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (vcr)
> packageVersion("vcr")
[1] ‘1.7.0.91’
> devtools::test(filter = 'DEMO')
ℹ Testing rebird
✔ | F W  S  OK | Context
✖ | 1        0 | DEMO                                                                                                             
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Error (test-DEMO.R:3:5): DEMO
Error: 

================================================================================
An HTTP request has been made that vcr does not know how to handle:
GET http://ipinfo.io
vcr is currently using the following cassette:
  - /Users/richard/src/rebird/tests/fixtures/DEMO.yml
    - record_mode: once
    - match_requests_on: method, uri
Run `vcr::vcr_last_error()` for more verbose errors
If you're not sure what to do, open an issue https://github.com/ropensci/vcr/issues
& see https://books.ropensci.org/http-testing
================================================================================


Backtrace:
     ▆
  1. └─rebird::getlatlng() at test-DEMO.R:3:5
  2.   ├─jsonlite::fromJSON(...) at rebird/R/getlatlng.R:15:3
  3.   ├─httr::content(GET("http://ipinfo.io"), as = "text", encoding = "UTF-8")
  4.   │ ├─base::stopifnot(is.response(x))
  5.   │ └─httr:::is.response(x)
  6.   └─httr::GET("http://ipinfo.io")
  7.     └─httr:::request_perform(req, hu$handle$handle)
  8.       └─httr:::perform_callback("request", req = req)
  9.         └─webmockr (local) callback(...)
 10.           └─webmockr::HttrAdapter$new()$handle_request(req)
 11.             └─private$request_handler(req)$handle()
 12.               └─eval(parse(text = req_type_fun))(self$request)
 13.                 └─err$run()
 14.                   └─self$construct_message()
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

══ Results ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
── Failed tests ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Error (test-DEMO.R:3:5): DEMO
Error: 

================================================================================
An HTTP request has been made that vcr does not know how to handle:
GET http://ipinfo.io
vcr is currently using the following cassette:
  - /Users/richard/src/rebird/tests/fixtures/DEMO.yml
    - record_mode: once
    - match_requests_on: method, uri
Run `vcr::vcr_last_error()` for more verbose errors
If you're not sure what to do, open an issue https://github.com/ropensci/vcr/issues
& see https://books.ropensci.org/http-testing
================================================================================


Backtrace:
     ▆
  1. └─rebird::getlatlng() at test-DEMO.R:3:5
  2.   ├─jsonlite::fromJSON(...) at rebird/R/getlatlng.R:15:3
  3.   ├─httr::content(GET("http://ipinfo.io"), as = "text", encoding = "UTF-8")
  4.   │ ├─base::stopifnot(is.response(x))
  5.   │ └─httr:::is.response(x)
  6.   └─httr::GET("http://ipinfo.io")
  7.     └─httr:::request_perform(req, hu$handle$handle)
  8.       └─httr:::perform_callback("request", req = req)
  9.         └─webmockr (local) callback(...)
 10.           └─webmockr::HttrAdapter$new()$handle_request(req)
 11.             └─private$request_handler(req)$handle()
 12.               └─eval(parse(text = req_type_fun))(self$request)
 13.                 └─err$run()
 14.                   └─self$construct_message()

[ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ]

@sckott
Copy link
Copy Markdown
Collaborator

sckott commented Jun 17, 2025

@RichardLitt so I think you need to restart R before you run the test after installing vcr. The packageVersion("vcr") call shows the right version, but I think the R session is using the old vcr since that error message is from the old R version.

@sckott sckott removed this from the v2.0 milestone Jun 27, 2025
@RichardLitt
Copy link
Copy Markdown
Author

Yes, it appears to work with rebird. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants