Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gergness/crunchtestdemo
https://github.com/gergness/crunchtestdemo
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/gergness/crunchtestdemo
- Owner: gergness
- License: lgpl-2.1
- Created: 2020-05-06T14:50:05.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-07T15:57:32.000Z (over 4 years ago)
- Last Synced: 2023-03-23T12:59:37.225Z (almost 2 years ago)
- Language: R
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# crunchtestdemo
Demo usage of httptest to capture mocks from the crunch API.In this
[commit](https://github.com/gergness/crunchtestdemo/commit/cce311a552ee45baf4cffe5d3e99426339570bb3),
we go from a (simple) working but untested package,
to one that uses httptest to have mock tests.## Key steps
- file
[`inst/httptest/redact.R`](https://github.com/gergness/crunchtestdemo/blob/cce311a552ee45baf4cffe5d3e99426339570bb3/inst/httptest/redact.R)
pulls the `crunch` package's redaction file
which helps make sure that `httptest::capture_requests()` doesn't include
tokens, and also does some other pruning on the requests.
- file
[`fixture-creation/fixture_1.R`](https://github.com/gergness/crunchtestdemo/blob/cce311a552ee45baf4cffe5d3e99426339570bb3/fixture-creation/fixture_1.R)
is a replayable script that makes the requests we need for a test and saves them into
this folder
[`tests/testthat/fixture1`](https://github.com/gergness/crunchtestdemo/tree/cce311a552ee45baf4cffe5d3e99426339570bb3/tests/testthat/fixture1).
- Now the test in
[`tests/testthat/test-crunch_mean_by.R`](https://github.com/gergness/crunchtestdemo/blob/cce311a552ee45baf4cffe5d3e99426339570bb3/tests/testthat/test-crunch_mean_by.R)
can use the fixture.
I've run the same set of tests twice, once with the options being set
explicitly, and another with a function modeled after `with_mock_crunch()`
from the crunch package. I modified it so that it takes a directory path,
because I would recommend not having overlapping mocks like the crunch
does.