Skip to content

How to extend Pact for different content types

Beth Skurrie edited this page Jun 9, 2016 · 1 revision

1. Make a differ

This must return a structure representing the differences between the expected and the actual content.

eg. The existing Pact JSON Differ and the bare bones of the XML Differ here

2. Make a diff formatter

This should accept the diff created by the differ, and turn it into a string in a human readable format. Some examples are the UnixDiffFormatter and the EmbeddedDiffFormatter. For an example of how the diffs are represented, have a look at the documentation.

3. Configure the matching with the differ and formatter

require 'pact'
require 'pact/xml'

Pact.configure do | config |

    config.register_body_differ /xml/, Pact::XML::Differ
    config.register_diff_formatter /xml/, Pact::XML::DiffFormatter

end