When testing with dittodb, wrap your tests in with_mock_db({}) to use the database fixtures. dittodb will look for fixtures in all entries of .db_mock_paths.

with_mock_db(expr)

Arguments

expr

the expression to execute

Value

nothing

Details

Connections should be made inside of with_mock_db() because dittodb uses the database name (given in dbname or Database argument of dbConnect depending on the driver) to separate different fixtures.

Examples

if (FALSE) { with_mock_db({ con <- dbConnect( RPostgreSQL::PostgreSQL(), dbname = "nycflights", host = "127.0.0.1", user = "travis", password = "" ) test_that("We get one airline", { one_airline <- dbGetQuery( con, "SELECT carrier, name FROM airlines LIMIT 1" ) expect_is(one_airline, "data.frame") expect_equal(nrow(one_airline), 1) expect_equal(one_airline$carrier, "9E") expect_equal(one_airline$name, "Endeavor Air Inc.") }) }) }