Skip to content

Commit f6d2949

Browse files
committed
Polishing announce_snapshot_file() docs
1 parent c45ce93 commit f6d2949

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

R/snapshot-file.R

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,23 @@
4141
#' written to the `_snaps` directory but which no longer have
4242
#' corresponding R code to generate them. These dangling files are
4343
#' automatically deleted so they don't clutter the snapshot
44-
#' directory. However we want to preserve snapshot files when the R
45-
#' code wasn't executed because of an unexpected error or because of a
46-
#' [skip()]. Let testthat know about these files by calling
47-
#' `announce_snapshot_file()` before `expect_snapshot_file()`.
44+
#' directory.
45+
#'
46+
#' This can cause problems if youre test is conditionally executed, either
47+
#' because of an `if` statement or a [skip()]. To avoid files being deleted in
48+
#' this case, you can call `announce_snapshot_file()` before the conditional
49+
#' code.
50+
#'
51+
#' ```R
52+
#' test_that("can save a file", {
53+
#' if (!can_save()) {
54+
#' announce_snapshot_file("data.txt")
55+
#' skip("Can't save file")
56+
#' }
57+
#' path <- withr::local_tempfile()
58+
#' expect_snasphot_file(save_file(path, mydata()), "data.txt")
59+
#' })
60+
#' ```
4861
#'
4962
#' @export
5063
#' @examples

man/expect_snapshot_file.Rd

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)