-
Notifications
You must be signed in to change notification settings - Fork 14
Deprecate check_cassette_names()
#464
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
61b4413
Deprecate `check_cassette_names()`
hadley 2eaffb7
Merge commit 'bdfd3d77ba1428fd76e88fab74c3952c3c7749b8'
hadley 85144c5
Polish test
hadley cf99bd5
Delete duplicate import
hadley 918e3fa
Apply suggestions from code review
hadley bef8636
Re-document
hadley d3a7c4b
Merged origin/main into deprecate-check-cassette-names
hadley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# check_cassette_names is deprecated | ||
|
||
Code | ||
check_cassette_names(dir) | ||
Condition | ||
Warning: | ||
`check_cassette_names()` was deprecated in vcr 2.0.0. | ||
|
||
# check_cassette_names | ||
|
||
Code | ||
check_cassette_names() | ||
Condition | ||
Error: | ||
! you should not have duplicated cassette names: | ||
testing (found in test-catbar.R, test-single.R) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
test_that("check_cassette_names", { | ||
withr::local_options(lifecycle_verbosity = "quiet") | ||
|
||
test_that("check_cassette_names is deprecated", { | ||
dir <- make_pkg() | ||
expect_snapshot(check_cassette_names(dir)) | ||
}) | ||
|
||
res <- use_vcr(dir, verbose = FALSE) | ||
strg_dup <- 'test_that("bar", {\n vcr::use_cassette("testing", cat("bar"))\n vcr::use_cassette("testing", cat("bar"))\n})' | ||
cat(strg_dup, file = file.path(dir, "tests/testthat/test-catbar.R")) | ||
strg_single <- 'test_that("bar", {\n expect_true(TRUE)\n vcr::use_cassette("testing", cat("bar"))\n})' | ||
cat(strg_single, file = file.path(dir, "tests/testthat/test-single.R")) | ||
strg_not_used <- 'hi' | ||
cat(strg_not_used, file = file.path(dir, "tests/testthat/cat.R")) | ||
test_that("check_cassette_names", { | ||
withr::local_options(lifecycle_verbosity = "quiet") | ||
|
||
withr::local_dir(file.path(dir, "tests/testthat")) | ||
expect_error( | ||
check_cassette_names(), | ||
"you should not have duplicated cassette names", | ||
class = "error" | ||
test_path <- file.path(make_pkg(), "tests/testthat") | ||
writeLines( | ||
c( | ||
'test_that("bar", {', | ||
' vcr::use_cassette("testing", cat("bar"))', | ||
' vcr::use_cassette("testing", cat("bar"))', | ||
'})' | ||
), | ||
file.path(test_path, "test-catbar.R") | ||
) | ||
mssg <- tryCatch(check_cassette_names(), error = function(e) e) | ||
expect_match(mssg$message, "you should not have duplicated cassette names") | ||
expect_match(mssg$message, "testing \\(found in ") | ||
expect_match(mssg$message, "test-catbar.R, test-single.R, test-vcr_example.R") | ||
writeLines( | ||
c( | ||
'test_that("bar", {', | ||
' vcr::use_cassette("testing", cat("bar"))', | ||
'})' | ||
), | ||
file.path(test_path, "test-single.R") | ||
) | ||
writeLines("hi", con = file.path(test_path, "cat.R")) | ||
|
||
withr::local_dir(test_path) | ||
expect_snapshot(check_cassette_names(), error = TRUE) | ||
|
||
# can allow duplicated names via the allowed_duplicates param | ||
expect_error(check_cassette_names(allowed_duplicates = "testing"), NA) | ||
expect_no_error(check_cassette_names(allowed_duplicates = "testing")) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,3 +143,7 @@ Make sure you ejected the cassette you were using! | |
|
||
Unless your vcr helper/setup file tweaked more things than you would like, | ||
you do not even need to re-start R, but you could, just to be on the safe side. | ||
|
||
### Re-used cassestte name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly a placeholder so I don't forget about it in the debugging vignette. |
||
|
||
You need to make sure that every test has it's own unique cassette name, otherwise you won't find the responses that you're expecting. This is generally a fairly easy problem to diagnose if you're aware of it: if you re-record the cassette to fix the test you're currently in, a different test will break. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.