tests/testthat/test-offline.R

test_that("currently_offline interacts with the mock contexts", {
  expect_message(
    expect_false(with_fake_http(currently_offline())),
    "GET http://httpbin.org/"
  )
  expect_true(without_internet(currently_offline()))
})

public({
  test_that("skip_if_disconnected when disconnected", {
    without_internet({
      skip_if_disconnected("This should skip")
      expect_true(FALSE)
    })
  })
  test_that("skip_if_disconnected when 'connected'", {
    expect_message(
      with_fake_http({
        skip_if_disconnected("This should not skip")
        expect_failure(expect_true(FALSE))
      }),
      "GET http://httpbin.org/"
    )
  })
})

Try the httptest package in your browser

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

httptest documentation built on July 9, 2023, 7:45 p.m.