Skip to content

Commit c138d7d

Browse files
committed
fix: Add skip_if_not_installed("vcr") to skip vcr-dependent tests in check-no-suggests CI
1 parent 7fe463e commit c138d7d

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

tests/testthat/helper-vcr.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
library("vcr") # *Required* as vcr is set up on loading
2-
invisible(vcr::vcr_configure(
3-
dir = vcr::vcr_test_path("fixtures")
4-
))
5-
vcr::check_cassette_names()
1+
if ("vcr" %in% installed.packages()) {
2+
library("vcr") # *Required* as vcr is set up on loading
3+
invisible(vcr::vcr_configure(
4+
dir = vcr::vcr_test_path("fixtures")
5+
))
6+
vcr::check_cassette_names()
7+
}

tests/testthat/test-openFDA.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ test_that("openFDA can call its API and reach correct endpoints", {
4646

4747
test_that(
4848
desc = "openFDA paging is possible with correct printing behaviour", {
49+
skip_if_not_installed(pkg = "vcr")
4950
vcr::use_cassette("test-paging", {
5051
# Query which requires paging
5152
resps <- openFDA(search = "openfda.generic_name:\"semaglutide\"",
@@ -76,6 +77,7 @@ test_that(
7677
# Does not need vcr as error is thrown *before* any HTTP requests sent
7778
test_that(
7879
desc = "openFDA paging fails if `paging == \"ask\" but not interactive", {
80+
skip_if_not_installed(pkg = "vcr")
7981
skip_if(interactive())
8082
# Query which requires paging
8183
expect_error(
@@ -88,6 +90,7 @@ test_that(
8890
})
8991

9092
test_that("openFDA throws formatted HTTP errors", {
93+
skip_if_not_installed(pkg = "vcr")
9194
vcr::use_cassette("test-handle_http_errors", {
9295
for (handle_http_errors in c("error", "warn", "silent")) {
9396
expect_fn <- switch(handle_http_errors,
@@ -193,7 +196,8 @@ test_that("openFDA throws formatted HTTP errors", {
193196
})
194197
})
195198

196-
# Also doesn't require vcr --> errors occur before `httr2::req_perform()`
199+
# Doesn't require vcr and no need to skip on CRAN --> errors occur before
200+
# `httr2::req_perform()`
197201
test_that("openFDA errors on certain bad inputs", {
198202
suppressMessages(
199203
set_api_key(api_key = "api_key_string")

0 commit comments

Comments
 (0)