Skip to content

Commit

Permalink
Apply workshop (#30)
Browse files Browse the repository at this point in the history
* Simplify helper.

* Cleaner cleaners.
  • Loading branch information
jonthegeek authored Oct 5, 2023
1 parent 4e75d90 commit 8106cae
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 37 deletions.
1 change: 0 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
url: https://jonthegeek.github.io/beekeeper/
template:
bootstrap: 5

41 changes: 8 additions & 33 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@

create_local_package <- function(pkgname = "testpkg",
env = parent.frame()) {
dir <- fs::file_temp(pattern = pkgname)
withr::local_options(usethis.quiet = TRUE, .local_envir = env)

old_wd <- getwd()
dir <- withr::local_tempdir(pattern = pkgname, .local_envir = env)

withr::defer(
{
fs::dir_delete(dir)
},
envir = env
)
usethis::create_package(
dir,
# This is for the sake of interactive development of snapshot tests.
# When the active usethis project is a package created with this
# function, testthat learns its edition from *that* package, not from
# usethis. So, by default, opt in to testthat 3e in these ephemeral test
# packages.
# I also need a url to check for it in user agent.
# I need a url to check for it in user agent.
fields = list(
"URL" = "https://example.com",
"Config/testthat/edition" = "3"
Expand All @@ -29,23 +18,9 @@ create_local_package <- function(pkgname = "testpkg",
check_name = FALSE
)

old_project <- usethis::proj_set(dir)
withr::defer(
{
usethis::proj_set(old_project, force = TRUE)
},
envir = env
)

withr::defer(
{
setwd(old_wd)
},
envir = env
)
setwd(usethis::proj_get())
usethis::local_project(dir, quiet = TRUE, .local_envir = env)

invisible(usethis::proj_get())
invisible(dir)
}

scrub_testpkg <- function(text) {
Expand All @@ -55,15 +30,15 @@ scrub_testpkg <- function(text) {
scrub_updated <- function(input) {
sub(
"updated_on:.*$",
"updated_on: DATETIME\"",
"updated_on: DATETIME",
input
)
}

scrub_rapid_file_location <- function(input) {
sub(
"rapid_file: file.*$",
"rapid_file: RAPID_FILE_PATH\"",
"rapid_file: .*$",
"rapid_file: RAPID_FILE_PATH",
input
)
}
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-generate.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
withr::local_options(usethis.quiet = TRUE)

test_that("generate_pkg() adds beekeeper to suggests.", {
skip_on_cran()
config <- readLines(test_path("_fixtures", "guru_beekeeper.yml"))
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-use_beekeeper.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ test_that("config writes a yml", {
expected_result_file <- scrub_config(
readLines(test_path("_fixtures", "guru_beekeeper.yml"))
)
expected_result_file[[4]] <- "rapid_file: RAPID_FILE_PATH\""
expect_identical(
test_result_file,
expected_result_file
Expand Down

0 comments on commit 8106cae

Please sign in to comment.