Skip to content

Commit 27615de

Browse files
committed
swtich webmockr -> vcr for tests
1 parent 921d2fa commit 27615de

9 files changed

+218
-44
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+
tests/fixtures/**/* -diff

DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: allcontributors
22
Title: Acknowledge all Contributors to a Project
3-
Version: 0.0.2.026
3+
Version: 0.0.2.027
44
Authors@R:
55
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"))
66
Description: Acknowledge all contributors to a project via a single
@@ -24,6 +24,7 @@ Suggests:
2424
knitr,
2525
rmarkdown,
2626
testthat,
27+
vcr (>= 0.6.0),
2728
webmockr
2829
VignetteBuilder:
2930
knitr

codemeta.json

+15-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"codeRepository": "https://github.com/ropenscilabs/allcontributors",
1111
"issueTracker": "https://github.com/ropenscilabs/allcontributors/issues",
1212
"license": "https://spdx.org/licenses/GPL-3.0",
13-
"version": "0.0.2.26",
13+
"version": "0.0.2.27",
1414
"programmingLanguage": {
1515
"@type": "ComputerLanguage",
1616
"name": "R",
@@ -73,6 +73,19 @@
7373
},
7474
"sameAs": "https://CRAN.R-project.org/package=testthat"
7575
},
76+
{
77+
"@type": "SoftwareApplication",
78+
"identifier": "vcr",
79+
"name": "vcr",
80+
"version": ">= 0.6.0",
81+
"provider": {
82+
"@id": "https://cran.r-project.org",
83+
"@type": "Organization",
84+
"name": "Comprehensive R Archive Network (CRAN)",
85+
"url": "https://cran.r-project.org"
86+
},
87+
"sameAs": "https://CRAN.R-project.org/package=vcr"
88+
},
7689
{
7790
"@type": "SoftwareApplication",
7891
"identifier": "webmockr",
@@ -185,7 +198,7 @@
185198
}
186199
],
187200
"readme": "https://github.com/ropenscilabs/allcontributors/blob/main/README.md",
188-
"fileSize": "65.26KB",
201+
"fileSize": "93.422KB",
189202
"contIntegration": ["https://github.com/ropenscilabs/allcontributors/actions?query=workflow%3AR-CMD-check", "https://codecov.io/gh/ropenscilabs/allcontributors"],
190203
"developmentStatus": "https://www.repostatus.org/#active",
191204
"provider": {

tests/fixtures/get_contribs.yml

+153
Large diffs are not rendered by default.

tests/fixtures/testing.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
http_interactions:
2+
- request:
3+
method: head
4+
uri: https://httpbin.org/get
5+
body:
6+
encoding: ''
7+
string: ''
8+
headers:
9+
User-Agent: libcurl/7.79.1 r-curl/4.3.2 crul/1.1.0
10+
response:
11+
status:
12+
status_code: '200'
13+
message: OK
14+
explanation: Request fulfilled, document follows
15+
headers:
16+
status: 'HTTP/2 200 '
17+
date: Thu, 07 Oct 2021 11:17:59 GMT
18+
content-type: application/json
19+
content-length: '334'
20+
server: gunicorn/19.9.0
21+
access-control-allow-origin: '*'
22+
access-control-allow-credentials: 'true'
23+
body:
24+
encoding: UTF-8
25+
file: no
26+
string: ''
27+
recorded_at: 2021-10-07 11:17:59 GMT
28+
recorded_with: vcr/1.0.2, webmockr/0.8.0

tests/testthat/geodist-hdrs.Rds

-856 Bytes
Binary file not shown.

tests/testthat/geodist.Rds

-447 Bytes
Binary file not shown.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
library("vcr") # *Required* as vcr is set up on loading
2+
invisible(vcr::vcr_configure(
3+
dir = vcr::vcr_test_path("fixtures")
4+
))
5+
vcr::check_cassette_names()

tests/testthat/test-get-contribs.R

+13-41
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,18 @@
1-
context("webmockr")
1+
context("get contributors")
22

3-
u_base <- "https://api.github.com"
4-
path <- "repos/hypertidy/geodist/contributors"
5-
u <- httr::modify_url (u_base, path = path)
6-
#z <- httr::GET (u)
7-
#saveRDS (httr::content (z), file = "geodist.Rds")
8-
#saveRDS (z$headers, file = "geodist-hdrs.Rds")
3+
test_that("get_contributors", {
94

10-
library (webmockr)
11-
httr_mock()
5+
vcr::use_cassette("get_contribs", {
126

13-
test_all <- (identical (Sys.getenv ("MPADGE_LOCAL"), "true"))
14-
if (test_all) {
15-
tok1 <- Sys.getenv ("GITHUB_TOKEN")
16-
tok2 <- Sys.getenv ("GITHUB_GRAPHQL_TOKEN")
17-
Sys.unsetenv ("GITHUB_TOKEN")
18-
Sys.unsetenv ("GITHUB_GRAPHQL_TOKEN")
19-
}
20-
21-
22-
stub_request ("get", uri = u) %>%
23-
wi_th (
24-
headers = list ("Accept" =
25-
"application/json, text/xml, application/xml, */*")
26-
) %>%
27-
to_return(status = 200,
28-
body = readRDS ("geodist.Rds"),
29-
headers = readRDS ("geodist-hdrs.Rds"))
30-
31-
test_that("vcr test", {
32-
33-
org <- "hypertidy"
34-
repo <- "geodist"
35-
x <- get_gh_code_contributors (org, repo)
7+
x <- get_contributors (org = "hypertidy", repo = "geodist")
8+
})
369

3710
expect_is (x, "data.frame")
38-
expect_equal (ncol (x), 3)
39-
expect_identical (names (x), c ("logins", "contributions", "avatar"))
40-
41-
})
42-
43-
if (test_all) {
44-
Sys.setenv ("GITHUB_TOKEN" = tok1)
45-
Sys.setenv ("GITHUB_GRAPHQL_TOKEN" = tok2)
46-
}
11+
expect_equal (ncol (x), 4)
12+
expect_identical (names (x),
13+
c ("logins", "contributions", "avatar", "type"))
14+
expect_true (all (unique (x$type) %in% c ("code",
15+
"issue_authors",
16+
"issue_contributors")))
17+
18+
})

0 commit comments

Comments
 (0)