|
1 | 1 | test_that("informs about files being accepted", { |
2 | | - path <- local_snapshot_dir(c("a.md", "a.new.md", "b.md", "b.new.md")) |
| 2 | + path <- local_snapshot_dir(c( |
| 3 | + "a.md", |
| 4 | + "a.new.md", |
| 5 | + "test/b.txt", |
| 6 | + "test/b.new.txt" |
| 7 | + )) |
3 | 8 |
|
4 | 9 | expect_snapshot(snapshot_accept(path = path)) |
5 | | - expect_equal(dir(file.path(path, "_snaps")), c("a.md", "b.md")) |
| 10 | + expect_equal( |
| 11 | + dir(file.path(path, "_snaps"), recursive = TRUE), |
| 12 | + c("a.md", "test/b.txt") |
| 13 | + ) |
| 14 | +}) |
6 | 15 |
|
| 16 | +test_that("useful mesasge if no files to accept", { |
| 17 | + path <- local_snapshot_dir(character()) |
7 | 18 | expect_snapshot(snapshot_accept(path = path)) |
8 | 19 | }) |
9 | 20 |
|
10 | | -test_that("can accept specific files", { |
| 21 | +test_that("can accept files created by expect_snapshot()", { |
| 22 | + # without extension |
11 | 23 | path <- local_snapshot_dir(c("a.md", "a.new.md", "b.md", "b.new.md")) |
12 | | - expect_snapshot(snapshot_accept("a", path = path)) |
| 24 | + suppressMessages(snapshot_accept("a", path = path)) |
13 | 25 | expect_equal(dir(file.path(path, "_snaps")), c("a.md", "b.md", "b.new.md")) |
14 | 26 |
|
15 | | - path <- local_snapshot_dir(c("test/a.txt", "test/a.new.txt")) |
16 | | - expect_snapshot(snapshot_accept("test/a.txt", path = path)) |
17 | | - expect_equal(dir(file.path(path, "_snaps"), recursive = TRUE), "test/a.txt") |
| 27 | + # with extension |
| 28 | + path <- local_snapshot_dir(c("a.md", "a.new.md", "b.md", "b.new.md")) |
| 29 | + suppressMessages(snapshot_accept("a.md", path = path)) |
| 30 | + expect_equal(dir(file.path(path, "_snaps")), c("a.md", "b.md", "b.new.md")) |
18 | 31 |
|
19 | 32 | # or whole directory |
| 33 | + path <- local_snapshot_dir(c("a.md", "a.new.md", "b.md", "b.new.md")) |
| 34 | + suppressMessages(snapshot_accept(path = path)) |
| 35 | + expect_equal(dir(file.path(path, "_snaps")), c("a.md", "b.md")) |
| 36 | +}) |
| 37 | + |
| 38 | +test_that("can accept files created by expect_snapshot_file()", { |
20 | 39 | path <- local_snapshot_dir(c("test/a.txt", "test/a.new.txt")) |
21 | | - expect_snapshot(snapshot_accept("test/", path = path)) |
| 40 | + suppressMessages(snapshot_accept("test/a.txt", path = path)) |
22 | 41 | expect_equal(dir(file.path(path, "_snaps"), recursive = TRUE), "test/a.txt") |
| 42 | + |
| 43 | + # including markdown files |
| 44 | + path <- local_snapshot_dir(c("test/a.md", "test/a.new.md")) |
| 45 | + suppressMessages(snapshot_accept("test/", path = path)) |
| 46 | + expect_equal(dir(file.path(path, "_snaps"), recursive = TRUE), "test/a.md") |
| 47 | + |
| 48 | + # or the whole directory |
| 49 | + path <- local_snapshot_dir(c( |
| 50 | + "test/a.md", |
| 51 | + "test/a.new.md", |
| 52 | + "test/b.txt", |
| 53 | + "test/b.new.txt" |
| 54 | + )) |
| 55 | + suppressMessages(snapshot_accept("test/", path = path)) |
| 56 | + expect_equal( |
| 57 | + dir(file.path(path, "_snaps"), recursive = TRUE), |
| 58 | + c("test/a.md", "test/b.txt") |
| 59 | + ) |
23 | 60 | }) |
24 | 61 |
|
25 | 62 | test_that("can work with variants", { |
|
0 commit comments