"Pact" is an implementation of "consumer driven contract" testing that allows mocking of responses in the consumer codebase, and verification of the interactions in the provider codebase. The initial implementation was written in Ruby for Rack apps, however a consumer and provider may be implemented in different programming languages, so the "mocking" and the "verifying" steps would be best supported by libraries in their respective project's native languages. Given that the pact file is written in JSON, it should be straightforward to implement a pact library in any language, however, to get the best experience and most reliability of out mixing pact libraries, the matching logic for the requests and responses needs to be identical. There is little confidence to be gained in having your pacts "pass" if the logic used to verify a "pass" is inconsistent between implementations.
To support consistency of matching logic, the Pact-specification has been developed as a benchmark that all pact libraries can check themselves against if they want to ensure consistency with other pact libraries.
Pact Specificaton Philosophy
The Pact matching rules follow Postel's Law.
Be as strict as we reasonably can with what we send out (requests).
We should know and be able to control exactly what a consumer is sending out. Information should not be allowed to "leak" silently.
Be as loose as we reasonably can with what we accept (responses).
A provider should be able to send extra information that this particular consumer does not care about, without breaking this consumer.
When writing the matching rules, err on the side of being more strict now, because it will break fewer things to be looser later, than to get stricter later.
Note: One implications of this philosophy is that you cannot verify, using pact, that a key or a header will not be present in a response. You can only verify what is.
JSON schemas - Currently for v1 / v2
Version 1 - A spec that describes the existing matching in the ruby implementation, and provides test cases for implementations in other languages to ensure that matching is consistent.
Version 1.1 - Updated specification shared between Ruby, JVM and .Net versions.
Version 2 - Introduces non-language specific regular expression and type matching.
Version 3 - Introduces pact format for message queues and corrects some issues with V2.
X - Implemented and actively supported 1 - Implemented in beta 0 - Implemented and not actively supported
All new Pact implementations should wrap the Rust implementation using FFI calls, to allow us to roll out new features quickly and consistently across our 10+ Pact languages.
Support is appreciated if you wish to contribute in migrating a language from the Ruby to Rust core, or wish to create a new language implementation
In order to faciliate the move to from v2 to v3 specification, in the respective client libraries, migration guides have been written to help to transition across.
- A migration between pact specifications, for existing published contracts, will trigger a rule
contract_requiring_verification_publishedevent type as the generated matcher rules may have changed between specifications.