tests/testthat/test-resp.R

test_that("response has basic print method", {

  file.create("path-empty")
  writeBin("sample content", "path-content")

  withr::defer(unlink(c("path-empty", "path-content")))

  expect_snapshot({
    response(200)
    response(200, headers = "Content-Type: text/html")
    response(200, body = charToRaw("abcdef"))
    response(200, body = new_path("path-empty"))
    response(200, body = new_path("path-content"))
  })
})

test_that("response adds date if not provided by server", {
  resp <- response(headers = "Test: 1")
  expect_named(resp_headers(resp), c("Test", "Date"))
})

test_that("check_response produces helpful error", {
  expect_snapshot(check_response(1), error = TRUE)
})

Try the httr2 package in your browser

Any scripts or data that you put into this service are public.

httr2 documentation built on Nov. 14, 2023, 5:08 p.m.