Skip to content
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

make cassette names content re-usable #216

Merged
merged 2 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions R/check_cassette_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,8 @@
#' we use `immediate.=TRUE` so the warning happens at the top of your
#' tests rather than you seeing it after tests have run (as would happen
#' by default)
#' @details This function is meant to be run during your tests, from a
#' `setup-pkgname.R` file inside the `tests/testthat` directory. It only
#' checks that cassette names are not duplicated. A helper function
#' `check_cassette_name()` runs inside [insert_cassette()] that checks
#' that cassettes do not have: spaces, file extensions, unaccepted
#' characters (slashes)
#' @section Cassette names:
#' - Should be meaningful so that it's obvious to you what test/function
#' they relate to. Meaningful names are important so that you can quickly
#' determine to what test file or test block a cassette belongs. Note that
#' vcr cannot check that your cassette names are meaningful.
#' - Should not be duplicated. Duplicated cassette names would lead to
#' a test using the wrong cassette.
#' - Should not have spaces. Spaces can lead to problems in using file paths.
#' - Should not include a file extension. vcr handles file extensions for
#' the user.
#' - Should not have illegal characters that can lead to problems in using
#' file paths: '/', '?', '<', '>', '\\', ':', '*', '|', and '\"'
#' - Should not have control characters, e.g., `\n`
#' - Should not have just dots, e.g., `.` or `..`
#' - Should not have Windows reserved words, e.g., `com1`
#' - Should not have trailing dots
#' - Should not be longer than 255 characters
#' @includeRmd man/rmdhunks/cassette-names.Rmd details

check_cassette_names <- function(pattern = "test-", behavior = "stop") {
files <- list.files(".", pattern = pattern, full.names = TRUE)
if (length(files) == 0) return()
Expand Down
4 changes: 2 additions & 2 deletions R/insert_cassette.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ vcr__env <- new.env()
#' @export
#' @inheritParams use_cassette
#' @inheritSection use_cassette Cassette options
#' @inheritSection check_cassette_names Cassette names
#' @inherit check_cassette_names details
#' @seealso [use_cassette()], [eject_cassette()]
#' @return an object of class `Cassette`
#' @examples \dontrun{
Expand All @@ -28,7 +28,7 @@ vcr__env <- new.env()
#' x$new_recorded_interactions # same, 1 interaction
#' x$previously_recorded_interactions() # now not empty
#' ## stub_registry now empty, eject() calls webmockr::disable(), which
#' ## calls the disable method for each of crul and httr adadapters,
#' ## calls the disable method for each of crul and httr adadapters,
#' ## which calls webmockr's remove_stubs() method for each adapter
#' webmockr::stub_registry()
#'
Expand Down
2 changes: 1 addition & 1 deletion R/use_cassette.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Use a cassette to record HTTP requests
#'
#' @export
#' @inheritSection check_cassette_names Cassette names
#' @inherit check_cassette_names details
#' @param name The name of the cassette. vcr will check this to ensure it
#' is a valid file name. Not allowed: spaces, file extensions, control
#' characters (e.g., `\n`), illegal characters ('/', '?', '<', '>', '\\', ':',
Expand Down
40 changes: 20 additions & 20 deletions man/check_cassette_names.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 31 additions & 23 deletions man/insert_cassette.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions man/rmdhunks/cassette-names.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Cassette names:

- Should be meaningful so that it's obvious to you what test/function
they relate to. Meaningful names are important so that you can quickly
determine to what test file or test block a cassette belongs. Note that
vcr cannot check that your cassette names are meaningful.
- Should not be duplicated. Duplicated cassette names would lead to
a test using the wrong cassette.
- Should not have spaces. Spaces can lead to problems in using file paths.
- Should not include a file extension. vcr handles file extensions for
the user.
- Should not have illegal characters that can lead to problems in using
file paths: '/', '?', '<', '>', '\\', ':', '*', '|', and '\"'
- Should not have control characters, e.g., `\n`
- Should not have just dots, e.g., `.` or `..`
- Should not have Windows reserved words, e.g., `com1`
- Should not have trailing dots
- Should not be longer than 255 characters

`vcr::check_cassette_names()` is meant to be run during your tests, from a
`setup-pkgname.R` file inside the `tests/testthat` directory. It only
checks that cassette names are not duplicated. A helper function
`check_cassette_name()` runs inside [insert_cassette()] that checks
that cassettes do not have: spaces, file extensions, unaccepted
characters (slashes)
22 changes: 0 additions & 22 deletions man/use_cassette.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.