File: test-cassettes.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 (55 lines) | stat: -rw-r--r-- 1,261 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
context("cassettes")
test_that("cassettes works", {
  aa <- cassettes()
  expect_is(aa, "list")
  expect_equal(length(aa), 0)

  cc <- suppressMessages(insert_cassette("foobar"))

  bb <- cassettes()
  # cassette in named list
  expect_named(bb, "foobar")
  # even after cassette inserted, list is empty
  expect_equal(length(bb$foobar), 0)

  # eject
  cc$eject()
})

unlink(file.path(vcr_configuration()$dir, "foobar.yml"))

# FIXME: add tests for on_disk and verb params

context("current_cassette")
test_that("current_cassette works", {
  # no cassettes in use
  aa <- current_cassette()
  expect_is(aa, "list")
  expect_equal(length(aa), 0)

  # cassette in use
  cas <- insert_cassette("rrrrrrrrrrr")
  aa <- current_cassette()
  expect_is(aa, "Cassette")
  expect_gt(length(aa), 1)
  expect_equal(aa$name, 'rrrrrrrrrrr')
  cas$eject()
})

unlink(file.path(vcr_configuration()$dir, "rrrrrrrrrrr.yml"))

context("cassette_path")
test_that("cassette_path works", {
  # before vcr_config set, there's a temp dir
  aa <- cassette_path()
  expect_is(aa, "character")

  # after vcr_config set, dir should be different
  vcr_configure(dir = "foo")
  aa <- cassette_path()
  expect_is(aa, "character")
  expect_equal(aa, "foo")
})

# reset
vcr_configure_reset()