From 71dc963d21dcfb71e102cd3041b40787a0bdc7b5 Mon Sep 17 00:00:00 2001 From: Maximilian Muecke Date: Sat, 5 Oct 2024 15:30:29 +0200 Subject: [PATCH] tests: migrate to testthat mocking --- DESCRIPTION | 1 - R/mocks.R | 2 ++ tests/testthat/test-platform.R | 4 ++-- tests/testthat/test-repo.R | 8 ++++++-- 4 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 R/mocks.R diff --git a/DESCRIPTION b/DESCRIPTION index 50bd204fe..dd49cd126 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,7 +45,6 @@ Suggests: gitcreds, glue (>= 1.6.2), jsonlite (>= 1.8.0), - mockery, pingr, pkgbuild (>= 1.4.2), pkgcache (>= 2.0.4), diff --git a/R/mocks.R b/R/mocks.R new file mode 100644 index 000000000..140f8d14a --- /dev/null +++ b/R/mocks.R @@ -0,0 +1,2 @@ +file.exists <- NULL +getRversion <- NULL diff --git a/tests/testthat/test-platform.R b/tests/testthat/test-platform.R index 0ff31ac05..ae7d90de0 100644 --- a/tests/testthat/test-platform.R +++ b/tests/testthat/test-platform.R @@ -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(".", ".")) diff --git a/tests/testthat/test-repo.R b/tests/testthat/test-repo.R index 7c333ff6e..15d5ae5e0 100644 --- a/tests/testthat/test-repo.R +++ b/tests/testthat/test-repo.R @@ -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) @@ -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)