Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start on a vcr workflows chapter #94

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _bookdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rmd_files: ["index.Rmd",
"conclusion.Rmd",
"03-mocking.Rmd", "04-webmockr-stubs.Rmd", "05-webmockr-testing.Rmd",
"06-webmockr-utilities.Rmd", "07-vcr.Rmd", "08-vcr-usage.Rmd", "09-configuration.Rmd",
"10-record-modes.Rmd", "11-request-matching.Rmd", "12-logging.Rmd", "13-security.Rmd",
"vcr-workflow.Rmd", "10-record-modes.Rmd", "11-request-matching.Rmd", "12-logging.Rmd", "13-security.Rmd",
"14-escape-hatches.Rmd", "15-cassettes.Rmd", "16-gotchas.Rmd",
"18-session-info.Rmd", "404.Rmd"]
before_chapter_script: "_common.R"
before_chapter_script: "_common.R"
66 changes: 66 additions & 0 deletions vcr-workflow.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# vcr workflows {#vcr-workflows}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this not a vignette with an Rmd fragment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do


- Re-recording cassettes
- Making sure vcr is working
- Make tasks

## Re-recording cassettes {#vcr-re-recording}

There are a number of reasons why you may want to re-record your cassettes:

1. `vcr`/`webmockr` upgrades: you may want to re-record your cassettes if
you've recently upgraded either of these packages. There should in general
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's unclear to me whether it's really useful since there should be no problem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by "there should be no problem?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a sentence that you wrote in this paragraph, "There should in general be no problem (...)" so I wonder when it is useful.

be no problem if you do not re-record your cassettes when using new versions
of `vcr`/`webmockr`. Cassettes record the version of `vcr`/`webmockr` they
were recorded with.
2. Code linked to cassette has changed in a way that would lead to different
request/response. Whenever your code has changed leading to different request
and/or response you should record a new cassette.
3. Remote API has changed leading to a different response. In this case the
HTTP request is likely identical to the one on the cassette, but since the
remote API response has changed, you should record a new cassette. Note that
matching HTTP requests is not done on HTTP responses, but if your tests
check any aspect of the response then you'll likely want to re-record
your cassettes.

How do you re-record a cassette?

This can be as simple as deleting existing cassettes and running tests again,
which should record new cassettes.

Another option is to use the vcr configuration option [re_record_interval][rri].
With this option you can set a time in seconds after which a new cassette
will be recorded, deleting the old one first. This will help make sure your
cassettes have up to date HTTP response bodies from the remote API; helping
you avoid cases where you're essentially testing old API behavior.

## Making sure vcr is working {#vcr-working}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well not vcr but more something like "Making sure your vcr infrastructure is working"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, will make that change


How do you know vcr is working without internet access?

- Make sure you have recorded cassettes. Then turn WI-FI off. Now run tests again.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that tip is also earlier in the book because it's an excellent tip you had given me!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh good. okay to duplicate here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes!

If tests behave the same exact way while WI-FI was on, then your tests are not
dependent on an internet connection. Note that this exercise may reveal that
you have some tests that do not use vcr that do require an internet connection
that you weren't aware of, or had forgotten about.

Can my tests run in the absence of my API key?

- After cassettes are recorded, you can temporarily disable your key by replacing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add examples of how you'd do that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

the real key with an invalid key. Then run tests again, then re-enable your key. While
you your key was disabled your tests should still pass.


## Make tasks {#vcr-make-tasks}

Make is a build automation tool used across programming languages. You use Make
through the command `make`, which looks up commands you define in a `Makefile`.
See [Wikipedia][mf] for a general overview of Make and the Makefile.

(waiting on https://github.com/ropensci/vcr/issues/103)




[rri]: https://docs.ropensci.org/vcr/reference/vcr_configure.html#configurable-settings
[mf]: https://en.wikipedia.org/wiki/Make_(software)#Makefile