Learn R Programming

httptest (version 3.0.0)

start_vignette: Set mocking/capturing state for a vignette

Description

Use start_vignette() to either use previously recorded responses or capture real responses for future use, depending on the value of the RECORD environment variable.

Usage

start_vignette(path, ...)

end_vignette()

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

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.

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.

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