capture_requests: Capture and record database transactions and save them as...

Description Usage Arguments Details Value Examples

Description

When creating database fixtures, it can sometimes be helpful to see record the responses from the database for use in crafting tests.

Usage

1
2
3

Arguments

path

the path to record mocks (default if missing: the first path in .mockPaths().

Details

You can start capturing with start_capturing() and end it with stop_capturing. All queries run against a database will be executed like normal, but their responses will be saved to the mock path given, so that if you use the same queries later inside of a with_mock_db block, the database functions will return as if they had been run against the database.

note You should always call DBI::dbConnect inside of the capturing block. When you connect to the database, dbtest sets up the mocks for the specific database you're connecting to when you call DBI::dbConnect.

Value

NULL (invisibily)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
start_capturing()
con <- dbConnect(RSQLite::SQLite(), "memory")

df_1 <- dbGetQuery(con, "SELECT * FROM rpostgresql.airlines LIMIT 1")
res <- dbSendQuery(con, "SELECT * FROM rpostgresql.airlines LIMIT 2")
df_2 <- dbFetch(res)

dbDisconnect(con)
stop_capturing()

## End(Not run)

pachamaltese/dbtest documentation built on Dec. 3, 2019, 11:08 p.m.