Skip to content

Commit

Permalink
transition from mockr to testthat (closes #230)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Oct 23, 2024
1 parent cd36203 commit b9ef734
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Suggests:
kernlab,
kknn,
knitr,
mockr,
modeldata,
nnet,
ranger,
Expand Down
24 changes: 20 additions & 4 deletions tests/testthat/_snaps/fit_members.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,33 @@

# fit_members checks for required packages

The package a needs to be installed before fitting members.
Code
error_needs_install(letters[1], rep(FALSE, 1))
Condition
Error in `error_needs_install()`:
! The package a needs to be installed before fitting members.

---

The packages a and b need to be installed before fitting members.
Code
error_needs_install(letters[1:2], rep(FALSE, 2))
Condition
Error in `error_needs_install()`:
! The packages a and b need to be installed before fitting members.

---

The packages a, b, and c need to be installed before fitting members.
Code
error_needs_install(letters[1:3], rep(FALSE, 3))
Condition
Error in `error_needs_install()`:
! The packages a, b, and c need to be installed before fitting members.

---

The packages recipes, parsnip, and kernlab need to be installed before fitting members.
Code
st_reg_1_ %>% fit_members()
Condition
Error in `fit_members()`:
! The packages recipes, parsnip, and kernlab need to be installed before fitting members.

14 changes: 3 additions & 11 deletions tests/testthat/test_fit_members.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ test_that("fit_members errors informatively with a bad model_stack arg", {
test_that("fit_members checks for required packages", {
skip_on_cran()

skip_if_not_installed("mockr")

library(mockr)

# check pluralization of error
expect_snapshot(error = TRUE, error_needs_install(letters[1], rep(FALSE, 1)))
expect_snapshot(error = TRUE, error_needs_install(letters[1:2], rep(FALSE, 2)))
Expand All @@ -142,11 +138,7 @@ test_that("fit_members checks for required packages", {
expect_true(isNamespaceLoaded("kernlab"))

# errors informatively when it's not installed
mockr::with_mock(
is_installed_ = function(x) {FALSE},
{expect_snapshot_error(
st_reg_1_ %>%
fit_members()
)}
)
testthat::local_mocked_bindings(is_installed_ = function(x) {FALSE})

expect_snapshot(error = TRUE, st_reg_1_ %>% fit_members())
})

0 comments on commit b9ef734

Please sign in to comment.