Configurable options that define vcr's default behavior.

vcr_configure(...)

vcr_configure_reset()

vcr_configuration()

vcr_config_defaults()

Arguments

...

configuration settings used to override defaults. See below for a complete list of valid arguments.

Configurable settings

vcr options

File locations

  • dir Cassette directory

  • write_disk_path (character) path to write files to for any requests that write responses to disk. by default this parameter is NULL. For testing a package, you'll probably want this path to be in your tests/ directory, perhaps next to your cassettes directory, e.g., where your cassettes are in tests/fixtures, your files from requests that write to disk are in tests/files. If you want to ignore these files in your installed package, add them to .Rinstignore. If you want these files ignored on build then add them to .Rbuildignore (though if you do, tests that depend on these files probably will not work because they won't be found; so you'll likely have to skip the associated tests as well).

Contexts

  • turned_off (logical) VCR is turned on by default. Default: FALSE

  • allow_unused_http_interactions (logical) Default: TRUE

  • allow_http_connections_when_no_cassette (logical) Determines how vcr treats HTTP requests that are made when no vcr cassette is in use. When TRUE, requests made when there is no vcr cassette in use will be allowed. When FALSE (default), an UnhandledHTTPRequestError error will be raised for any HTTP request made when there is no cassette in use

Filtering

  • ignore_hosts (character) Vector of hosts to ignore. e.g., localhost, or google.com. These hosts are ignored and real HTTP requests allowed to go through

  • ignore_localhost (logical) Default: FALSE

  • ignore_request List of requests to ignore. NOT USED RIGHT NOW, sorry

  • filter_sensitive_data named list of values to replace. Format is:

    list(thing_to_replace_it_with = thing_to_replace)
    

    We replace all instances of thing_to_replace with thing_to_replace_it_with. Uses gsub() internally, with fixed=TRUE; so does exact matches. Before recording (writing to a cassette) we do the replacement and then when reading from the cassette we do the reverse replacement to get back to the real data. Before record replacement happens in internal function write_interactions(), while before playback replacement happens in internal function YAML$deserialize()

  • filter_sensitive_data_regex named list of values to replace. Follows filter_sensitive_data format, except uses fixed=FALSE in the gsub() function call; this means that the value in thing_to_replace is a regex pattern.

  • filter_request_headers (character/list) request headers to filter. A character vector of request headers to remove - the headers will not be recorded to disk. Alternatively, a named list similar to filter_sensitive_data instructing vcr with what value to replace the real value of the request header.

  • filter_response_headers (named list) response headers to filter. A character vector of response headers to remove - the headers will not be recorded to disk. Alternatively, a named list similar to filter_sensitive_data instructing vcr with what value to replace the real value of the response header.

  • filter_query_parameters (named list) query parameters to filter. A character vector of query parameters to remove - the query parameters will not be recorded to disk. Alternatively, a named list similar to filter_sensitive_data instructing vcr with what value to replace the real value of the query parameter.

Errors

  • verbose_errors Do you want more verbose errors or less verbose errors when cassette recording/usage fails? Default is FALSE, that is, less verbose errors. If TRUE, error messages will include more details about what went wrong and suggest possible solutions. For testing in an interactive R session, if verbose_errors=FALSE, you can run vcr_last_error() to get the full error. If in non-interactive mode, which most users will be in when running the entire test suite for a package, you can set an environment variable (VCR_VERBOSE_ERRORS) to toggle this setting (e.g., Sys.setenv(VCR_VERBOSE_ERRORS=TRUE); devtools::test())

Internals

  • cassettes (list) don't use

  • linked_context (logical) linked context

  • uri_parser the uri parser, default: crul::url_parse()

Logging

  • log (logical) should we log important vcr things? Default: FALSE

  • log_opts (list) Additional logging options:

    • 'file' either "console" or a file path to log to

    • 'log_prefix' default: "Cassette". We insert the cassette name after that prefix, then the rest of the message.

    • More to come...

Cassette Options

These settings can be configured globally, using vcr_configure(), or locally, using either use_cassette() or insert_cassette(). Global settings are applied to all cassettes but are overridden by settings defined locally for individual cassettes.

  • record (character) One of 'all', 'none', 'new_episodes', or 'once'. See recording

  • match_requests_on vector of matchers. Default: (method, uri) See request-matching for details.

  • serialize_with: (character) "yaml" or "json". Note that you can have multiple cassettes with the same name as long as they use different serializers; so if you only want one cassette for a given cassette name, make sure to not switch serializers, or clean up files you no longer need.

  • json_pretty: (logical) want JSON to be newline separated to be easier to read? Or remove newlines to save disk space? default: FALSE

  • persist_with (character) only option is "FileSystem"

  • preserve_exact_body_bytes (logical) preserve exact body bytes for

  • re_record_interval (numeric) When given, the cassette will be re-recorded at the given interval, in seconds.

  • clean_outdated_http_interactions (logical) Should outdated interactions be recorded back to file. Default: FALSE

  • quiet (logical) Suppress any messages from both vcr and webmockr. Default: TRUE

  • warn_on_empty_cassette (logical) Should a warning be thrown when an empty cassette is detected? Empty cassettes are cleaned up (deleted) either way. This option only determines whether a warning is thrown or not. Default: FALSE

Examples

vcr_configure(dir = tempdir())
#> <vcr configuration> #> Cassette Dir: /tmp/RtmpIWwim8 #> Record: once #> Serialize with: yaml #> URI Parser: crul::url_parse #> Match Requests on: method, uri #> Preserve Bytes?: FALSE #> Logging?: FALSE #> ignored hosts: #> ignore localhost?: FALSE #> Write disk path:
vcr_configure(dir = tempdir(), record = "all")
#> <vcr configuration> #> Cassette Dir: /tmp/RtmpIWwim8 #> Record: all #> Serialize with: yaml #> URI Parser: crul::url_parse #> Match Requests on: method, uri #> Preserve Bytes?: FALSE #> Logging?: FALSE #> ignored hosts: #> ignore localhost?: FALSE #> Write disk path:
vcr_configuration()
#> <vcr configuration> #> Cassette Dir: /tmp/RtmpIWwim8 #> Record: all #> Serialize with: yaml #> URI Parser: crul::url_parse #> Match Requests on: method, uri #> Preserve Bytes?: FALSE #> Logging?: FALSE #> ignored hosts: #> ignore localhost?: FALSE #> Write disk path:
vcr_config_defaults()
#> $warn_on_empty_cassette #> [1] TRUE #> #> $quiet #> [1] TRUE #> #> $verbose_errors #> [1] FALSE #> #> $write_disk_path #> NULL #> #> $filter_query_parameters #> NULL #> #> $filter_response_headers #> NULL #> #> $filter_request_headers #> NULL #> #> $filter_sensitive_data_regex #> NULL #> #> $filter_sensitive_data #> NULL #> #> $log_opts #> $log_opts$file #> [1] "vcr.log" #> #> $log_opts$log_prefix #> [1] "Cassette" #> #> $log_opts$date #> [1] TRUE #> #> #> $log #> [1] FALSE #> #> $linked_context #> NULL #> #> $cassettes #> list() #> #> $allow_http_connections_when_no_cassette #> [1] FALSE #> #> $clean_outdated_http_interactions #> [1] FALSE #> #> $re_record_interval #> NULL #> #> $turned_off #> [1] FALSE #> #> $preserve_exact_body_bytes #> [1] FALSE #> #> $uri_parser #> [1] "crul::url_parse" #> #> $ignore_request #> NULL #> #> $ignore_localhost #> [1] FALSE #> #> $ignore_hosts #> NULL #> #> $persist_with #> [1] "FileSystem" #> #> $json_pretty #> [1] FALSE #> #> $serialize_with #> [1] "yaml" #> #> $allow_unused_http_interactions #> [1] TRUE #> #> $match_requests_on #> [1] "method" "uri" #> #> $record #> [1] "once" #> #> $dir #> [1] "." #>
vcr_configure(dir = tempdir(), ignore_hosts = "google.com")
#> <vcr configuration> #> Cassette Dir: /tmp/RtmpIWwim8 #> Record: all #> Serialize with: yaml #> URI Parser: crul::url_parse #> Match Requests on: method, uri #> Preserve Bytes?: FALSE #> Logging?: FALSE #> ignored hosts: google.com #> ignore localhost?: FALSE #> Write disk path:
vcr_configure(dir = tempdir(), ignore_localhost = TRUE)
#> <vcr configuration> #> Cassette Dir: /tmp/RtmpIWwim8 #> Record: all #> Serialize with: yaml #> URI Parser: crul::url_parse #> Match Requests on: method, uri #> Preserve Bytes?: FALSE #> Logging?: FALSE #> ignored hosts: google.com #> ignore localhost?: TRUE #> Write disk path:
# logging vcr_configure(dir = tempdir(), log = TRUE, log_opts = list(file = file.path(tempdir(), "vcr.log")))
#> <vcr configuration> #> Cassette Dir: /tmp/RtmpIWwim8 #> Record: all #> Serialize with: yaml #> URI Parser: crul::url_parse #> Match Requests on: method, uri #> Preserve Bytes?: FALSE #> Logging?: TRUE (/tmp/RtmpIWwim8/vcr.log) #> ignored hosts: google.com #> ignore localhost?: TRUE #> Write disk path:
vcr_configure(dir = tempdir(), log = TRUE, log_opts = list(file = "console"))
#> <vcr configuration> #> Cassette Dir: /tmp/RtmpIWwim8 #> Record: all #> Serialize with: yaml #> URI Parser: crul::url_parse #> Match Requests on: method, uri #> Preserve Bytes?: FALSE #> Logging?: TRUE (console) #> ignored hosts: google.com #> ignore localhost?: TRUE #> Write disk path:
vcr_configure(dir = tempdir(), log = TRUE, log_opts = list( file = file.path(tempdir(), "vcr.log"), log_prefix = "foobar" ))
#> <vcr configuration> #> Cassette Dir: /tmp/RtmpIWwim8 #> Record: all #> Serialize with: yaml #> URI Parser: crul::url_parse #> Match Requests on: method, uri #> Preserve Bytes?: FALSE #> Logging?: TRUE (/tmp/RtmpIWwim8/vcr.log) #> ignored hosts: google.com #> ignore localhost?: TRUE #> Write disk path:
vcr_configure(dir = tempdir(), log = FALSE)
#> <vcr configuration> #> Cassette Dir: /tmp/RtmpIWwim8 #> Record: all #> Serialize with: yaml #> URI Parser: crul::url_parse #> Match Requests on: method, uri #> Preserve Bytes?: FALSE #> Logging?: FALSE #> ignored hosts: google.com #> ignore localhost?: TRUE #> Write disk path:
# filter sensitive data vcr_configure(dir = tempdir(), filter_sensitive_data = list(foo = "<bar>") )
#> <vcr configuration> #> Cassette Dir: /tmp/RtmpIWwim8 #> Record: all #> Serialize with: yaml #> URI Parser: crul::url_parse #> Match Requests on: method, uri #> Preserve Bytes?: FALSE #> Logging?: FALSE #> ignored hosts: google.com #> ignore localhost?: TRUE #> Write disk path:
vcr_configure(dir = tempdir(), filter_sensitive_data = list(foo = "<bar>", hello = "<world>") )
#> <vcr configuration> #> Cassette Dir: /tmp/RtmpIWwim8 #> Record: all #> Serialize with: yaml #> URI Parser: crul::url_parse #> Match Requests on: method, uri #> Preserve Bytes?: FALSE #> Logging?: FALSE #> ignored hosts: google.com #> ignore localhost?: TRUE #> Write disk path: