File: test-lightswitch.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 (46 lines) | stat: -rw-r--r-- 1,047 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
context("lightswitch functions")

test_that("turn_on & turned_on", {
  expect_true(turned_on())

  expect_false(light_switch$turned_off)
  expect_false(turn_on())
  expect_false(light_switch$turned_off)

  expect_true(turned_on())
})

test_that("turn_off", {
  expect_true(turned_on())

  expect_false(light_switch$turned_off)
  expect_true(suppressMessages(turn_off()))
  expect_message(turn_off(), "vcr turned off")
  expect_true(light_switch$turned_off)

  expect_false(turned_on())
})

test_that("turned_off", {
  turn_on()

  # if a cassette is in use
  mycas <- insert_cassette("adfadfdfadfadsf")
  expect_error(turned_off(5 + 5), "You must eject it")
  mycas$eject()

  # no cassette in use
  expect_true(turned_on())
  suppressMessages(turned_off({
    beetle <- crul::HttpClient$new(url = "https://eu.httpbin.org/get")$get()
  }))
  expect_is(beetle, "HttpResponse")
  expect_true(turned_on())
})

# cleanup
# eject_cassette()
unlink(file.path(vcr_configuration()$dir, "adfadfdfadfadsf.yml"))

# reset configuration
vcr_configure_reset()