Skip to content

Autogenerated documentation

Beth Skurrie edited this page Feb 10, 2015 · 7 revisions

To generate markdown documentation from the pact files, in the pact_helper.rb file in the consumer project configure:

Pact.configure do | config |
  config.doc_generator = :markdown
  config.doc_dir = "..." # optional, defaults to "./doc/pacts" 
end

If you would like another type of documentation (eg. HTML), you can roll your own.

An example of the generated documentation follows:


A pact between Zoo App and Animal Service

Requests from Zoo App to Animal Service

Interactions

Given there is an alligator named Mary, upon receiving a request for an alligator from Zoo App, with

{
  "method": "get",
  "path": "/alligators/Mary",
  "headers": {
    "Accept": "application/json"
  }
}

Animal Service will respond with:

{
  "status": 200,
  "headers": {
    "Content-Type": "application/json;charset=utf-8"
  },
  "body": {
    "name": "Mary"
  }
}

Given there is not an alligator named Mary, upon receiving a request for an alligator from Zoo App, with

{
  "method": "get",
  "path": "/alligators/Mary",
  "headers": {
    "Accept": "application/json"
  }
}

Animal Service will respond with:

{
  "status": 404
}

Given an error occurs retrieving an alligator, upon receiving a request for an alligator from Zoo App, with

{
  "method": "get",
  "path": "/alligators/Mary",
  "headers": {
    "Accept": "application/json"
  }
}

Animal Service will respond with:

{
  "status": 500,
  "headers": {
    "Content-Type": "application/json;charset=utf-8"
  },
  "body": {
    "error": "Argh!!!"
  }
}