tests/testthat/helper-with_mappy.R

library(testthatsomemore)

with_options <- function(options, expr) {
  old_options <- options(options)
  on.exit(options(old_options))
  eval.parent(substitute(expr))
}

with_mappy <- function(expr) {
  tempdir <- tempfile()
  unlink(tempdir, FALSE, TRUE)
  dir.create(tempdir, FALSE, TRUE)
  testthatsomemore::package_stub("base", "interactive", function() TRUE, {
    with_options(list(mappy.file = file.path(tempdir, "mappy")), {
      memoise::forget(registry_dir)
      memoise::forget(registry_obj)
      on.exit(unlink(tempdir, FALSE, TRUE))
      eval.parent(substitute(expr))
    })
  })
}
robertzk/mappy documentation built on May 27, 2019, 10:34 a.m.