tests/testthat/skip_if_net_down.R

has_internet <- function() {
  z <- try(suppressWarnings(readLines("https://www.google.com", n = 1)),
    silent = TRUE
  )
  !inherits(z, "try-error")
}

skip_if_net_down <- function() {
  if (has_internet()) {
    return()
  }
  testthat::skip("no internet")
}
maurolepore/ghr documentation built on May 18, 2019, 12:26 p.m.