You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the request side, you can now match the request body against one or
more substrings and regular expressions, which makes life easier for
those of us who need to deal with request bodies that have
non-deterministic elements in them (like nonces).
On the response side. you can now write your JSON response bodies *as
JSON*, which is significantly easier than having to escape
eleventy-billion quotes, and match up braces by eye.
To avoid any bloat or unpleasant interactions with existing code, all
the new features are gated behind, well, features.
Copy file name to clipboardExpand all lines: README.md
+38Lines changed: 38 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -89,6 +89,44 @@ To deserialize `.yaml` Cassette files use
89
89
$ cargo add vcr-cassette
90
90
```
91
91
92
+
## Features
93
+
94
+
*`json` -- enables parsing and comparison of JSON request and response bodies.
95
+
Saves having to escape every double quote character in your JSON-format bodies when you're manually
96
+
writing them. Looks like this:
97
+
98
+
```json
99
+
{
100
+
"body": {
101
+
"json": {
102
+
"arbitrary": ["json", "is", "now", "supported"],
103
+
"success_factor": 100,
104
+
}
105
+
}
106
+
}
107
+
```
108
+
109
+
*`matching` -- provides a mechanism for specifying "matchers" for request bodies, rather than a request body
110
+
having to be byte-for-byte compatible with what's specified in the cassette. There are currently two match types available, `substring` and `regex` (if the `regex` feature is also enabled).
111
+
They do more-or-less what they say on the tin. Use them like this:
112
+
113
+
```json
114
+
{
115
+
"body": {
116
+
"matches": [
117
+
{ "substring": "something" },
118
+
{ "substring": "funny" },
119
+
{ "regex": "\\d+" }
120
+
]
121
+
}
122
+
}
123
+
```
124
+
125
+
The above stanza, appropriately placed in a *request* specification, will match any request whose body contains the strings `"something"`, and `"funny"`, and *also* contains a number (of any length).
126
+
127
+
*`regex` -- Enables the `regex` match type.
128
+
This is a separate feature, because the `regex` crate can be a bit heavyweight for resource-constrained environments, and so it's optional, in case you don't need it.
129
+
92
130
## Safety
93
131
This crate uses ``#![deny(unsafe_code)]`` to ensure everything is implemented in
0 commit comments