Skip to content

Commit dd0880e

Browse files
committed
Correct snapshot by hidding path
1 parent 975ca64 commit dd0880e

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

R/utils.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,13 @@ in_positron <- function() {
4242
in_rstudio <- function() {
4343
identical(Sys.getenv("RSTUDIO"), "1")
4444
}
45+
46+
47+
# for test
48+
49+
hide_path <- function(path) {
50+
function(x) {
51+
x <- gsub(path, "<project directory>", x, fixed = TRUE)
52+
gsub(fs::path_norm(path), "<project directory>", x, fixed = TRUE)
53+
}
54+
}

tests/testthat/_snaps/blog.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1-
# Create a blog post
2-
3-
Code
4-
new_blog_post("Intro to Felt Surrogacy", data = "1999-12-31", open = FALSE)
5-
Condition
6-
Error in `new_blog_post()`:
7-
! There is already a 'intro-to-felt-surrogacy' directory in 'posts/'
8-
91
# Error if not a quarto project
102

113
Code
124
new_blog_post("Intro to Felt Surrogacy", open = FALSE)
135
Condition
146
Error in `new_blog_post()`:
15-
! You need to be at root of a Quarto project to create a blog post in the 'posts/' directory at 'C:/Users/chris/AppData/Local/Temp/RtmpU72EnV/test-blog-project-415061be69e8'.
7+
! You need to be at root of a Quarto project to create a blog post in the 'posts/' directory at '<project directory>'.
168

179
---
1810

1911
Code
20-
new_blog_post("Intro to Felt Surrogacy", wd = withr::local_tempdir(pattern = "test-blog-project-2-"),
21-
open = FALSE)
12+
new_blog_post("Intro to Felt Surrogacy", wd = tmp_dir, open = FALSE)
2213
Condition
2314
Error in `new_blog_post()`:
24-
! You need to be at root of a Quarto project to create a blog post in the 'posts/' directory at 'C:/Users/chris/AppData/Local/Temp/RtmpU72EnV/test-blog-project-2-4150447c3b64'.
15+
! You need to be at root of a Quarto project to create a blog post in the 'posts/' directory at '<project directory>'.
2516

tests/testthat/test-blog.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ test_that("Create a blog post", {
3535
# ------------------------------------------------------------------------------
3636

3737
expect_snapshot(
38-
new_blog_post("Intro to Felt Surrogacy", data = "1999-12-31", open = FALSE),
39-
error = TRUE
38+
error = TRUE,
39+
new_blog_post("Intro to Felt Surrogacy", data = "1999-12-31", open = FALSE)
4040
)
4141

4242
# ------------------------------------------------------------------------------
@@ -67,16 +67,19 @@ test_that("Error if not a quarto project", {
6767
withr::local_dir(dir_path)
6868

6969
expect_snapshot(
70+
error = TRUE,
71+
transform = hide_path(dir_path),
7072
new_blog_post("Intro to Felt Surrogacy", open = FALSE),
71-
error = TRUE
7273
)
7374

75+
tmp_dir <- withr::local_tempdir(pattern = "test-blog-project-2-")
7476
expect_snapshot(
77+
error = TRUE,
78+
transform = hide_path(tmp_dir),
7579
new_blog_post(
7680
"Intro to Felt Surrogacy",
77-
wd = withr::local_tempdir(pattern = "test-blog-project-2-"),
81+
wd = tmp_dir,
7882
open = FALSE
7983
),
80-
error = TRUE
8184
)
8285
})

0 commit comments

Comments
 (0)