Skip to content

Commit 6cf18f0

Browse files
authored
Minor improvements to vignette tests (#1353)
1 parent f9975dd commit 6cf18f0

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

tests/testthat/_snaps/vignette.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# use_vignette() gives useful errors
2+
3+
Code
4+
use_vignette()
5+
Error <simpleError>
6+
argument "name" is missing, with no default
7+
Code
8+
use_vignette("bad name")
9+
Error <usethis_error>
10+
'bad name' is not a valid filename for a vignette. It must:
11+
* Start with a letter.
12+
* Contain only letters, numbers, '_', and '-'.
13+

tests/testthat/test-vignette.R

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
test_that("use_vignette() requires a package", {
2-
skip_if_not_installed("rmarkdown")
1+
# use_vignette ------------------------------------------------------------
32

3+
test_that("use_vignette() requires a package", {
44
create_local_project()
5+
56
expect_usethis_error(use_vignette(), "not an R package")
67
})
78

8-
test_that("use_vignette() requires a `name`", {
9-
skip_if_not_installed("rmarkdown")
10-
9+
test_that("use_vignette() gives useful errors", {
1110
create_local_package()
12-
expect_error(use_vignette(), "no default")
13-
})
1411

15-
test_that("valid_vignette_name() works", {
16-
expect_true(valid_vignette_name("perfectly-valid-name"))
17-
expect_false(valid_vignette_name("01-test"))
18-
expect_false(valid_vignette_name("test.1"))
12+
expect_snapshot(error = TRUE, {
13+
use_vignette()
14+
use_vignette("bad name")
15+
})
1916
})
2017

2118
test_that("use_vignette() does the promised setup", {
22-
skip_if_not_installed("rmarkdown")
23-
2419
create_local_package()
20+
2521
use_vignette("name", "title")
22+
expect_proj_file("vignettes/name.Rmd")
2623

2724
ignores <- read_utf8(proj_path(".gitignore"))
2825
expect_true("inst/doc" %in% ignores)
@@ -38,9 +35,19 @@ test_that("use_vignette() does the promised setup", {
3835
)
3936
})
4037

38+
# use_article -------------------------------------------------------------
39+
4140
test_that("use_article goes in article subdirectory", {
4241
create_local_package()
4342

4443
use_article("test")
4544
expect_proj_file("vignettes/articles/test.Rmd")
4645
})
46+
47+
# helpers -----------------------------------------------------------------
48+
49+
test_that("valid_vignette_name() works", {
50+
expect_true(valid_vignette_name("perfectly-valid-name"))
51+
expect_false(valid_vignette_name("01-test"))
52+
expect_false(valid_vignette_name("test.1"))
53+
})

0 commit comments

Comments
 (0)