Description Usage Arguments Details Value Examples
When testing with dbtest, wrap your tests in with_mock_db({})
to use the
database fixtures. dbtest
will look for fixtures in all entries of
.mockPaths
.
1 | with_mock_db(expr)
|
expr |
the expression to execute |
Connections should be made inside of with_mock_db()
because dbtest
uses
the database name (given in dbname
or Database
argument of dbConnect
depending on the driver) to separate different fixtures.
nothing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ## Not run:
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.")
})
})
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.