Skip to content

Commit

Permalink
Decouple edition setting in capture vs expect_snapshot()
Browse files Browse the repository at this point in the history
This is appears to be some sort of change in behaviour in withr 2.5.0 vs 3.0.0.

The key point is to capture the checklist with testthat 2e in force, while still being able to execute expect_snapshot(), which requires testhat 3e.

The changes around the DESCRIPTION file in the test package are separate and are just about making it look more like the DESCRIPTION file of a package who hasn't updated to testthat 3e.
  • Loading branch information
jennybc committed Feb 13, 2024
1 parent a7d340c commit 175bf64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 1 addition & 2 deletions tests/testthat/_snaps/upkeep.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@
---

Code
local_edition(2L)
writeLines(upkeep_checklist())
writeLines(checklist)
Output
* [ ] `usethis::use_readme_rmd()`
* [ ] `usethis::use_github_links()`
Expand Down
18 changes: 14 additions & 4 deletions tests/testthat/test-upkeep.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,26 @@ test_that("upkeep bullets don't change accidentally",{

expect_snapshot(writeLines(upkeep_checklist()))

# Add some files to test conditional todos
# Test some conditional TODOs
use_code_of_conduct("[email protected]")
use_testthat()
writeLines("# test environment\n", "cran-comments.md")
local_mocked_bindings(git_default_branch = function() "master")

expect_snapshot({
# Look like a package that hasn't switched to testthat 3e yet
use_testthat()
desc::desc_del("Config/testthat/edition")
desc::desc_del("Suggests")
use_package("testthat", "Suggests")

# previously (withr 2.5.0) we could put local_edition(2L) inside {..} inside
# the expect_snapshot() call
# that is no longer true with withr 3.0.0, but this hacktastic approach works
local({
local_edition(2L)
writeLines(upkeep_checklist())
checklist <<- upkeep_checklist()
})

expect_snapshot(writeLines(checklist))
})

test_that("get extra upkeep bullets works", {
Expand Down

0 comments on commit 175bf64

Please sign in to comment.