thoughtworks/pacto — pull request #118 by maxlinc (2014-06-04 20:49:20+00:00)
Title: Stubbing/Simulating by example

This adds one major new feature: the ability to use example requests/responses in order to simulate a service consumer or stub a service provider. The feature basically works as described in #113, but it does not update meta-validation to validate each example (it will only validate the first).

This feature is backwards compatible, because it falls back to the old behavior if the Contract doesn't have any examples - and since examples were just added no existing contracts have examples.

This implements a big chunk of #113, #114, and #115 and lays the groundwork for #116. So there was a lot of refactoring and improvements that went into this, to make things more extensible and testable. The code still isn't clean, but it's moving towards classes that better adhere to the [SRP](http://en.wikipedia.org/wiki/Single_responsibility_principle) and cleaner design patterns.

Some improvements here or in recently merged refactors include:
- The WebMockAdapter is getting closer the Adapter pattern. It should be a thin mapping between WebMock and Pacto classes and APIs, and shouldn't have much logic about Pacto's features.
- Related: the WebMockHelper is virtually gone, and replaced with the far simpler HTTPMiddleware, which uses the Observer pattern so it doesn't need to know all the different features that may process the http requests (generation/reporting/logging/post-processing/etc)
- Creating Consumer and Provider APIs that are pluggable (e.g. you can swap out the Faraday HTTP driver, or the class that handles creating stubbed responses). The Contract class delegates to these APIs now, rather than the simulationg/stubbing logic being inside the contract or it's composite classes (RequestClause and ResponseClause).
- Replaced a lot of mocking with objects created using Fabrication factories.