Skip to content

Commit

Permalink
Merge pull request #700 from m-muecke/mocks
Browse files Browse the repository at this point in the history
tests: migrate to testthat mocking
  • Loading branch information
gaborcsardi authored Oct 5, 2024
2 parents 78e40fa + 71dc963 commit fd28536
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 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:
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

0 comments on commit fd28536

Please sign in to comment.