-
Notifications
You must be signed in to change notification settings - Fork 17
/
topics-errors.Rmd
22 lines (15 loc) · 1.63 KB
/
topics-errors.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Faking HTTP errors {#errors-chapter}
With HTTP testing you can test the behavior of your package in case of an API error without having to actually trigger an API error.
This is important for testing your package's [gracefulness](#graceful) (informative error message for the user) and robustness (if you e.g. use retrying in case of API errors).
## How to test for API errors (e.g. 503)
Different possibilities:
* Use webmockr as in [our demo](#vcr).
* [Edit a vcr cassette](https://docs.ropensci.org/vcr/articles/cassette-manual-editing.html); be careful to skip this test when vcr is off with `vcr::skip_if_vcr_is_off()`.
* With httptest or httptest2, edit a mock file as in [our demo](#httptest2), or create it from scratch.
* With webfakes, choose what to return, have a specific app for the test, see [our demo](#webfakes).
## How to test for sequence of responses (e.g. 503 then 200)
Different possibilities:
* Use [webmockr](https://docs.ropensci.org/vcr/articles/cassette-manual-editing.html#the-same-thing-with-webmockr-3).
* [Edit a vcr cassette](https://docs.ropensci.org/vcr/articles/cassette-manual-editing.html#example-2-test-using-an-edited-cassette-with-a-503-then-a-200-1); be careful to skip this test when vcr is off with `vcr::skip_if_vcr_is_off()`
* With httptest, this is [not easy yet](https://github.com/nealrichardson/httptest/issues/49) ([httptest2 issue](https://github.com/nealrichardson/httptest2/issues/18))
* With webfakes, follow [the docs](https://r-lib.github.io/webfakes/articles/how-to.html#how-do-i-test-a-sequence-of-requests-). Also have a specific app for the test as this is not the behavior you want in all your tests.`