Skip to content

Commit 33f4694

Browse files
committed
Tweak message; improve frame hanlding
1 parent 36de017 commit 33f4694

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

R/snapshot-file.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ expect_snapshot_file <- function(
137137
path,
138138
file_equal = compare,
139139
variant = variant,
140-
trace_env = caller_env()
141140
)
142141
if (inherits(equal, "expectation_failure")) {
143142
return(equal)
@@ -204,7 +203,7 @@ snapshot_file_equal <- function(
204203
trace_env = caller_env()
205204
) {
206205
if (!file.exists(path)) {
207-
cli::cli_abort("{.path {path}} not found.")
206+
cli::cli_abort("{.path {path}} not found.", call = trace_env)
208207
}
209208

210209
if (is.null(snap_variant)) {

tests/testthat/DELETE-ME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
If you see me, something has gone wrong with old-school teardown

tests/testthat/DELETE-ME-2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
If you see me, something has gone wrong with new-school teardown

tests/testthat/_snaps/snapshot-file.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# expect_snapshot_file finds duplicate snapshot files
2+
3+
Code
4+
expect_snapshot_file(write_tmp_lines(r_version()), "version.txt", variant = r_version())
5+
Condition
6+
Error in `expect_snapshot_file()`:
7+
! Snapshot file names must be unique. `name` has already been used.
8+
19
# warns on first creation
210

311
Code
@@ -11,7 +19,7 @@
1119
Code
1220
snapshot_file_equal_("doesnt-exist.txt")
1321
Condition
14-
Error in `snapshot_file_equal()`:
22+
Error in `snapshot_file_equal_()`:
1523
! 'doesnt-exist.txt' not found.
1624

1725
# snapshot_hint output differs in R CMD check

tests/testthat/test-snapshot-file.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ test_that("expect_snapshot_file works with variant", {
3939
})
4040

4141
test_that("expect_snapshot_file finds duplicate snapshot files", {
42-
# Save to the same file as in previous test
43-
expect_error(
42+
expect_snapshot(
4443
expect_snapshot_file(
4544
write_tmp_lines(r_version()),
4645
"version.txt",
47-
compare = compare_file_text,
4846
variant = r_version()
4947
),
50-
"provide a unique snapshot file name"
48+
error = TRUE
5149
)
5250
})
5351

0 commit comments

Comments
 (0)