Use start_vignette()
to either use previously recorded responses, if they
exist, or capture real responses for future use.
Arguments
- path
Root file path for the mocks for this vignette. A good idea is to use the file name of the vignette itself.
- ...
Optional arguments passed to
start_capturing()
Details
In a vignette or other R Markdown or Sweave document, place
start_vignette()
in an R code block at the beginning,
before the first API request is made, and put
end_vignette()
in a R code chunk at the end. You may
want to make those R code chunks have echo=FALSE
in order to hide the fact
that you're calling them.
The behavior changes based on the existence of the path
directory. The
first time you build the vignette, the directory won't exist yet, so it will
make real requests and record them inside of path
. On subsequent runs, the
mocks will be used. To record fresh responses from the server, delete the
path
directory, and the responses will be recorded again the next time the
vignette runs.
If you have additional setup code that you'd like available across all of
your package's vignettes, put it in inst/httptest/start-vignette.R
in your
package, and it will be called in start_vignette()
before the mock/record
context is set. Similarly, teardown code can go in
inst/httptest/end-vignette.R
, evaluated in end_vignette()
after mocking
is stopped.
See also
start_capturing()
for how requests are recorded; use_mock_api()
for how previously recorded requests are loaded; change_state()
for how to
handle recorded requests when the server state is changing;
vignette("vignettes", package="httptest")
for an overview of all