File: test-insert_cassette.R

package info (click to toggle)
r-cran-vcr 0.2.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 596 kB
  • sloc: sh: 13; makefile: 2
file content (66 lines) | stat: -rw-r--r-- 2,029 bytes parent folder | download
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
context("insert_cassette")

context("insert_cassette fails well")
test_that("insert_cassette fails well", {
  unlink(file.path(vcr_c$dir, "foobar.yml"))

  # must pass a cassette name
  expect_error(insert_cassette(), "argument \"name\" is missing")

  # record valid values
  expect_error(
    suppressMessages(insert_cassette("newbar", record = "stuff")),
    "'record' value of 'stuff' is not in the allowed set"
  )

  # match_requests_on valid values
  expect_error(
    suppressMessages(insert_cassette("newbar", match_requests_on = "stuff")),
    "'match_requests_on' values \\(stuff\\) is not in the allowed set"
  )

  # update_content_length_header valid type
  expect_error(
    suppressMessages(insert_cassette("newbar3", update_content_length_header = 5)),
    "update_content_length_header must be of class logical"
  )

  # preserve_exact_body_bytes valid type
  expect_error(
    suppressMessages(insert_cassette("newbar4",  preserve_exact_body_bytes = 5)),
    "preserve_exact_body_bytes must be of class logical"
  )

  # persist_with valid value
  expect_error(
    suppressMessages(insert_cassette("newbar5", persist_with = "foobar")),
    "The requested VCR cassette persister \\(foobar\\) is not registered"
  )

  # persist_with valid value
  expect_error(
    suppressMessages(insert_cassette("newbar6", serialize_with = "howdy")),
    "The requested VCR cassette serializer \\(howdy\\) is not registered"
  )
})

context("insert_cassette works")
test_that("insert_cassette works as expected", {
  aa <- suppressMessages(insert_cassette("foobar3"))
  expect_is(aa, "Cassette")
  expect_is(aa$name, "character")
  expect_equal(aa$name, "foobar3")
  expect_false(aa$allow_playback_repeats)
  expect_false(aa$any_new_recorded_interactions())
  expect_is(aa$args, "list")
  expect_is(aa$call_block, "function")

  # eject
  aa$eject()
})

# cleanup
unlink(file.path(vcr_configuration()$dir, "foobar3.yml"))
unlink(list.files(pattern = "newbar", full.names = TRUE))
unlink("foobar.yml")
unlink("testing1.yml")