Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use testthat mocking #450

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading