Skip to content

Commit 1380480

Browse files
committed
Elimiante no longer used argument
1 parent 3e31ea7 commit 1380480

File tree

4 files changed

+75
-8
lines changed

4 files changed

+75
-8
lines changed

R/snapshot-file.R

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ expect_snapshot_file <- function(
160160
if (in_check_reporter()) {
161161
hint <- ""
162162
} else {
163-
hint <- snapshot_review_hint(file, name, is_text = is_text)
163+
hint <- snapshot_review_hint(file, is_text = is_text)
164164
}
165165

166166
if (!equal) {
@@ -209,24 +209,21 @@ announce_snapshot_file <- function(path, name = basename(path)) {
209209

210210
snapshot_review_hint <- function(
211211
test,
212-
name,
213212
is_text = FALSE,
214213
reset_output = TRUE
215214
) {
216215
if (reset_output) {
217216
local_reporter_output()
218217
}
219218

220-
path <- paste0("tests/testthat/_snaps/", test, "/", new_name(name))
221-
222219
c(
223220
if (is_text) {
224221
cli::format_inline(
225222
"* Run {.run testthat::snapshot_accept('{test}/')} to accept the change."
226223
)
227224
},
228225
cli::format_inline(
229-
"* Run {.run testthat::snapshot_review('{test}/')} to review changes."
226+
"* Run {.run testthat::snapshot_review('{test}/')} to review the change."
230227
)
231228
)
232229
}

tests/testthat/_snaps/snapshot-file.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@
2525
# generates informative hint
2626

2727
Code
28-
cat(snapshot_review_hint("lala", "foo.r", reset_output = FALSE))
28+
base::writeLines(snapshot_review_hint("lala", reset_output = FALSE))
2929
Output
3030
* Run `testthat::snapshot_review('lala/')` to review changes.
3131

32+
---
33+
34+
Code
35+
base::writeLines(snapshot_review_hint("lala", is_text = TRUE, reset_output = FALSE))
36+
Output
37+
* Run `testthat::snapshot_accept('lala/')` to accept the change.
38+
* Run `testthat::snapshot_review('lala/')` to review changes.
39+
3240
# expect_snapshot_file validates its inputs
3341

3442
Code
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
9+
# warns on first creation
10+
11+
Code
12+
out <- snapshot_file_equal_(path)
13+
Condition
14+
Warning:
15+
Adding new file snapshot: 'tests/testthat/_snaps/my-test/test.txt'
16+
17+
---
18+
19+
Code
20+
snapshot_file_equal_("doesnt-exist.txt")
21+
Condition
22+
Error in `snapshot_file_equal_()`:
23+
! 'doesnt-exist.txt' not found.
24+
25+
# generates informative hint
26+
27+
Code
28+
base::writeLines(snapshot_review_hint("lala", reset_output = FALSE))
29+
Output
30+
* Run `testthat::snapshot_review('lala/')` to review the change.
31+
32+
---
33+
34+
Code
35+
base::writeLines(snapshot_review_hint("lala", is_text = TRUE, reset_output = FALSE))
36+
Output
37+
* Run `testthat::snapshot_accept('lala/')` to accept the change.
38+
* Run `testthat::snapshot_review('lala/')` to review the change.
39+
40+
# expect_snapshot_file validates its inputs
41+
42+
Code
43+
expect_snapshot_file(123, "test.txt")
44+
Condition
45+
Error in `expect_snapshot_file()`:
46+
! `path` must be a single string, not the number 123.
47+
Code
48+
expect_snapshot_file("test.txt", 123)
49+
Condition
50+
Error in `expect_snapshot_file()`:
51+
! `name` must be a single string, not the number 123.
52+
Code
53+
expect_snapshot_file("test.txt", "test.txt", cran = "yes")
54+
Condition
55+
Error in `expect_snapshot_file()`:
56+
! `cran` must be `TRUE` or `FALSE`, not the string "yes".
57+

tests/testthat/test-snapshot-file.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,14 @@ test_that("split_path handles edge cases", {
163163
})
164164

165165
test_that("generates informative hint", {
166-
expect_snapshot(cat(snapshot_review_hint(
166+
expect_snapshot(base::writeLines(snapshot_review_hint(
167167
"lala",
168-
"foo.r",
168+
reset_output = FALSE
169+
)))
170+
171+
expect_snapshot(base::writeLines(snapshot_review_hint(
172+
"lala",
173+
is_text = TRUE,
169174
reset_output = FALSE
170175
)))
171176
})

0 commit comments

Comments
 (0)