Skip to content

Commit

Permalink
add tests for utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestguevarra committed Dec 31, 2024
1 parent 3286b48 commit dc5d94d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/testthat/test-add_logo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Tests for add_logo functions -------------------------------------------------

test_that("add_logo works as expected", {
create_readme_file()

add_logo(repo = "katilingban/pakete")

expect_snapshot_file(
path = "README.Rmd",
name = "README.Rmd"
)

remove_readme_file()
})


test_that("add_logo with logo present works as expected", {
create_readme_file()

add_logo(repo = "katilingban/pakete")

add_logo(repo = "katilingban/pakete")

expect_snapshot_file(
path = "README.Rmd",
name = "README.Rmd"
)

remove_readme_file()
})
42 changes: 42 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Tests for utility functions --------------------------------------------------

test_that("get_github_repository works as expected", {
expect_error(get_github_repository())
})


test_that("get_readme_path works as expected", {
create_readme_file()

rmarkdown::render("README.Rmd")
remove_readme_file()

expect_identical(get_readme_path(), "README.md")

file.remove("README.md")

expect_error(get_readme_path())
})


test_that("insert_readme_badge_text works as expected", {
expect_error(insert_readme_badge_text())
expect_error(
insert_readme_badge_text(
badge_text = "[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)"
)
)

create_readme_file()
add_badge_status("wip", path = "README.Rmd")
readme_lines <- readLines("README.Rmd")

expect_warning(
insert_readme_badge_text(
badge_text = "[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)",
readme_lines = readme_lines
)
)

remove_readme_file()
})

0 comments on commit dc5d94d

Please sign in to comment.