RSpec JSON Expectations
This project appears to have been a Ruby gem that added JSON matchers to RSpec, most notably an include_json style matcher for checking that a JSON response contains certain keys and values without asserting on the whole document. That approach is popular for API tests, where responses carry timestamps and IDs that change on every run.
Its original feature documentation is no longer published here. The pages below are independent guides to the topics it covered, written for this archive. Code samples show the general technique and are not a reference for any particular gem version.
Guides
- Partial JSON Expectations in RSpec: An Overview
Why partial JSON matching makes API specs more robust, and how an include_json style matcher fits into an RSpec suite.
- Getting Started with an include_json Matcher
A first look at using an include_json style matcher in RSpec request specs: flat expectations, failure output and good habits.
- Nested Hashes in Partial JSON Matching
How nested hash expectations behave in an include_json style RSpec matcher, with examples for objects, arrays of objects and deep paths.
- Matching JSON Values with Regular Expressions in RSpec
Use regular expressions inside partial JSON expectations to check tokens, timestamps and IDs whose exact values change on every run.