Use start_vignette() to either use previously recorded responses, if they exist, or capture real responses for future use.

start_vignette(dir, ...)

end_vignette()

Arguments

dir

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()

Value

Nothing; called for its side effect of starting/ending response recording or mocking.

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.

As in with_mock_dir(), the behavior changes based on the existence of the dir 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 dir. On subsequent runs, the mocks will be used. To record fresh responses from the server, delete the dir 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/httptest2/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/httptest2/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 = "httptest2") for an overview of all