Skip to content

Commit

Permalink
Use testthat mocking (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored Nov 15, 2023
1 parent 6ee8a31 commit ce5c62c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Suggests:
covr,
fortunes,
miniUI,
mockr,
rprojroot,
sessioninfo,
shiny,
Expand Down
1 change: 0 additions & 1 deletion inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ lifecycle
lockfile
macOS
metapackage
mockr
noninteractive
oducible
outfiles
Expand Down
4 changes: 0 additions & 4 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ expect_messages_to_include <- function(haystack, needles) {
invisible()
}

with_mock <- function(..., .parent = parent.frame()) {
mockr::with_mock(..., .parent = .parent, .env = "reprex")
}

# 1. creates a subdirectory within session temp
# 2. makes that the current working directory
# 3. schedules these cleanup actions for when env goes out of scope:
Expand Down
18 changes: 6 additions & 12 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
test_that("locate_input() works", {
with_mock(
with_mocked_bindings(
reprex_clipboard = function() TRUE,
{
expect_identical("clipboard", locate_input(NULL))
}
expect_identical("clipboard", locate_input(NULL))
)
with_mock(
with_mocked_bindings(
reprex_clipboard = function() FALSE,
in_rstudio = function() TRUE,
{
expect_identical("selection", locate_input(NULL))
}
expect_identical("selection", locate_input(NULL))
)
with_mock(
with_mocked_bindings(
reprex_clipboard = function() FALSE,
in_rstudio = function() FALSE,
{
expect_null(locate_input(NULL))
}
expect_null(locate_input(NULL))
)
expect_identical("path", locate_input(path_temp()))
expect_identical("input", locate_input(c("a", "b")))
Expand Down

0 comments on commit ce5c62c

Please sign in to comment.