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

tests: migrate to testthat mocking #700

Merged
merged 1 commit into from
Oct 5, 2024
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:
gitcreds,
glue (>= 1.6.2),
jsonlite (>= 1.8.0),
mockery,
pingr,
pkgbuild (>= 1.4.2),
pkgcache (>= 2.0.4),
Expand Down
2 changes: 2 additions & 0 deletions R/mocks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
file.exists <- NULL
getRversion <- NULL
4 changes: 2 additions & 2 deletions tests/testthat/test-platform.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ test_that("platform_match", {

test_that("check_platform", {
# load_all() is fine without data
mockery::stub(check_platform, "file.exists", FALSE)
local_mocked_bindings(file.exists = function(...) FALSE)
expect_silent(check_platform(".", "."))

# during installation?
mockery::stub(check_platform, "file.exists", TRUE)
local_mocked_bindings(file.exists = function(...) TRUE)
withr::with_envvar(
c(R_PACKAGE_DIR = "foobar"),
expect_silent(check_platform(".", "."))
Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/test-repo.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ test_that("Old URL", {
for (i in seq_len(nrow(tsts))) {
cu <- get_curl(repo, tsts$pkg_type[i], tsts$rver[i])
av <- available.packages(cu, filters = list(), ignore_repo_cache = TRUE)
mockery::stub(rver_flt, "getRversion", package_version(tsts$rver[i]))
local_mocked_bindings(
getRversion = function() package_version(tsts$rver[i])
)
res <- rver_flt(av)

expect_equal(nrow(res), 1L)
Expand Down Expand Up @@ -113,7 +115,9 @@ test_that("New URL", {

cu <- get_curl(repo, tsts$pkg_type[i], tsts$rver[i])
av <- available.packages(cu, filters = list(), ignore_repo_cache = TRUE)
mockery::stub(rver_flt, "getRversion", package_version(tsts$rver[i]))
local_mocked_bindings(
getRversion = function() package_version(tsts$rver[i])
)
res <- rver_flt(av)

expect_equal(nrow(res), 1L)
Expand Down
Loading