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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
context("UnhandledHTTPRequestError")
dir <- tempdir()
invisible(vcr_configure(dir = dir))
request <- Request$new(
"post", 'https://eu.httpbin.org/post?a=5', "", list(foo = "bar"))
test_that("UnhandledHTTPRequestError fails well", {
z <- UnhandledHTTPRequestError$new(request)
expect_error(
z$construct_message(),
"There is currently no cassette in use"
)
# insert a cassette
unlink(file.path(vcr_c$dir, "turtle"))
cas <- suppressMessages(insert_cassette("turtle"))
# types
expect_error(
UnhandledHTTPRequestError$new(5),
"request must be of class Request"
)
# types
expect_error(
UnhandledHTTPRequestError$new(request, 5),
"cassette must be of class character"
)
})
test_that("UnhandledHTTPRequestError works as expected", {
a <- UnhandledHTTPRequestError$new(request)
expect_is(a, "UnhandledHTTPRequestError")
expect_is(a$cassette, "Cassette")
expect_equal(a$cassette$name, "turtle")
expect_is(a$construct_message, "function")
expect_error(
a$construct_message(),
"An HTTP request has been made that vcr does not know how to handle"
)
})
# cleanup
eject_cassette()
unlink(file.path(vcr_configuration()$dir, "turtle.yml"))
# reset configuration
vcr_configure_reset()
|