File: skip-vcr-off.R

package info (click to toggle)
r-cran-vcr 0.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,360 kB
  • sloc: cpp: 15; sh: 13; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,002 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#' Skip tests if vcr is off
#'
#' Custom testthat skipper to skip tests if vcr is turned off via the
#' environment variable `VCR_TURN_OFF`.
#'
#' @details This might be useful if your test will fail with real requests:
#' when the cassette was e.g. edited (a real request produced a 200 status code
#' but you made it a 502 status code for testing the behavior of your code
#' when the API errors)
#' or if the tests are very specific (e.g. testing a date was correctly parsed,
#' but making a real request would produce a different date).
#'
#' @return Nothing, skip test.
#' @export
#'
#' @seealso [turn_off()]
skip_if_vcr_off <- function() {

  if (!requireNamespace("testthat", quietly = TRUE)) {
    stop(
      paste0(
        "This function is meant to be used within testthat tests.",
        "Please install testthat."
      )
      )
  }

  if (
    nzchar(Sys.getenv("VCR_TURN_OFF")) &&
    as.logical(Sys.getenv("VCR_TURN_OFF"))
    ) {
    testthat::skip("Not run when vcr is off")
  }
}