tests/testthat/test_set_api_key.R

context("test set_api_key")

tmp <- tempfile()
api_key <- "foobar"

testthat::test_that("test that the set api key function creates a file with the api key", {
  
  # mock out the askpass function because we do not want interactivity in the tests
  mockery::stub(newsanchor::set_api_key, "askpass::askpass", api_key)
  
  newsanchor::set_api_key(path = tmp)
  
  # test that the temp file exists
  testthat::expect_true(file.exists(tmp))
  content <- readLines(tmp) # read content
  testthat::expect_true(content == paste0("NEWS_API_KEY=", api_key))
})

testthat::teardown({
  file.remove(tmp)
})

Try the newsanchor package in your browser

Any scripts or data that you put into this service are public.

newsanchor documentation built on June 29, 2019, 5:02 p.m.