"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, this 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.
The Pact matching rules follow Postel's Law.
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.
Since some pact implementations call others, it's helpful to have guidelines for the log levels.
Error
: Something has gone wrong or there were test failuresWarn
: We think you may be using something incorrectly, or you’ve turned off some safety switches.Info
: You probably want to know this every time you run pact, and if tests are failing here is an explanationDebug
: Information to help users know exactly what is happening during their tests (eg if they want to debug a failing test)Trace
: Very detailled information to help maintainers debug pactThe default log level (if any) should be info.
JSON schemas - Pact Specification as a series of JSON schemas. To see the key differences between versions, see https://github.com/pactflow/pact-schemas/blob/main/src/index.ts.
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.
Version 4 - Adds lots of new features, see RFC #71 for details.