Skip to content

Commit e2d494f

Browse files
committed
testthat edition 3, parallel tests
1 parent 49ce91a commit e2d494f

37 files changed

+398
-472
lines changed

DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Suggests:
4444
withr
4545
Remotes: ropensci/vcr
4646
RoxygenNote: 7.3.2
47+
Config/testthat/edition: 3
48+
Config/testthat/parallel: true
4749
X-schema.org-applicationCategory: Web
4850
X-schema.org-keywords: http, https, API, web-services, curl, mock, mocking, fakeweb, http-mocking, testing, testing-tools, tdd
4951
X-schema.org-isPartOf: https://ropensci.org

tests/testthat/test-Adapter.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
context("Adapter class")
2-
31
test_that("Adapter class can't be instantiated", {
4-
expect_is(Adapter, "R6ClassGenerator")
2+
expect_s3_class(Adapter, "R6ClassGenerator")
53
expect_error(
64
Adapter$new(),
75
"Adapter parent class should not be called directly"

tests/testthat/test-CrulAdapter.R

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
context("CrulAdapter")
2-
31
aa <- CrulAdapter$new()
42

53
test_that("CrulAdapter bits are correct", {
64
skip_on_cran()
75

8-
expect_is(CrulAdapter, "R6ClassGenerator")
6+
expect_s3_class(CrulAdapter, "R6ClassGenerator")
97

10-
expect_is(aa, "CrulAdapter")
8+
expect_s3_class(aa, "CrulAdapter")
119
expect_null(aa$build_crul_request) # pulled out of object, so should be NULL
1210
expect_null(aa$build_crul_response) # pulled out of object, so should be NULL
13-
expect_is(aa$disable, "function")
14-
expect_is(aa$enable, "function")
15-
expect_is(aa$handle_request, "function")
16-
expect_is(aa$remove_stubs, "function")
17-
expect_is(aa$name, "character")
11+
expect_type(aa$disable, "closure")
12+
expect_type(aa$enable, "closure")
13+
expect_type(aa$handle_request, "closure")
14+
expect_type(aa$remove_stubs, "closure")
15+
expect_type(aa$name, "character")
1816

1917
expect_equal(aa$name, "CrulAdapter")
2018
})
@@ -52,17 +50,16 @@ test_that("CrulAdapter: works when vcr is loaded but no cassette is inserted", {
5250
cli <- crul::HttpClient$new(hb())
5351

5452
expect_silent(x <- cli$get("get"))
55-
expect_is(x, "HttpResponse")
53+
expect_s3_class(x, "HttpResponse")
5654

5755
# works when empty cassette is loaded
5856
vcr::vcr_configure(dir = tempdir())
5957
vcr::insert_cassette("empty")
6058
expect_silent(x <- cli$get("get"))
6159
vcr::eject_cassette()
62-
expect_is(x, "HttpResponse")
60+
expect_s3_class(x, "HttpResponse")
6361
})
6462

65-
context("CrulAdapter - with real data")
6663
test_that("CrulAdapter works", {
6764
skip_on_cran()
6865
skip_if_not_installed("vcr")
@@ -90,8 +87,8 @@ test_that("CrulAdapter works", {
9087

9188
aa <- res$handle_request(crul_obj)
9289

93-
expect_is(res, "CrulAdapter")
94-
expect_is(aa, "HttpResponse")
90+
expect_s3_class(res, "CrulAdapter")
91+
expect_s3_class(aa, "HttpResponse")
9592
expect_equal(aa$method, "get")
9693
expect_equal(aa$url, "http://localhost:9000/get")
9794

@@ -109,17 +106,17 @@ test_that("CrulAdapter works", {
109106

110107
aa <- res$handle_request(crul_obj)
111108

112-
expect_is(res, "CrulAdapter")
113-
expect_is(aa, "HttpResponse")
109+
expect_s3_class(res, "CrulAdapter")
110+
expect_s3_class(aa, "HttpResponse")
114111
expect_equal(aa$method, "get")
115112
expect_equal(aa$url, "http://localhost:9000/get")
116113

117114
# has response_headers and response_headers_all
118115
expect_equal(length(aa$response_headers), 1)
119-
expect_is(aa$response_headers, "list")
116+
expect_type(aa$response_headers, "list")
120117
expect_named(aa$response_headers, "user-agent")
121118
expect_equal(length(aa$response_headers_all), 1)
122-
expect_is(aa$response_headers_all, "list")
119+
expect_type(aa$response_headers_all, "list")
123120
expect_named(aa$response_headers_all, NULL)
124121
expect_named(aa$response_headers_all[[1]], "user-agent")
125122

@@ -145,12 +142,12 @@ test_that("CrulAdapter works", {
145142

146143
# has response_headers and response_headers_all
147144
expect_equal(length(aa$response_headers), 2)
148-
expect_is(aa$response_headers, "list")
145+
expect_type(aa$response_headers, "list")
149146
expect_equal(sort(names(aa$response_headers)), c("location", "status"))
150147
expect_equal(length(aa$response_headers_all), 1)
151148
expect_equal(length(aa$response_headers_all[[1]]), 2)
152-
expect_is(aa$response_headers_all, "list")
153-
expect_is(aa$response_headers_all[[1]], "list")
149+
expect_type(aa$response_headers_all, "list")
150+
expect_type(aa$response_headers_all[[1]], "list")
154151
expect_named(aa$response_headers_all, NULL)
155152
expect_equal(
156153
sort(names(aa$response_headers_all[[1]])),

tests/testthat/test-HashCounter.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
context("HashCounter")
1+
22

33
test_that("HashCounter: structure", {
4-
expect_is(HashCounter, "R6ClassGenerator")
4+
expect_s3_class(HashCounter, "R6ClassGenerator")
55

66
x <- HashCounter$new()
7-
expect_is(x, "HashCounter")
7+
expect_s3_class(x, "HashCounter")
88

9-
expect_is(x$clone, "function")
10-
expect_is(x$get, "function")
11-
expect_is(x$put, "function")
9+
expect_type(x$clone, "closure")
10+
expect_type(x$get, "closure")
11+
expect_type(x$put, "closure")
1212

13-
expect_is(x$hash, "list")
13+
expect_type(x$hash, "list")
1414
})
1515

1616
test_that("HashCounter: works as expected", {

tests/testthat/test-HttpLibAdapaterRegistry.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
context("HttpLibAdapaterRegistry")
21

32
test_that("HttpLibAdapaterRegistry: structure", {
4-
expect_is(HttpLibAdapaterRegistry, "R6ClassGenerator")
3+
expect_s3_class(HttpLibAdapaterRegistry, "R6ClassGenerator")
54

65
aa <- HttpLibAdapaterRegistry$new()
76

8-
expect_is(aa, "HttpLibAdapaterRegistry")
7+
expect_s3_class(aa, "HttpLibAdapaterRegistry")
98

109
expect_null(aa$adapters)
11-
expect_is(aa$clone, "function")
12-
expect_is(aa$print, "function")
13-
expect_is(aa$register, "function")
10+
expect_type(aa$clone, "closure")
11+
expect_type(aa$print, "closure")
12+
expect_type(aa$register, "closure")
1413

1514
expect_output(print(aa), "HttpLibAdapaterRegistry")
1615
})
@@ -22,7 +21,7 @@ test_that("HttpLibAdapaterRegistry: behaves as expected", {
2221
aa$register(CrulAdapter$new())
2322

2423
expect_length(aa$adapters, 1)
25-
expect_is(aa$adapters[[1]], "CrulAdapter")
24+
expect_s3_class(aa$adapters[[1]], "CrulAdapter")
2625
expect_equal(aa$adapters[[1]]$name, "CrulAdapter")
2726

2827
expect_output(print(aa), "HttpLibAdapaterRegistry")
@@ -36,7 +35,7 @@ test_that("HttpLibAdapaterRegistry: behaves as expected", {
3635
aa$register(HttrAdapter$new())
3736

3837
expect_length(aa$adapters, 1)
39-
expect_is(aa$adapters[[1]], "HttrAdapter")
38+
expect_s3_class(aa$adapters[[1]], "HttrAdapter")
4039
expect_equal(aa$adapters[[1]]$name, "HttrAdapter")
4140

4241
expect_output(print(aa), "HttpLibAdapaterRegistry")
@@ -50,7 +49,7 @@ test_that("HttpLibAdapaterRegistry: behaves as expected", {
5049
aa$register(Httr2Adapter$new())
5150

5251
expect_length(aa$adapters, 1)
53-
expect_is(aa$adapters[[1]], "Httr2Adapter")
52+
expect_s3_class(aa$adapters[[1]], "Httr2Adapter")
5453
expect_equal(aa$adapters[[1]]$name, "Httr2Adapter")
5554

5655
expect_output(print(aa), "HttpLibAdapaterRegistry")

tests/testthat/test-Httr2Adapter.R

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("Httr2Adapter")
2-
31
skip_if_not_installed("httr2")
42
library("httr2")
53

@@ -8,16 +6,16 @@ aa <- Httr2Adapter$new()
86
test_that("Httr2Adapter bits are correct", {
97
skip_on_cran()
108

11-
expect_is(Httr2Adapter, "R6ClassGenerator")
9+
expect_s3_class(Httr2Adapter, "R6ClassGenerator")
1210

13-
expect_is(aa, "Httr2Adapter")
11+
expect_s3_class(aa, "Httr2Adapter")
1412
expect_null(aa$build_httr_request) # pulled out of object, so should be NULL
1513
expect_null(aa$build_httr_response) # pulled out of object, so should be NULL
16-
expect_is(aa$disable, "function")
17-
expect_is(aa$enable, "function")
18-
expect_is(aa$handle_request, "function")
19-
expect_is(aa$remove_stubs, "function")
20-
expect_is(aa$name, "character")
14+
expect_type(aa$disable, "closure")
15+
expect_type(aa$enable, "closure")
16+
expect_type(aa$handle_request, "closure")
17+
expect_type(aa$remove_stubs, "closure")
18+
expect_type(aa$name, "character")
2119

2220
expect_equal(aa$name, "Httr2Adapter")
2321
})
@@ -64,7 +62,6 @@ test_that("Httr2Adapter: works when vcr is loaded but no cassette is inserted",
6462
})
6563

6664

67-
context("Httr2Adapter: date slot")
6865
test_that("Httr2Adapter date slot works", {
6966
skip_on_cran()
7067
skip_if_not_installed("vcr")
@@ -79,7 +76,7 @@ test_that("Httr2Adapter date slot works", {
7976
x <- request(hb("/get")) %>% req_perform()
8077

8178
# $headers$date is a different format
82-
expect_is(x$headers$date, "character")
79+
expect_type(x$headers$date, "character")
8380
expect_error(format(x$headers$date, "%Y-%m-%d %H:%M"), "invalid 'trim'")
8481
})
8582

@@ -89,7 +86,6 @@ test_that("Httr2Adapter date slot works", {
8986
# httr2_obj <- z$request
9087
# save(httr2_obj, file = "tests/testthat/httr2_obj.rda", version = 2)
9188

92-
context("Httr2Adapter: works with real data")
9389
test_that("Httr2Adapter works", {
9490
skip_on_cran()
9591
skip_if_not_installed("vcr")
@@ -117,8 +113,8 @@ test_that("Httr2Adapter works", {
117113

118114
aa <- res$handle_request(httr2_obj)
119115

120-
expect_is(res, "Httr2Adapter")
121-
expect_is(aa, "httr2_response")
116+
expect_s3_class(res, "Httr2Adapter")
117+
expect_s3_class(aa, "httr2_response")
122118
expect_null(aa$request$method)
123119
expect_equal(aa$url, hb("/get"))
124120

@@ -135,8 +131,8 @@ test_that("Httr2Adapter works", {
135131

136132
aa <- res$handle_request(httr2_obj)
137133

138-
expect_is(res, "Httr2Adapter")
139-
expect_is(aa, "httr2_response")
134+
expect_s3_class(res, "Httr2Adapter")
135+
expect_s3_class(aa, "httr2_response")
140136
expect_null(aa$request$method)
141137
expect_equal(aa$url, hb("/get"))
142138

@@ -191,7 +187,7 @@ test_that("Httr2Adapter works with req_auth_basic", {
191187
x <- request(hb("/basic-auth/foo/bar")) %>%
192188
req_auth_basic("foo", "bar") %>%
193189
req_perform()
194-
expect_is(x, "httr2_response")
190+
expect_s3_class(x, "httr2_response")
195191
expect_equal(
196192
jsonlite::fromJSON(rawToChar(x$body)),
197193
list(authenticated = TRUE, user = "foo")
@@ -209,7 +205,7 @@ test_that("Httr2Adapter works with req_auth_basic", {
209205
load("httr2_obj_auth.rda")
210206
zz <- Httr2Adapter$new()
211207
z <- zz$handle_request(httr2_obj_auth)
212-
expect_is(z, "httr2_response")
208+
expect_s3_class(z, "httr2_response")
213209
expect_equal(
214210
jsonlite::fromJSON(rawToChar(z$body)),
215211
list(foo = "bar")

0 commit comments

Comments
 (0)