git clone https://github.com/skyrex-mark/Pact-Tutorial-for-Beginner.git
- Install ruby 2.2.0 or later and bundler >= 1.12.0
- Windows users: get a Rails/Ruby installer from RailsInstaller and run it
- unix users
sudo apt install ruby-full
- oepn a new terminal
- Run
git clone https://github.com/pact-foundation/pact_broker.git && cd pact_broker/example
orcd pact_broker/example
- Run
bundle install
- Run
bundle exec rackup -p 8080
(this will use a Sqlite database. If you want to try it out with a Postgres database, see the README in the example directory.) - Open http://localhost:8080 and you should see a list containing the pact between the Zoo App and the Animal Service
- Click the name of either a provider or consumer
- Click on the arrow to see the generated HTML documentation
- Click on either service to see an autogenerated network diagram
- Click on the HAL Browser link to have a poke around the API
- Click on the book icon under "docs" to view documentation related to a given relation
- open a new terminal
cd
to client directory- run
npm install
oryarn install
- run
npm run test
oryarn test
, if the test fails , try to runmocha -t 50000 consumer.spec.js
instead - a pact file will be genreated in the
pacts
folder - run
npm run publish
oryarn publish
, the pact file.will be published to the local pact broker
- open a new terminal
cd api-service
- run
npm install
oryarn install
. - run
npm start
oryarn start
to spin up .a local api service - open a new terminal
cd
to api-service directory- run
npm run test
oryarn test
to retrieve the pact from the local broker , verify the pact with local service and send the verification result back to the pact broker
-
Install Docker from here https://www.docker.com/community-edition
-
open a new terminal
-
git clone https://github.com/DiUS/pact_broker-docker.git
-
cd pact_broker-docker
-
run
docker-compose up
-
Wait for the pact broker to go online( 2-5 min)
-
navigate to
http://localhost
to see the pact brokerClient:
- Go to the
client
directory - Open
publish.js
- Change
pactBroker: 'http://localhost:8080'
topactBroker: 'http://localhost'
Provider:
- Go to the
api-service
directory - Open
provider.spec.js
- Change
pactUrls: [ 'http://localhost:8080/pacts/provider/sender/consumer/receiver/latest' ]
topactUrls: [ 'http://localhost/pacts/provider/sender/consumer/receiver/latest
- Go to the
@JiahuaZhang for helping me to review this tutorial.