Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fake vcr cassette #8

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
tests/fixtures/**/* -diff
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
Suggests:
testthat
testthat,
vcr
Config/testthat/edition: 3
Imports:
purrr,
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions tests/fixtures/error-status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
http_interactions:
- request:
method: get
uri: https://kctbh9vrtdwd.statuspage.io/api/v2/components.json
body:
encoding: ''
string: ''
headers:
Accept: application/json, text/xml, application/xml, */*
response:
status:
status_code: 502
recorded_at: 2020-11-12 15:29:07 GMT
recorded_with: vcr/0.5.4, webmockr/0.7.0
492 changes: 492 additions & 0 deletions tests/fixtures/organizations.yml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions tests/testthat/helper-exemplighratia.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
library("vcr")
invisible(vcr::vcr_configure(
dir = "../fixtures",
filter_sensitive_data = list("<<github_api_token>>" = Sys.getenv('GITHUB_PAT'))
))
vcr::check_cassette_names()
5 changes: 4 additions & 1 deletion tests/testthat/test-api-status.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
test_that("gh_api_status() works", {
testthat::expect_type(gh_api_status(), "character")
vcr::use_cassette("error-status", {
testthat::expect_error(gh_api_status())
})

})
7 changes: 6 additions & 1 deletion tests/testthat/test-organizations.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
vcr::use_cassette("organizations", {
test_that("gh_organizations works", {
testthat::expect_type(gh_organizations(), "character")

testthat::expect_message(foo <- gh_organizations(), "Retrying")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see @sckott it's a case where I think it's easier to just wrap the whole test with use_cassette(). 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: when one wraps the whole test in use_cassette(), there's no straightforward way to "skip" the test.


testthat::expect_type(foo, "character")
})
})