https://github.com/louis-kevin/vcr
A dart VCR
https://github.com/louis-kevin/vcr
client dart dio flutter flutter-package mock tests vcr
Last synced: 8 months ago
JSON representation
A dart VCR
- Host: GitHub
- URL: https://github.com/louis-kevin/vcr
- Owner: louis-kevin
- License: mit
- Created: 2019-12-17T14:24:25.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2023-05-15T07:03:06.000Z (about 3 years ago)
- Last Synced: 2025-10-22T23:54:40.788Z (8 months ago)
- Topics: client, dart, dio, flutter, flutter-package, mock, tests, vcr
- Language: Dart
- Homepage: https://pub.dev/packages/vcr
- Size: 137 KB
- Stars: 9
- Watchers: 1
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# vcr
A package to mock requests using Dio Client

## Getting Started
To start using, just create a adapter and put inside your client
This is a example with Dio client:
```
VcrAdapter adapter = VcrAdapter({basePath:'test/cassettes', createIfNotExists: true });
Dio client = Dio();
client.httpClientAdapter = adapter;
```
After config the adapter, you now can use a cassette
```
Response response = await client.get('https://api.github.com/users/louis-kevin/repos');
expect(response.statusCode, 200);
```
Now the request is stored in `test/cassette/users/louis-kevin/repos.json`
If you have multiple requests for one test, they will be added in a list of requests
If the adapter can't find the right request, he will make a normal request and then store the request
This package is inspired by VCR gem
#### Options
| option | type | description | default |
|-------------------|---------|---------------------------------------------------------------------------|----------------|
| basePath | string | Path to store your cassettes, relative to root | test/cassettes |
| createIfNotExists | boolean | If this is disabled, you need to call `useCassette` before call your api | true |
### Using useCassette
The only main difference is that you need to call `useCassette` before calling your API
```
adapter.useCassette('github/my_casssete')
Response response = await client.get('https://api.github.com/users/louis-kevin/repos');
expect(response.statusCode, 200);
```
You can choose passing `.json` format or not, it will store the cassette in json either way
Now the request is stored in `test/cassette/github/my_casssete.json`
#### Next Features
- [ ] Work with Http Package
- [ ] Work with YAML