Skip to content

Commit

Permalink
REVDEPCHECK add tests for Async and mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jul 18, 2024
1 parent 6df10e4 commit 6305fdf
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions tests/testthat/test-mocking.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ test_that("mocking with HttpRequest", {
bb <- make_req(url)

# content and times differ btw the two
expect_is(aa, "HttpResponse")
expect_is(bb, "HttpResponse")
expect_s3_class(aa, "HttpResponse")
expect_s3_class(bb, "HttpResponse")

expect_is(aa$content, "raw")
expect_equal(length(bb$content), 0)
Expand All @@ -54,6 +54,49 @@ test_that("mocking with HttpRequest", {
webmockr::stub_registry_clear()
})

context("mocking: HttpRequest with Async")
test_that("mocking with HttpRequest", {
skip_if_not_installed("webmockr")

loadNamespace("webmockr")
url <- hb()
urls <- c(
file.path(url, "get"),
file.path(url, "anything"),
file.path(url, "encoding/utf8")
)
for (u in urls) webmockr::stub_request("get", u)
# webmockr::stub_registry()

make_req <- function(urls) {
cc <- Async$new(urls = urls)
cc$get()
}

mock(FALSE)
# webmockr IS NOT enabled
not_mocked <- make_req(urls)

# webmockr IS enabled
mock()
mocked <- make_req(urls)

expect_s3_class(not_mocked[[1]], "HttpResponse")
expect_s3_class(mocked[[1]], "HttpResponse")

expect_s3_class(not_mocked[[1]]$status_http(), "http_code")
expect_s3_class(mocked[[1]]$status_http(), "http_code")

expect_is(not_mocked[[1]]$content, "raw")
expect_equal(length(mocked[[1]]$content), 0)

expect_is(not_mocked[[1]]$times, "numeric")
expect_null(mocked[[1]]$times)

# clean up
webmockr::stub_registry_clear()
})

context("mocking: HttpClient")
test_that("mocking with HttpClient", {
skip_if_not_installed("webmockr")
Expand Down

0 comments on commit 6305fdf

Please sign in to comment.