-
Notifications
You must be signed in to change notification settings - Fork 17
/
07-vcr.Rmd
59 lines (36 loc) · 1.86 KB
/
07-vcr.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# (PART) vcr details {-}
# Caching HTTP requests {#vcr-intro}
Record HTTP calls and replay them
## Package documentation {#vcr-pkgdown}
Check out <https://docs.ropensci.org/vcr/> for documentation on `vcr` functions.
## Terminology {#terminology}
```{r, echo=FALSE}
get_vcr_doc("man/rmdhunks/glossary.Rmd")
```
```{r child='rmd-fragments/man/rmdhunks/glossary.Rmd', eval=TRUE}
```
## Design {#design}
```{r, echo=FALSE}
get_vcr_doc("man/rmdhunks/vcr-design.Rmd")
```
```{r child='rmd-fragments/man/rmdhunks/vcr-design.Rmd', eval=TRUE}
```
## Basic usage {#vcr-basic-usage}
```{r, echo=FALSE}
get_vcr_doc("man/rmdhunks/basic-usage.Rmd")
```
```{r child='rmd-fragments/man/rmdhunks/basic-usage.Rmd', eval=TRUE}
```
All components of both the request and response are preserved, so that the HTTP client (in this case `crul`) can reconstruct its own response just as it would if it wasn't using `vcr`.
## vcr enabled testing {#vcr-enabled-testing}
### check vs. test {#check-vs-test}
> TLDR: Run `devtools::test()` before running `devtools::check()` for recording your cassettes.
When running tests or checks of your whole package, note that you'll get different results with
`devtools::check()` (check button of RStudio build pane) vs. `devtools::test()` (test button of RStudio build pane). This arises because `devtools::check()` runs in a
temporary directory and files created (vcr cassettes) are only in that temporary directory and
thus don't persist after `devtools::check()` exits.
However, `devtools::test()` does not run in a temporary directory, so files created (vcr
cassettes) are in whatever directory you're running it in.
Alternatively, you can run `devtools::test_file()` (or the "Run test" button in RStudio) to create your vcr cassettes one test file at a time.
### CI sites: GitHub Actions, Appveyor, etc. {#vcr-ci}
Refer to [the security chapter](#vcr-security).