pact 1.4.0.rc4 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +13 -0
- data/lib/pact/consumer/configuration/mock_service.rb +2 -1
- data/lib/pact/consumer/consumer_contract_builder.rb +2 -1
- data/lib/pact/version.rb +1 -1
- data/pact.gemspec +4 -3
- metadata +32 -205
- data/.gitignore +0 -29
- data/.rspec +0 -2
- data/.travis.yml +0 -8
- data/Gemfile +0 -9
- data/Gemfile.lock +0 -108
- data/README.md +0 -314
- data/Rakefile +0 -9
- data/config.ru +0 -3
- data/documentation/README.md +0 -13
- data/documentation/configuration.md +0 -166
- data/documentation/diff_formatter_embedded.png +0 -0
- data/documentation/diff_formatter_list.png +0 -0
- data/documentation/diff_formatter_unix.png +0 -0
- data/example/animal-service/Gemfile +0 -14
- data/example/animal-service/Gemfile.lock +0 -69
- data/example/animal-service/Rakefile +0 -5
- data/example/animal-service/config.ru +0 -3
- data/example/animal-service/db/animal_db.sqlite3 +0 -0
- data/example/animal-service/lib/animal_service/animal_repository.rb +0 -12
- data/example/animal-service/lib/animal_service/api.rb +0 -29
- data/example/animal-service/lib/animal_service/db.rb +0 -5
- data/example/animal-service/spec/service_consumers/pact_helper.rb +0 -11
- data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +0 -26
- data/example/zoo-app/Gemfile +0 -12
- data/example/zoo-app/Gemfile.lock +0 -63
- data/example/zoo-app/Rakefile +0 -5
- data/example/zoo-app/doc/pacts/markdown/README.md +0 -3
- data/example/zoo-app/doc/pacts/markdown/Zoo App - Animal Service.md +0 -75
- data/example/zoo-app/lib/zoo_app/animal_service_client.rb +0 -31
- data/example/zoo-app/lib/zoo_app/models/alligator.rb +0 -17
- data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +0 -67
- data/example/zoo-app/spec/service_providers/animal_service_client_spec.rb +0 -71
- data/example/zoo-app/spec/service_providers/pact_helper.rb +0 -15
- data/example/zoo-app/spec/spec_helper.rb +0 -6
- data/scratchpad.rb +0 -52
- data/spec/features/consumption_spec.rb +0 -114
- data/spec/features/production_spec.rb +0 -155
- data/spec/features/provider_states/zebras.rb +0 -28
- data/spec/integration/consumer_async_request_spec.rb +0 -46
- data/spec/integration/consumer_more_than_one_matching_interaction_spec.rb +0 -49
- data/spec/integration/consumer_no_matching_interaction_spec.rb +0 -53
- data/spec/integration/consumer_with_a_provider_state_spec.rb +0 -44
- data/spec/integration/consumer_with_form_hash_spec.rb +0 -62
- data/spec/integration/consumer_with_form_spec.rb +0 -50
- data/spec/integration/consumer_with_params_hash_spec.rb +0 -122
- data/spec/integration/pact/consumer_configuration_spec.rb +0 -66
- data/spec/integration/pact/provider_configuration_spec.rb +0 -25
- data/spec/lib/pact/cli_spec.rb +0 -47
- data/spec/lib/pact/configuration_spec.rb +0 -297
- data/spec/lib/pact/consumer/app_manager_spec.rb +0 -41
- data/spec/lib/pact/consumer/configuration_spec.rb +0 -57
- data/spec/lib/pact/consumer/consumer_contract_builder_spec.rb +0 -69
- data/spec/lib/pact/consumer/interaction_builder_spec.rb +0 -87
- data/spec/lib/pact/consumer/interactions_spec.rb +0 -64
- data/spec/lib/pact/consumer/mock_service/app_spec.rb +0 -52
- data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +0 -78
- data/spec/lib/pact/consumer/mock_service/interaction_mismatch_spec.rb +0 -70
- data/spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb +0 -12
- data/spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb +0 -88
- data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +0 -142
- data/spec/lib/pact/consumer/service_consumer_spec.rb +0 -11
- data/spec/lib/pact/doc/generator_spec.rb +0 -84
- data/spec/lib/pact/doc/interaction_view_model_spec.rb +0 -132
- data/spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb +0 -29
- data/spec/lib/pact/doc/markdown/index_renderer_spec.rb +0 -29
- data/spec/lib/pact/provider/configuration/configuration_extension_spec.rb +0 -17
- data/spec/lib/pact/provider/configuration/pact_verification_spec.rb +0 -43
- data/spec/lib/pact/provider/configuration/service_provider_config_spec.rb +0 -21
- data/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb +0 -108
- data/spec/lib/pact/provider/configuration_spec.rb +0 -50
- data/spec/lib/pact/provider/matchers/messages_spec.rb +0 -116
- data/spec/lib/pact/provider/pact_helper_locator_spec.rb +0 -54
- data/spec/lib/pact/provider/print_missing_provider_states_spec.rb +0 -19
- data/spec/lib/pact/provider/request_spec.rb +0 -78
- data/spec/lib/pact/provider/rspec/formatter_rspec_2_spec.rb +0 -68
- data/spec/lib/pact/provider/rspec/formatter_rspec_3_spec.rb +0 -72
- data/spec/lib/pact/provider/rspec_spec.rb +0 -55
- data/spec/lib/pact/provider/state/provider_state_manager_spec.rb +0 -89
- data/spec/lib/pact/provider/state/provider_state_proxy_spec.rb +0 -80
- data/spec/lib/pact/provider/state/provider_state_spec.rb +0 -213
- data/spec/lib/pact/provider/world_spec.rb +0 -41
- data/spec/lib/pact/tasks/task_helper_spec.rb +0 -74
- data/spec/lib/pact/tasks/verification_task_spec.rb +0 -75
- data/spec/pact_specification/compliance-1.0.0.rb +0 -47
- data/spec/spec_helper.rb +0 -22
- data/spec/standalone/consumer_fail_test.rb +0 -55
- data/spec/standalone/consumer_pass_test.rb +0 -51
- data/spec/support/a_consumer-a_producer.json +0 -32
- data/spec/support/a_consumer-a_provider.json +0 -32
- data/spec/support/active_support_if_configured.rb +0 -6
- data/spec/support/app_for_config_ru.rb +0 -4
- data/spec/support/case-insensitive-response-header-matching.json +0 -21
- data/spec/support/case-insensitive-response-header-matching.rb +0 -15
- data/spec/support/consumer_contract_template.json +0 -24
- data/spec/support/factories.rb +0 -82
- data/spec/support/generated_index.md +0 -4
- data/spec/support/generated_markdown.md +0 -55
- data/spec/support/interaction_view_model.json +0 -63
- data/spec/support/interaction_view_model_with_terms.json +0 -50
- data/spec/support/markdown_pact.json +0 -48
- data/spec/support/missing_provider_states_output.txt +0 -25
- data/spec/support/options.json +0 -21
- data/spec/support/options_app.rb +0 -15
- data/spec/support/pact_helper.rb +0 -57
- data/spec/support/shared_examples_for_request.rb +0 -94
- data/spec/support/spec_support.rb +0 -20
- data/spec/support/stubbing.json +0 -22
- data/spec/support/stubbing_using_allow.rb +0 -29
- data/spec/support/term.json +0 -48
- data/spec/support/test_app_fail.json +0 -61
- data/spec/support/test_app_pass.json +0 -38
- data/spec/support/test_app_with_right_content_type_differ.json +0 -23
- data/tasks/pact-test.rake +0 -114
- data/tasks/spec.rake +0 -8
data/README.md
DELETED
@@ -1,314 +0,0 @@
|
|
1
|
-
# Pact
|
2
|
-
|
3
|
-
Define a pact between service consumers and providers, enabling "consumer driven contract" testing.
|
4
|
-
|
5
|
-
Pact provides an fluent API for service consumers to define the HTTP requests they will make to a service provider and the HTTP responses they expect back. These expectations are used in the consumer specs to provide a mock service provider. The interactions are recorded, and played back in the service provider specs to ensure the service provider actually does provide the response the consumer expects.
|
6
|
-
|
7
|
-
This allows testing of both sides of an integration point using fast unit tests.
|
8
|
-
|
9
|
-
This gem is inspired by the concept of "Consumer driven contracts". See [this article](http://martinfowler.com/articles/consumerDrivenContracts.html) by Martin Fowler for more information.
|
10
|
-
|
11
|
-
Travis CI Status: [![travis-ci.org Build Status](https://travis-ci.org/realestate-com-au/pact.png)](https://travis-ci.org/realestate-com-au/pact)
|
12
|
-
|
13
|
-
## What is it good for?
|
14
|
-
|
15
|
-
Pact is most valuable for designing and testing integrations where you (or your team/organisation/partner organisation) control the development of both the consumer and the provider. It is fantastic tool for testing intra-organsation microservices.
|
16
|
-
|
17
|
-
## What is it not good for?
|
18
|
-
|
19
|
-
* Performance and load testing.
|
20
|
-
* Functional testing of the provider - that is what the provider's own tests should do. Pact is about checking the contents and format of requests and responses.
|
21
|
-
* Situations where you cannot load data into the provider without using the API that you're actually testing.
|
22
|
-
|
23
|
-
## Features
|
24
|
-
|
25
|
-
* A service is mocked using an actual process running on a specified port, so javascript clients can be tested as easily as backend clients.
|
26
|
-
* "Provider states" (similar to fixtures) allow the same request to be made with a different expected response.
|
27
|
-
* Consumers specify only the fields they are interested in, allowing a provider to return more fields without breaking the pact. This allows a provider to have a different pact with a different consumer, and know which fields each cares about in a given response.
|
28
|
-
* RSpec and Minitest support for the service consumer codebase.
|
29
|
-
* Rake tasks allow pacts to be verified against a service provider codebase.
|
30
|
-
* Different versions of a consumer/provider pairs can be easily tested against each other, allowing confidence when deploying new versions of each (see the pact_broker and pact_broker-client gems).
|
31
|
-
* Autogenerated API documentation - need we say more?
|
32
|
-
* Autogenerated network diagrams with the [Pact Broker](https://github.com/bethesque/pact_broker)
|
33
|
-
|
34
|
-
## How does it work?
|
35
|
-
|
36
|
-
1. In the specs for the provider facing code in the consumer project, expectations are set up on a mock service provider.
|
37
|
-
1. When the specs are run, the mock service returns the expected responses. The requests, and their expected responses, are then written to a "pact" file.
|
38
|
-
1. The requests in the pact file are later replayed against the provider, and the actual responses are checked to make sure they match the expected responses.
|
39
|
-
|
40
|
-
## Why is developing and testing with Pact better than using traditional system integration tests?
|
41
|
-
|
42
|
-
* Faster execution.
|
43
|
-
* Reliable responses from mock service reduce likelihood of flakey tests.
|
44
|
-
* Causes of failure are easier to identify as only one component is being tested at a time.
|
45
|
-
* Design of service provider is improved by considering first how the data is actually going to be used, rather than how it is most easily retrieved and serialised.
|
46
|
-
* No separate integration environment required for automated integration tests - pact tests run in standalone CI builds.
|
47
|
-
* Integration flows that would traditionally require running multiple services at the same time can be broken down and each integration point tested separately.
|
48
|
-
|
49
|
-
## Contact
|
50
|
-
|
51
|
-
* Twitter: [@pact_up](https://twitter.com/pact_up)
|
52
|
-
* Google users group: https://groups.google.com/forum/#!forum/pact-support
|
53
|
-
|
54
|
-
## Installation
|
55
|
-
|
56
|
-
Put it in your Gemfile. You know how.
|
57
|
-
|
58
|
-
## Usage
|
59
|
-
|
60
|
-
### Service Consumer project
|
61
|
-
|
62
|
-
#### 1. Start with your model
|
63
|
-
|
64
|
-
Imagine a model class that looks something like this. The attributes for a Something live on a remote server, and will need to be retrieved by an HTTP call.
|
65
|
-
|
66
|
-
```ruby
|
67
|
-
class Something
|
68
|
-
attr_reader :name
|
69
|
-
|
70
|
-
def initialize name
|
71
|
-
@name = name
|
72
|
-
end
|
73
|
-
|
74
|
-
def == other
|
75
|
-
other.is_a?(Something) && other.name == name
|
76
|
-
end
|
77
|
-
end
|
78
|
-
```
|
79
|
-
|
80
|
-
#### 2. Create a skeleton client class
|
81
|
-
|
82
|
-
Imagine a service provider client class that looks something like this.
|
83
|
-
|
84
|
-
```ruby
|
85
|
-
require 'httparty'
|
86
|
-
|
87
|
-
class MyServiceProviderClient
|
88
|
-
include HTTParty
|
89
|
-
base_uri 'http://my-service'
|
90
|
-
|
91
|
-
def get_something
|
92
|
-
# Yet to be implemented because we're doing Test First Development...
|
93
|
-
end
|
94
|
-
end
|
95
|
-
```
|
96
|
-
#### 3. Configure the mock server
|
97
|
-
|
98
|
-
The following code will create a mock service on localhost:1234 which will respond to your application's queries over HTTP as if it were the real "My Service Provider" app. It also creates a mock service provider object which you will use to set up your expectations. The method name to access the mock service provider will be what ever name you give as the service argument - in this case "my_service_provider"
|
99
|
-
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
# In /spec/service_providers/pact_helper.rb
|
103
|
-
|
104
|
-
require 'pact/consumer/rspec'
|
105
|
-
# or require 'pact/consumer/minitest' if you are using Minitest
|
106
|
-
|
107
|
-
Pact.service_consumer "My Service Consumer" do
|
108
|
-
has_pact_with "My Service Provider" do
|
109
|
-
mock_service :my_service_provider do
|
110
|
-
port 1234
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
```
|
115
|
-
|
116
|
-
#### 4. Write a failing spec for the client
|
117
|
-
|
118
|
-
```ruby
|
119
|
-
# In /spec/service_providers/my_service_provider_client_spec.rb
|
120
|
-
|
121
|
-
# When using RSpec, use the metadata `:pact => true` to include all the pact functionality in your spec.
|
122
|
-
# When using Minitest, include Pact::Consumer::Minitest in your spec.
|
123
|
-
|
124
|
-
describe MyServiceProviderClient, :pact => true do
|
125
|
-
|
126
|
-
before do
|
127
|
-
# Configure your client to point to the stub service on localhost using the port you have specified
|
128
|
-
MyServiceProviderClient.base_uri 'localhost:1234'
|
129
|
-
end
|
130
|
-
|
131
|
-
subject { MyServiceProviderClient.new }
|
132
|
-
|
133
|
-
describe "get_something" do
|
134
|
-
|
135
|
-
before do
|
136
|
-
my_service_provider.given("something exists").
|
137
|
-
upon_receiving("a request for something").with(method: :get, path: '/something', query: '').
|
138
|
-
will_respond_with(
|
139
|
-
status: 200,
|
140
|
-
headers: {'Content-Type' => 'application/json'},
|
141
|
-
body: {name: 'A small something'} )
|
142
|
-
end
|
143
|
-
|
144
|
-
it "returns a Something" do
|
145
|
-
expect(subject.get_something).to eq(Something.new('A small something'))
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
```
|
152
|
-
|
153
|
-
#### 5. Run the specs
|
154
|
-
|
155
|
-
Running the consumer spec will generate a pact file in the configured pact dir (spec/pacts by default).
|
156
|
-
Logs will be output to the configured log dir that can be useful when diagnosing problems.
|
157
|
-
|
158
|
-
Of course, the above specs will fail because the client method is not implemented, so next, implement your client methods.
|
159
|
-
|
160
|
-
#### 6. Implement the client methods
|
161
|
-
|
162
|
-
```ruby
|
163
|
-
class MyServiceProviderClient
|
164
|
-
include HTTParty
|
165
|
-
base_uri 'http://my-service'
|
166
|
-
|
167
|
-
def get_something
|
168
|
-
name = JSON.parse(self.class.get("/something").body)['name']
|
169
|
-
Something.new(name)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
```
|
173
|
-
|
174
|
-
#### 7. Run the specs again.
|
175
|
-
|
176
|
-
Green! You now have a pact file that can be used to verify your expectations of the provider project.
|
177
|
-
|
178
|
-
Now, rinse and repeat for other likely status codes that may be returned. For example, consider how you want your client to respond to a:
|
179
|
-
* 404 (return null, or raise an error?)
|
180
|
-
* 500 (specifying that the response body should contain an error message, and ensuring that your client logs that error message will make your life much easier when things go wrong)
|
181
|
-
* 401/403 if there is authorisation.
|
182
|
-
|
183
|
-
### Service Provider project
|
184
|
-
|
185
|
-
#### 1. Create the skeleton API classes
|
186
|
-
|
187
|
-
Create your API class using the framework of your choice (the Pact authors have a preference for [Webmachine][webmachine] and [Roar][roar]) - leave the methods unimplemented, we're doing Test First Develoment, remember?
|
188
|
-
|
189
|
-
#### 2. Tell your provider that it needs to honour the pact file you made earlier
|
190
|
-
|
191
|
-
Require "pact/tasks" in your Rakefile.
|
192
|
-
|
193
|
-
```ruby
|
194
|
-
# In Rakefile
|
195
|
-
require 'pact/tasks'
|
196
|
-
```
|
197
|
-
|
198
|
-
Create a `pact_helper.rb` in your service provider project. The recommended place is `spec/service_consumers/pact_helper.rb`.
|
199
|
-
|
200
|
-
See [Verifying Pacts](https://github.com/realestate-com-au/pact/wiki/Verifying-pacts) and the [Provider](documentation/configuration.md#provider) section of the Configuration documentation for more information.
|
201
|
-
|
202
|
-
```ruby
|
203
|
-
# In specs/service_consumers/pact_helper.rb
|
204
|
-
|
205
|
-
require 'pact/provider/rspec'
|
206
|
-
|
207
|
-
Pact.service_provider "My Service Provider" do
|
208
|
-
|
209
|
-
honours_pact_with 'My Service Consumer' do
|
210
|
-
|
211
|
-
# This example points to a local file, however, on a real project with a continuous
|
212
|
-
# integration box, you would use a [Pact Broker](https://github.com/bethesque/pact_broker) or publish your pacts as artifacts,
|
213
|
-
# and point the pact_uri to the pact published by the last successful build.
|
214
|
-
|
215
|
-
pact_uri '../path-to-your-consumer-project/specs/pacts/my_consumer-my_provider.json'
|
216
|
-
end
|
217
|
-
end
|
218
|
-
```
|
219
|
-
|
220
|
-
#### 3. Run your failing specs
|
221
|
-
|
222
|
-
$ rake pact:verify
|
223
|
-
|
224
|
-
Congratulations! You now have a failing spec to develop against.
|
225
|
-
|
226
|
-
At this stage, you'll want to be able to run your specs one at a time while you implement each feature. At the bottom of the failed pact:verify output you will see the commands to rerun each failed interaction individually. A command to run just one interaction will look like this:
|
227
|
-
|
228
|
-
$ rake pact:verify PACT_DESCRIPTION="a request for something" PACT_PROVIDER_STATE="something exists"
|
229
|
-
|
230
|
-
#### 4. Implement enough to make your first interaction spec pass
|
231
|
-
|
232
|
-
Rinse and repeat.
|
233
|
-
|
234
|
-
#### 5. Keep going til you're green
|
235
|
-
|
236
|
-
Yay! Your provider now honours the pact it has with your consumer. You can now have confidence that your consumer and provider will play nicely together.
|
237
|
-
|
238
|
-
### Using provider states
|
239
|
-
|
240
|
-
Each interaction in a pact is verified in isolation, with no context maintained from the previous interactions. So how do you test a request that requires data to already exist on the provider? Read about provider states [here](https://github.com/realestate-com-au/pact/wiki/Provider-states).
|
241
|
-
|
242
|
-
|
243
|
-
## Configuration
|
244
|
-
|
245
|
-
See the [Configuration](/documentation/configuration.md) section of the documentation for options relating to thing like logging, diff formatting, and documentation generation.
|
246
|
-
|
247
|
-
## Pact best practices
|
248
|
-
|
249
|
-
As in all things, there are good ways to implement Pacts, and there are not so good ways. Check out the [Best practices](https://github.com/realestate-com-au/pact/wiki/Best-practices) section of the documentation to make sure you're not Pacting it Wrong.
|
250
|
-
|
251
|
-
## Docs
|
252
|
-
|
253
|
-
* [Example](example)
|
254
|
-
* [Configuration](documentation/configuration.md)
|
255
|
-
* [Terminology](https://github.com/realestate-com-au/pact/wiki/Terminology)
|
256
|
-
* [Provider States](https://github.com/realestate-com-au/pact/wiki/Provider-states)
|
257
|
-
* [Verifying pacts](https://github.com/realestate-com-au/pact/wiki/Verifying-pacts)
|
258
|
-
* [Sharing pacts between consumer and provider](https://github.com/realestate-com-au/pact/wiki/Sharing-pacts-between-consumer-and-provider)
|
259
|
-
* [Regular expressions and type matching with Pact](https://github.com/realestate-com-au/pact/wiki/Regular-expressions-and-type-matching-with-Pact)
|
260
|
-
* [Frequently asked questions](https://github.com/realestate-com-au/pact/wiki/FAQ)
|
261
|
-
* [Rarely asked questions](https://github.com/realestate-com-au/pact/wiki/RAQ)
|
262
|
-
* [Best practices](https://github.com/realestate-com-au/pact/wiki/Best-practices)
|
263
|
-
* [Troubleshooting](https://github.com/realestate-com-au/pact/wiki/Troubleshooting)
|
264
|
-
* [Testing with pact diagram](https://github.com/realestate-com-au/pact/wiki/Testing with pact.png)
|
265
|
-
|
266
|
-
## Related libraries
|
267
|
-
|
268
|
-
[Pact Provider Proxy](https://github.com/bethesque/pact-provider-proxy) - Verify a pact against a running server, allowing you to use pacts with a provider of any language.
|
269
|
-
|
270
|
-
[Pact Broker](https://github.com/bethesque/pact_broker) - A pact repository. Provides endpoints to access published pacts, meaning you don't need to use messy CI URLs in your codebase. Enables cross testing of prod/head versions of your consumer and provider, allowing you to determine whether the head version of one is compatible with the production version of the other. Helps you to answer that ever so important question, "can I deploy without breaking all the things?"
|
271
|
-
|
272
|
-
[Pact Broker Client](https://github.com/bethesque/pact_broker-client) - Contains rake tasks for publishing pacts to the pact_broker.
|
273
|
-
|
274
|
-
[Pact JVM](https://github.com/DiUS/pact-jvm) - A Pact implementation for the JVM (Java and Scala). It generates pact files that are compatible with the Ruby implementation.
|
275
|
-
|
276
|
-
[Pact .NET](https://github.com/SEEK-Jobs/pact-net) - A Pact implementation for .NET.
|
277
|
-
|
278
|
-
[Shokkenki](https://github.com/brentsnook/shokkenki) - Another Consumer Driven Contract gem written by one of Pact's original authors, Brent Snook. Shokkenki allows matchers to be composed using jsonpath expressions and allows auto-generation of mock response values based on regular expressions.
|
279
|
-
|
280
|
-
## Links
|
281
|
-
|
282
|
-
[Simplifying microservices testing with pacts](http://dius.com.au/2014/05/19/simplifying-micro-service-testing-with-pacts/) - Ron Holshausen (one of the original pact authors)
|
283
|
-
|
284
|
-
[Pact specification](https://github.com/bethesque/pact-specification)
|
285
|
-
|
286
|
-
[Integrated tests are a scam](http://vimeo.com/80533536) - J.B. Rainsberger
|
287
|
-
|
288
|
-
[Consumer Driven Contracts](http://martinfowler.com/articles/consumerDrivenContracts.html) - Ian Robinson
|
289
|
-
|
290
|
-
[Integration Contract Tests](http://martinfowler.com/bliki/IntegrationContractTest.html) - Martin Fowler
|
291
|
-
|
292
|
-
## TODO
|
293
|
-
|
294
|
-
Short term:
|
295
|
-
- Support hash of query params
|
296
|
-
|
297
|
-
Long term:
|
298
|
-
- Provide more flexible matching (eg the keys should match, and the classes of the values should match, but the values of each key do not need to be equal). This is to make the pact verification less brittle.
|
299
|
-
- Add XML support
|
300
|
-
- Decouple Rspec from Pact and make rspec-pact gem for easy integration
|
301
|
-
|
302
|
-
## Contributing
|
303
|
-
|
304
|
-
1. Fork it
|
305
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
306
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
307
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
308
|
-
5. Create new Pull Request
|
309
|
-
|
310
|
-
If you would like to implement pact in another language, please check out the [Pact specification](https://github.com/bethesque/pact-specification) and have a chat to one of us on the [pact-dev Google group](https://groups.google.com/forum/#!forum/pact-dev). The vision is to have a compatible pact implementation in all the commonly used languages, your help would be greatly appreciated!
|
311
|
-
|
312
|
-
[webmachine]: https://github.com/seancribbs/webmachine-ruby
|
313
|
-
[roar]: https://github.com/apotonick/roar
|
314
|
-
|
data/Rakefile
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require 'rspec/core/rake_task'
|
3
|
-
|
4
|
-
Dir.glob('./lib/tasks/**/*.rake').each { |task| load task }
|
5
|
-
Dir.glob('./tasks/**/*.rake').each { |task| load task }
|
6
|
-
RSpec::Core::RakeTask.new(:spec)
|
7
|
-
|
8
|
-
task :default => [:spec, 'pact:tests:all', :spec_with_active_support, 'pact:tests:all:with_active_support']
|
9
|
-
|
data/config.ru
DELETED
data/documentation/README.md
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
### Pact Documentation
|
2
|
-
|
3
|
-
* Step by step instructions for getting started with pacts can be found in the project [README.md](/README.md#usage)
|
4
|
-
* [Terminology](https://github.com/realestate-com-au/pact/wiki/Terminology)
|
5
|
-
* [Configuration](configuration.md)
|
6
|
-
* [Provider States](https://github.com/realestate-com-au/pact/wiki/Provider-states)
|
7
|
-
* [Verifying pacts](https://github.com/realestate-com-au/pact/wiki/Verifying-pacts)
|
8
|
-
* [Frequently asked questions](https://github.com/realestate-com-au/pact/wiki/FAQ)
|
9
|
-
* [Rarely asked questions](https://github.com/realestate-com-au/pact/wiki/RAQ)
|
10
|
-
* [Best practices](https://github.com/realestate-com-au/pact/wiki/Best-practices)
|
11
|
-
* [Troubleshooting](https://github.com/realestate-com-au/pact/wiki/Troubleshooting)
|
12
|
-
* [Testing with pact diagram](https://github.com/realestate-com-au/pact/wiki/Testing with pact.png)
|
13
|
-
* [Development workflow](https://github.com/realestate-com-au/pact/wiki/Development-workflow)
|
@@ -1,166 +0,0 @@
|
|
1
|
-
# Configuration
|
2
|
-
|
3
|
-
## Menu
|
4
|
-
|
5
|
-
#### Consumer and Provider configuration options
|
6
|
-
* [diff_formatter](#diff_formatter)
|
7
|
-
* [log_dir](#log_dir)
|
8
|
-
* [logger](#logger)
|
9
|
-
* [logger.level](#loggerlevel)
|
10
|
-
|
11
|
-
#### Consumer only configuration options
|
12
|
-
* [pact_dir](#pact_dir)
|
13
|
-
* [doc_dir](#doc_dir)
|
14
|
-
* [doc_generator](#doc_generator)
|
15
|
-
* [pactfile_write_mode](#pactfile_write_mode)
|
16
|
-
|
17
|
-
#### Provider only configuration options
|
18
|
-
* [include](#include)
|
19
|
-
|
20
|
-
## Consumer and Provider
|
21
|
-
|
22
|
-
### log_dir
|
23
|
-
|
24
|
-
```ruby
|
25
|
-
Pact.configure do | config |
|
26
|
-
config.log_dir = './log'
|
27
|
-
end
|
28
|
-
```
|
29
|
-
|
30
|
-
Default value: `./log`
|
31
|
-
|
32
|
-
### logger
|
33
|
-
|
34
|
-
```ruby
|
35
|
-
Pact.configure do | config |
|
36
|
-
config.logger = Logger.new
|
37
|
-
end
|
38
|
-
```
|
39
|
-
|
40
|
-
Default value: file logger to the configured log_dir.
|
41
|
-
|
42
|
-
### logger.level
|
43
|
-
|
44
|
-
```ruby
|
45
|
-
Pact.configure do | config |
|
46
|
-
config.logger.level = Logger::INFO
|
47
|
-
end
|
48
|
-
```
|
49
|
-
|
50
|
-
Default value: `Logger::DEBUG`
|
51
|
-
|
52
|
-
### diff_formatter
|
53
|
-
|
54
|
-
```ruby
|
55
|
-
Pact.configure do | config |
|
56
|
-
config.diff_formatter = :list
|
57
|
-
end
|
58
|
-
```
|
59
|
-
|
60
|
-
Default value: [:list](#list)
|
61
|
-
|
62
|
-
Options: [:unix](#unix), [:list](#list), [:embedded](#embedded), [Custom Diff Formatter](#custom-diff-formatter)
|
63
|
-
|
64
|
-
|
65
|
-
#### :unix
|
66
|
-
<img src="diff_formatter_unix.png" width="700">
|
67
|
-
|
68
|
-
#### :list
|
69
|
-
|
70
|
-
<img src="diff_formatter_list.png" width="700">
|
71
|
-
|
72
|
-
#### :embedded
|
73
|
-
|
74
|
-
<img src="diff_formatter_embedded.png" width="700">
|
75
|
-
|
76
|
-
|
77
|
-
#### Custom Diff Formatter
|
78
|
-
|
79
|
-
Any object can be used that responds to `call`, accepting the argument `diff`.
|
80
|
-
|
81
|
-
```ruby
|
82
|
-
class MyCustomDiffFormatter
|
83
|
-
|
84
|
-
def self.call diff
|
85
|
-
### Do stuff here
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
Pact.configure do | config |
|
91
|
-
config.diff_formatter = MyCustomDiffFormatter
|
92
|
-
end
|
93
|
-
```
|
94
|
-
|
95
|
-
|
96
|
-
## Consumer
|
97
|
-
|
98
|
-
### pact_dir
|
99
|
-
|
100
|
-
```ruby
|
101
|
-
Pact.configure do | config |
|
102
|
-
config.pact_dir = `./spec/pacts`
|
103
|
-
end
|
104
|
-
```
|
105
|
-
|
106
|
-
Default value: `./spec/pacts`
|
107
|
-
|
108
|
-
### doc_generator
|
109
|
-
|
110
|
-
```ruby
|
111
|
-
Pact.configure do | config |
|
112
|
-
config.doc_generator = :markdown
|
113
|
-
end
|
114
|
-
```
|
115
|
-
|
116
|
-
Default value: none
|
117
|
-
|
118
|
-
Options: [:markdown](#markdown), [Custom Doc Generator](#custom-doc-generator)
|
119
|
-
|
120
|
-
#### :markdown
|
121
|
-
|
122
|
-
Generates Markdown documentation based on the contents of the pact files created in this consumer. Files are created in `${Pact.configuration.doc_dir}/markdown`.
|
123
|
-
|
124
|
-
#### Custom Doc Generator
|
125
|
-
|
126
|
-
Any object can be used that responds to `call`, accepting the arguments `pact_dir` and `doc_dir`.
|
127
|
-
|
128
|
-
```ruby
|
129
|
-
Pact.configure do | config |
|
130
|
-
config.doc_generator = lambda{ | pact_dir, doc_dir | generate_some_docs(pact_dir, doc_dir) }
|
131
|
-
end
|
132
|
-
|
133
|
-
```
|
134
|
-
|
135
|
-
#### doc_dir
|
136
|
-
|
137
|
-
```ruby
|
138
|
-
Pact.configure do | config |
|
139
|
-
config.doc_dir = './doc'
|
140
|
-
end
|
141
|
-
```
|
142
|
-
|
143
|
-
Default value: `./doc`
|
144
|
-
|
145
|
-
|
146
|
-
### pactfile_write_mode
|
147
|
-
|
148
|
-
Default value: `:overwrite`
|
149
|
-
Options: `:overwrite`, `:update`, `:smart`
|
150
|
-
|
151
|
-
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.
|
152
|
-
|
153
|
-
## Provider
|
154
|
-
|
155
|
-
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.
|
156
|
-
|
157
|
-
### include
|
158
|
-
|
159
|
-
```ruby
|
160
|
-
Pact.configure do | config |
|
161
|
-
config.include MyTestHelperMethods
|
162
|
-
end
|
163
|
-
```
|
164
|
-
|
165
|
-
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.
|
166
|
-
|