Fix cache file test broken by recording the analysis parameters
Since cacheAs files record the parameters they were created with, in an
attribute, while the returned value deliberately does not carry it, the
test comparing the file against the returned value failed:
Expected `readRDS(cache_file)` to equal `first`.
Attributes: < Names: 1 string mismatch >
The test now strips the attribute before comparing, and asserts that it
is there in the first place, which is the behaviour that broke it.
The failure only showed up in CI because the test needs network access
and is guarded by skip_if_offline(), which skips unless NOT_CRAN is set,
as devtools::test() does but plain R CMD check does not.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Change-Id: I48bada5f923df661404627efc58ed623fc093440
diff --git a/tests/testthat/test-collocations.R b/tests/testthat/test-collocations.R
index 61602c0..866ecc0 100644
--- a/tests/testthat/test-collocations.R
+++ b/tests/testthat/test-collocations.R
@@ -983,7 +983,11 @@
)
expect_true(file.exists(cache_file))
- expect_equal(readRDS(cache_file), first)
+ # the file records the analysis parameters, the returned value does not
+ cached <- readRDS(cache_file)
+ expect_false(is.null(attr(cached, RKorAPClient:::collocationCacheAttribute)))
+ attr(cached, RKorAPClient:::collocationCacheAttribute) <- NULL
+ expect_equal(cached, first)
# the second call is served from the cache and therefore issues no token warning
second <- collocationAnalysis(