An example implementation of the pacto library.
This example tests a simple HTTP api that provides json responses. There are two endpoints (ping
and /lat/lon
) and a generic 404 response test. To run it:
bundle exec rake pacto:validate['https://tide-api.herokuapp.com','contracts']
Pacto can act as a stub server, and it will respond with data present in the examples
part of the contracts. As a stub server, it will also validate that request and response conform to contract. To run the server:
bundle exec pacto-server -sv -V --stub
You can then send requests to the stub server:
curl localhost:9000/ping
or
curl localhost:9000//23.98E/11.45N
Pacto server can also act as a middleman, and proxy requests to a live service while validating the request and response contract. This is particularly valuable for integration testing, to provide confidence that both the stubbing and the contract testing are valuable on their own. You can run the server as a middleman like this:
bundle exec pacto-server -sv -V --live -H https://tide-api.herokuapp.com
and then execute a request that will fail validation against the contract:
curl localhost:9000/23.98E/11.45N
Visit the pacto website for full documentation and other ways to use the library: https://thoughtworks.github.io/pacto/