When you declare a request and response using the traditional Pact DSL, ("uponReceiving" and "willRespondWith") you're building a structure that has three purposes -
- it provides the concrete example request and response used in the tests
- it specifies the contents of the contract which...
- defines how to validate the the actual request/response against the expected request/response
The three different uses of this structure are hidden from you when using HTTP Pact because the mock service handles numbers 1 & 2 in the consumer tests, and the verification task handles number 3 for you in the provider tests. When using Pact in a non-HTTP scenario, there is no nice neat protocol layer to inject the code to do this for you, so you have to explicitly do each step.
expected_data_from_collector.rb declares an object graph using the Pact DSL. This is going to be used to create the concrete example and the contract. This could be declared inline, but for easier maintenance, and to allow the contract publishing code to easily access it, it's in a separate file.
consumer.rb takes that object graph declared in
expected_data_from_collector.rb, and generates an example JSON document from it (that's what
FixtureHelpers.load_generated_pact_fixture does). It then uses that JSON document in a test to show that it can handle the document we expect.
consumer_publish_contract.rb shows how we take that same object graph and turn it into the JSON Pact-like contract, and publish it to the pact broker.
fixture_helpers.rb shows the code that is used to turn the object graph declared using the Pact DSL into the example structure.
z_provider.rb contains a test that uses the contract that we retrieve from the pact broker. It shows that the output that we produce contains all the data that the consumer expects (of course, it may contain extra data without it being a problem).