Configuration

Menu

Consumer and Provider configuration options

Consumer only configuration options

Provider only configuration options

Consumer and Provider

log_dir

  1. Pact.configure do | config |
  2. config.log_dir = './log'
  3. end

Default value: ./log

logger

  1. Pact.configure do | config |
  2. config.logger = Logger.new
  3. end

Default value: file logger to the configured log_dir.

logger.level

  1. Pact.configure do | config |
  2. config.logger.level = Logger::INFO
  3. end

Default value: Logger::DEBUG

diff_formatter

  1. Pact.configure do | config |
  2. config.diff_formatter = :list
  3. end

Default value: :list

Options: :unix, :list, :embedded, Custom Diff Formatter

:unix

Configuration - 图1

:list

Configuration - 图2

:embedded

Configuration - 图3

Custom Diff Formatter

Any object can be used that responds to call, accepting the argument diff.

  1. class MyCustomDiffFormatter
  2. def self.call diff
  3. ### Do stuff here
  4. end
  5. end
  6. Pact.configure do | config |
  7. config.diff_formatter = MyCustomDiffFormatter
  8. end

Consumer

pact_dir

  1. Pact.configure do | config |
  2. config.pact_dir = `./spec/pacts`
  3. end

Default value: ./spec/pacts

doc_generator

  1. Pact.configure do | config |
  2. config.doc_generator = :markdown
  3. end

Default value: none

Options: :markdown, Custom Doc Generator

:markdown

Generates Markdown documentation based on the contents of the pact files created in this consumer. Files are created in ${Pact.configuration.doc_dir}/markdown.

Custom Doc Generator

Any object can be used that responds to call, accepting the arguments pact_dir and doc_dir.

  1. Pact.configure do | config |
  2. config.doc_generator = lambda{ | pact_dir, doc_dir | generate_some_docs(pact_dir, doc_dir) }
  3. end

doc_dir

  1. Pact.configure do | config |
  2. config.doc_dir = './doc'
  3. end

Default value: ./doc

pactfile_write_mode

Default value: :overwrite
Options: :overwrite, :update, :smart, :none

By default, the pact file will be overwritten (started from scratch) every time any rspec runs any spec using pacts. This means that if there are interactions that haven’t been executed in the most recent rspec run, they are effectively removed from the pact file. If you have long running pact specs (e.g. they are generated using the browser with Capybara) and you are developing both consumer and provider in parallel, or trying to fix a broken interaction, it can be tedious to run all the specs at once. In this scenario, you can set the pactfile_write_mode to :update. This will keep all existing interactions, and update only the changed ones, identified by description and provider state. The down side of this is that if either of those fields change, the old interactions will not be removed from the pact file. As a middle path, you can set pactfile_write_mode to :smart. This will use :overwrite mode when running rake (as determined by a call to system using ‘ps’) and :update when running an individual spec. :none will not generate any pact files (with pact-mock_service >= 0.8.1).

Provider

Pact uses RSpec and Rack::Test to create dynamic specs based on the pact files. RSpec configuration can be used to modify test behaviour if there is not an appropriate Pact feature. If you wish to use the same spec_helper.rb file as your unit tests, require it in the pact_helper.rb, but remember that the RSpec configurations for your unit tests may or may not be what you want for your pact verification tests.

include

  1. Pact.configure do | config |
  2. config.include MyTestHelperMethods
  3. end

To make modules available in the provider state set_up and tear_down blocks, include them in the configuration as shown below. One common use of this to include factory methods for setting up data so that the provider states file doesn’t get too bloated.