Skip to content

Add a name parameter to allow for different fixtures #178

@Kjir

Description

@Kjir

It would be quite handy to be able to test the behaviour of the code with different results from the query: what if the table is empty? What if the table has more (or less) rows than the pagination limit?

I would expect to be able to provide a name to the asset, so that the same query can be registered with different outcomes. This would probably indirectly solve #159 as well.

Example code:

start_db_capturing("no-airlines")

con <- DBI::dbConnect(
  RPostgres::Postgres(),
  dbname = "nycflights"
)

get_an_airline(con)
DBI::dbDisconnect(con)

stop_db_capturing()

And test:

with_mock_db({
  con <- DBI::dbConnect(
    RPostgres::Postgres(),
    dbname = "nycflights"
  )
  
  test_that("We get no airline", {
    one_airline <- get_an_airline(con)
    expect_s3_class(one_airline, "data.frame")
    expect_equal(nrow(one_airline), 0)
  })
}, case = "no-airlines")

This would allow to use dittodb to run integration tests as well, instead of being able to test only the DB-to-R portion of the code.

In theory this could be achieved using with_mock_path, but it does feel clunkier

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions