pact 1.0.9 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +20 -0
- data/Gemfile.lock +3 -3
- data/example/animal-service/Gemfile +14 -0
- data/example/animal-service/Gemfile.lock +67 -0
- data/example/animal-service/Rakefile +3 -0
- data/example/animal-service/spec/service_consumers/pact_helper.rb +24 -0
- data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +9 -0
- data/example/zoo-app/Gemfile.lock +2 -15
- data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +21 -6
- data/example/zoo-app/spec/service_providers/animal_service_spec.rb +1 -1
- data/lib/pact/consumer.rb +10 -11
- data/lib/pact/consumer/app_manager.rb +1 -0
- data/lib/pact/consumer/configuration.rb +179 -0
- data/lib/pact/consumer/interaction_builder.rb +1 -2
- data/lib/pact/consumer/mock_service.rb +1 -370
- data/lib/pact/consumer/mock_service/app.rb +70 -0
- data/lib/pact/consumer/mock_service/interaction_delete.rb +28 -0
- data/lib/pact/consumer/mock_service/interaction_list.rb +57 -0
- data/lib/pact/consumer/mock_service/interaction_post.rb +25 -0
- data/lib/pact/consumer/mock_service/interaction_replay.rb +126 -0
- data/lib/pact/consumer/mock_service/missing_interactions_get.rb +26 -0
- data/lib/pact/consumer/mock_service/rack_request_helper.rb +51 -0
- data/lib/pact/consumer/mock_service/startup_poll.rb +22 -0
- data/lib/pact/consumer/mock_service/verification_get.rb +35 -0
- data/lib/pact/consumer/mock_service_client.rb +3 -1
- data/lib/pact/consumer/mock_service_interaction_expectation.rb +33 -0
- data/lib/pact/consumer/request.rb +27 -0
- data/lib/pact/consumer/rspec.rb +1 -4
- data/lib/pact/consumer_contract/consumer_contract.rb +11 -8
- data/lib/pact/consumer_contract/interaction.rb +9 -22
- data/lib/pact/consumer_contract/request.rb +68 -0
- data/lib/pact/consumer_contract/service_consumer.rb +6 -2
- data/lib/pact/consumer_contract/service_provider.rb +6 -2
- data/lib/pact/matchers/index_not_found.rb +20 -0
- data/lib/pact/matchers/matchers.rb +14 -28
- data/lib/pact/matchers/unexpected_index.rb +17 -0
- data/lib/pact/matchers/unexpected_key.rb +17 -0
- data/lib/pact/provider.rb +1 -1
- data/lib/pact/provider/configuration.rb +129 -0
- data/lib/pact/provider/request.rb +59 -0
- data/lib/pact/provider/rspec.rb +4 -5
- data/lib/pact/provider/test_methods.rb +14 -52
- data/lib/pact/shared/dsl.rb +20 -0
- data/lib/pact/shared/key_not_found.rb +24 -0
- data/lib/pact/shared/null_expectation.rb +31 -0
- data/lib/pact/shared/request.rb +68 -0
- data/lib/pact/something_like.rb +7 -1
- data/lib/pact/symbolize_keys.rb +12 -0
- data/lib/pact/tasks.rb +1 -1
- data/lib/pact/tasks/task_helper.rb +23 -0
- data/lib/pact/{verification_task.rb → tasks/verification_task.rb} +4 -4
- data/lib/pact/version.rb +1 -1
- data/lib/tasks/pact.rake +5 -4
- data/pact.gemspec +1 -1
- data/spec/features/consumption_spec.rb +1 -73
- data/spec/features/production_spec.rb +3 -0
- data/spec/integration/consumer_spec.rb +170 -0
- data/spec/integration/pact/consumer_configuration_spec.rb +1 -1
- data/spec/lib/pact/consumer/{dsl_spec.rb → configuration_spec.rb} +10 -9
- data/spec/lib/pact/consumer/consumer_contract_builder_spec.rb +2 -2
- data/spec/lib/pact/consumer/interaction_builder_spec.rb +1 -1
- data/spec/lib/pact/consumer/mock_service/interaction_list_spec.rb +66 -0
- data/spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb +82 -0
- data/spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb +54 -0
- data/spec/lib/pact/consumer/request_spec.rb +24 -0
- data/spec/lib/pact/consumer_contract/consumer_contract_spec.rb +1 -1
- data/spec/lib/pact/consumer_contract/interaction_spec.rb +0 -34
- data/spec/lib/pact/{request_spec.rb → consumer_contract/request_spec.rb} +45 -121
- data/spec/lib/pact/matchers/matchers_spec.rb +29 -13
- data/spec/lib/pact/provider/configuration_spec.rb +163 -0
- data/spec/lib/pact/provider/request_spec.rb +78 -0
- data/spec/lib/pact/provider/test_methods_spec.rb +0 -30
- data/spec/lib/pact/verification_task_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- data/spec/support/factories.rb +5 -1
- data/spec/support/pact_helper.rb +6 -0
- data/spec/support/shared_examples_for_request.rb +83 -0
- data/spec/support/test_app_fail.json +3 -0
- data/spec/support/test_app_pass.json +18 -1
- metadata +68 -31
- data/lib/pact/consumer/dsl.rb +0 -157
- data/lib/pact/pact_task_helper.rb +0 -21
- data/lib/pact/provider/dsl.rb +0 -115
- data/lib/pact/request.rb +0 -167
- data/spec/lib/pact/consumer/mock_service_spec.rb +0 -143
- data/spec/lib/pact/provider/dsl_spec.rb +0 -179
@@ -0,0 +1,83 @@
|
|
1
|
+
shared_examples "a request" do
|
2
|
+
|
3
|
+
describe 'matching' do
|
4
|
+
let(:expected) do
|
5
|
+
Pact::Request::Expected.from_hash(
|
6
|
+
{'method' => 'get', 'path' => 'path', 'query' => /b/}
|
7
|
+
)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:actual) do
|
11
|
+
Pact::Consumer::Request::Actual.from_hash({'method' => 'get', 'path' => 'path', 'query' => 'blah', 'headers' => {}, 'body' => ''})
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should match" do
|
15
|
+
expect(expected.difference(actual)).to eq({})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'full_path' do
|
20
|
+
context "with empty path" do
|
21
|
+
subject { described_class.from_hash({:path => '', :method => 'get', :query => '', :headers => {}}) }
|
22
|
+
it "returns the full path"do
|
23
|
+
expect(subject.full_path).to eq "/"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context "with a path" do
|
27
|
+
subject { described_class.from_hash({:path => '/path', :method => 'get', :query => '', :headers => {}}) }
|
28
|
+
it "returns the full path"do
|
29
|
+
expect(subject.full_path).to eq "/path"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
context "with a path and query" do
|
33
|
+
subject { described_class.from_hash({:path => '/path', :method => 'get', :query => "something", :headers => {}}) }
|
34
|
+
it "returns the full path"do
|
35
|
+
expect(subject.full_path).to eq "/path?something"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
context "with a path and a query that is a Term" do
|
39
|
+
subject { described_class.from_hash({:path => '/path', :method => 'get', :headers => {}, :query => Pact::Term.new(generate: 'a', matcher: /a/)}) }
|
40
|
+
it "returns the full path with reified path" do
|
41
|
+
expect(subject.full_path).to eq "/path?a"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "building from a hash" do
|
47
|
+
|
48
|
+
let(:raw_request) do
|
49
|
+
{
|
50
|
+
'method' => 'get',
|
51
|
+
'path' => '/mallory',
|
52
|
+
'query' => 'query',
|
53
|
+
'headers' => {
|
54
|
+
'Content-Type' => 'application/json'
|
55
|
+
},
|
56
|
+
'body' => 'hello mallory'
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
subject { described_class.from_hash(raw_request) }
|
61
|
+
|
62
|
+
its(:method) { should == 'get' }
|
63
|
+
its(:path) { should == '/mallory' }
|
64
|
+
its(:body) { should == 'hello mallory' }
|
65
|
+
its(:query) { should eq 'query'}
|
66
|
+
|
67
|
+
it "blows up if method is absent" do
|
68
|
+
raw_request.delete 'method'
|
69
|
+
expect { described_class.from_hash(raw_request) }.to raise_error
|
70
|
+
end
|
71
|
+
|
72
|
+
it "blows up if path is absent" do
|
73
|
+
raw_request.delete 'path'
|
74
|
+
expect { described_class.from_hash(raw_request) }.to raise_error
|
75
|
+
end
|
76
|
+
|
77
|
+
it "does not blow up if body is missing" do
|
78
|
+
raw_request.delete 'body'
|
79
|
+
expect { described_class.from_hash(raw_request) }.to_not raise_error
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -2,6 +2,9 @@
|
|
2
2
|
"consumer": {
|
3
3
|
"name": "some-test-consumer"
|
4
4
|
},
|
5
|
+
"provider": {
|
6
|
+
"name": "an unknown provider"
|
7
|
+
},
|
5
8
|
"interactions": [
|
6
9
|
{
|
7
10
|
"description": "A test request",
|
@@ -16,6 +19,20 @@
|
|
16
19
|
"body": {"message" : "sunny"}
|
17
20
|
},
|
18
21
|
"provider_state": "the weather is sunny"
|
19
|
-
}
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"description": "A test request for text",
|
25
|
+
"request": {
|
26
|
+
"method": "get",
|
27
|
+
"path": "/sometext",
|
28
|
+
"query": "",
|
29
|
+
"body" : "some request text"
|
30
|
+
},
|
31
|
+
"response": {
|
32
|
+
"status": 200,
|
33
|
+
"headers" : {"Content-type": "text/plain"},
|
34
|
+
"body": "some text"
|
35
|
+
}
|
36
|
+
}
|
20
37
|
]
|
21
38
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-
|
16
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: randexp
|
@@ -31,22 +31,6 @@ dependencies:
|
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.1.7
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: hashie
|
36
|
-
requirement: !ruby/object:Gem::Requirement
|
37
|
-
none: false
|
38
|
-
requirements:
|
39
|
-
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '2.0'
|
42
|
-
type: :runtime
|
43
|
-
prerelease: false
|
44
|
-
version_requirements: !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
|
-
requirements:
|
47
|
-
- - ~>
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '2.0'
|
50
34
|
- !ruby/object:Gem::Dependency
|
51
35
|
name: rspec
|
52
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -239,6 +223,22 @@ dependencies:
|
|
239
223
|
- - ~>
|
240
224
|
- !ruby/object:Gem::Version
|
241
225
|
version: '0.4'
|
226
|
+
- !ruby/object:Gem::Dependency
|
227
|
+
name: hashie
|
228
|
+
requirement: !ruby/object:Gem::Requirement
|
229
|
+
none: false
|
230
|
+
requirements:
|
231
|
+
- - ~>
|
232
|
+
- !ruby/object:Gem::Version
|
233
|
+
version: '2.0'
|
234
|
+
type: :development
|
235
|
+
prerelease: false
|
236
|
+
version_requirements: !ruby/object:Gem::Requirement
|
237
|
+
none: false
|
238
|
+
requirements:
|
239
|
+
- - ~>
|
240
|
+
- !ruby/object:Gem::Version
|
241
|
+
version: '2.0'
|
242
242
|
description: Define a pact between service consumers and providers
|
243
243
|
email:
|
244
244
|
- james.fraser@alumni.swinburne.edu
|
@@ -260,6 +260,11 @@ files:
|
|
260
260
|
- README.md
|
261
261
|
- Rakefile
|
262
262
|
- bin/pact
|
263
|
+
- example/animal-service/Gemfile
|
264
|
+
- example/animal-service/Gemfile.lock
|
265
|
+
- example/animal-service/Rakefile
|
266
|
+
- example/animal-service/spec/service_consumers/pact_helper.rb
|
267
|
+
- example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb
|
263
268
|
- example/zoo-app/Gemfile
|
264
269
|
- example/zoo-app/Gemfile.lock
|
265
270
|
- example/zoo-app/lib/zoo_app/animal_service_client.rb
|
@@ -273,42 +278,62 @@ files:
|
|
273
278
|
- lib/pact/configuration.rb
|
274
279
|
- lib/pact/consumer.rb
|
275
280
|
- lib/pact/consumer/app_manager.rb
|
281
|
+
- lib/pact/consumer/configuration.rb
|
276
282
|
- lib/pact/consumer/consumer_contract_builder.rb
|
277
283
|
- lib/pact/consumer/consumer_contract_builders.rb
|
278
|
-
- lib/pact/consumer/dsl.rb
|
279
284
|
- lib/pact/consumer/interaction_builder.rb
|
280
285
|
- lib/pact/consumer/interactions_filter.rb
|
281
286
|
- lib/pact/consumer/mock_service.rb
|
287
|
+
- lib/pact/consumer/mock_service/app.rb
|
288
|
+
- lib/pact/consumer/mock_service/interaction_delete.rb
|
289
|
+
- lib/pact/consumer/mock_service/interaction_list.rb
|
290
|
+
- lib/pact/consumer/mock_service/interaction_post.rb
|
291
|
+
- lib/pact/consumer/mock_service/interaction_replay.rb
|
292
|
+
- lib/pact/consumer/mock_service/missing_interactions_get.rb
|
293
|
+
- lib/pact/consumer/mock_service/rack_request_helper.rb
|
294
|
+
- lib/pact/consumer/mock_service/startup_poll.rb
|
295
|
+
- lib/pact/consumer/mock_service/verification_get.rb
|
282
296
|
- lib/pact/consumer/mock_service_client.rb
|
297
|
+
- lib/pact/consumer/mock_service_interaction_expectation.rb
|
298
|
+
- lib/pact/consumer/request.rb
|
283
299
|
- lib/pact/consumer/rspec.rb
|
284
300
|
- lib/pact/consumer/server.rb
|
285
301
|
- lib/pact/consumer_contract.rb
|
286
302
|
- lib/pact/consumer_contract/consumer_contract.rb
|
287
303
|
- lib/pact/consumer_contract/interaction.rb
|
304
|
+
- lib/pact/consumer_contract/request.rb
|
288
305
|
- lib/pact/consumer_contract/service_consumer.rb
|
289
306
|
- lib/pact/consumer_contract/service_provider.rb
|
290
307
|
- lib/pact/json_warning.rb
|
291
308
|
- lib/pact/logging.rb
|
292
309
|
- lib/pact/matchers.rb
|
310
|
+
- lib/pact/matchers/index_not_found.rb
|
293
311
|
- lib/pact/matchers/matchers.rb
|
294
|
-
- lib/pact/
|
312
|
+
- lib/pact/matchers/unexpected_index.rb
|
313
|
+
- lib/pact/matchers/unexpected_key.rb
|
295
314
|
- lib/pact/provider.rb
|
296
315
|
- lib/pact/provider/client_project_pact_helper.rb
|
297
|
-
- lib/pact/provider/
|
316
|
+
- lib/pact/provider/configuration.rb
|
298
317
|
- lib/pact/provider/matchers.rb
|
299
318
|
- lib/pact/provider/pact_helper_locator.rb
|
300
319
|
- lib/pact/provider/pact_spec_runner.rb
|
301
320
|
- lib/pact/provider/pact_verification.rb
|
302
321
|
- lib/pact/provider/provider_state.rb
|
322
|
+
- lib/pact/provider/request.rb
|
303
323
|
- lib/pact/provider/rspec.rb
|
304
324
|
- lib/pact/provider/test_methods.rb
|
305
325
|
- lib/pact/provider/verification_report.rb
|
306
326
|
- lib/pact/reification.rb
|
307
|
-
- lib/pact/
|
327
|
+
- lib/pact/shared/dsl.rb
|
328
|
+
- lib/pact/shared/key_not_found.rb
|
329
|
+
- lib/pact/shared/null_expectation.rb
|
330
|
+
- lib/pact/shared/request.rb
|
308
331
|
- lib/pact/something_like.rb
|
332
|
+
- lib/pact/symbolize_keys.rb
|
309
333
|
- lib/pact/tasks.rb
|
334
|
+
- lib/pact/tasks/task_helper.rb
|
335
|
+
- lib/pact/tasks/verification_task.rb
|
310
336
|
- lib/pact/term.rb
|
311
|
-
- lib/pact/verification_task.rb
|
312
337
|
- lib/pact/version.rb
|
313
338
|
- lib/tasks/pact.rake
|
314
339
|
- pact.gemspec
|
@@ -316,27 +341,32 @@ files:
|
|
316
341
|
- spec/features/consumption_spec.rb
|
317
342
|
- spec/features/production_spec.rb
|
318
343
|
- spec/features/provider_states/zebras.rb
|
344
|
+
- spec/integration/consumer_spec.rb
|
319
345
|
- spec/integration/pact/consumer_configuration_spec.rb
|
320
346
|
- spec/integration/pact/provider_configuration_spec.rb
|
321
347
|
- spec/lib/pact/configuration_spec.rb
|
322
348
|
- spec/lib/pact/consumer/app_manager_spec.rb
|
349
|
+
- spec/lib/pact/consumer/configuration_spec.rb
|
323
350
|
- spec/lib/pact/consumer/consumer_contract_builder_spec.rb
|
324
|
-
- spec/lib/pact/consumer/dsl_spec.rb
|
325
351
|
- spec/lib/pact/consumer/interaction_builder_spec.rb
|
326
352
|
- spec/lib/pact/consumer/interactions_spec.rb
|
327
|
-
- spec/lib/pact/consumer/
|
353
|
+
- spec/lib/pact/consumer/mock_service/interaction_list_spec.rb
|
354
|
+
- spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb
|
355
|
+
- spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
|
356
|
+
- spec/lib/pact/consumer/request_spec.rb
|
328
357
|
- spec/lib/pact/consumer/service_consumer_spec.rb
|
329
358
|
- spec/lib/pact/consumer_contract/consumer_contract_spec.rb
|
330
359
|
- spec/lib/pact/consumer_contract/interaction_spec.rb
|
360
|
+
- spec/lib/pact/consumer_contract/request_spec.rb
|
331
361
|
- spec/lib/pact/matchers/matchers_spec.rb
|
332
|
-
- spec/lib/pact/provider/
|
362
|
+
- spec/lib/pact/provider/configuration_spec.rb
|
333
363
|
- spec/lib/pact/provider/pact_helper_locator_spec.rb
|
334
364
|
- spec/lib/pact/provider/pact_spec_runner_spec.rb
|
335
365
|
- spec/lib/pact/provider/provider_state_spec.rb
|
366
|
+
- spec/lib/pact/provider/request_spec.rb
|
336
367
|
- spec/lib/pact/provider/rspec_spec.rb
|
337
368
|
- spec/lib/pact/provider/test_methods_spec.rb
|
338
369
|
- spec/lib/pact/reification_spec.rb
|
339
|
-
- spec/lib/pact/request_spec.rb
|
340
370
|
- spec/lib/pact/term_spec.rb
|
341
371
|
- spec/lib/pact/verification_task_spec.rb
|
342
372
|
- spec/spec_helper.rb
|
@@ -345,6 +375,7 @@ files:
|
|
345
375
|
- spec/support/consumer_contract_template.json
|
346
376
|
- spec/support/factories.rb
|
347
377
|
- spec/support/pact_helper.rb
|
378
|
+
- spec/support/shared_examples_for_request.rb
|
348
379
|
- spec/support/test_app_fail.json
|
349
380
|
- spec/support/test_app_pass.json
|
350
381
|
- tasks/pact-test.rake
|
@@ -377,27 +408,32 @@ test_files:
|
|
377
408
|
- spec/features/consumption_spec.rb
|
378
409
|
- spec/features/production_spec.rb
|
379
410
|
- spec/features/provider_states/zebras.rb
|
411
|
+
- spec/integration/consumer_spec.rb
|
380
412
|
- spec/integration/pact/consumer_configuration_spec.rb
|
381
413
|
- spec/integration/pact/provider_configuration_spec.rb
|
382
414
|
- spec/lib/pact/configuration_spec.rb
|
383
415
|
- spec/lib/pact/consumer/app_manager_spec.rb
|
416
|
+
- spec/lib/pact/consumer/configuration_spec.rb
|
384
417
|
- spec/lib/pact/consumer/consumer_contract_builder_spec.rb
|
385
|
-
- spec/lib/pact/consumer/dsl_spec.rb
|
386
418
|
- spec/lib/pact/consumer/interaction_builder_spec.rb
|
387
419
|
- spec/lib/pact/consumer/interactions_spec.rb
|
388
|
-
- spec/lib/pact/consumer/
|
420
|
+
- spec/lib/pact/consumer/mock_service/interaction_list_spec.rb
|
421
|
+
- spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb
|
422
|
+
- spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
|
423
|
+
- spec/lib/pact/consumer/request_spec.rb
|
389
424
|
- spec/lib/pact/consumer/service_consumer_spec.rb
|
390
425
|
- spec/lib/pact/consumer_contract/consumer_contract_spec.rb
|
391
426
|
- spec/lib/pact/consumer_contract/interaction_spec.rb
|
427
|
+
- spec/lib/pact/consumer_contract/request_spec.rb
|
392
428
|
- spec/lib/pact/matchers/matchers_spec.rb
|
393
|
-
- spec/lib/pact/provider/
|
429
|
+
- spec/lib/pact/provider/configuration_spec.rb
|
394
430
|
- spec/lib/pact/provider/pact_helper_locator_spec.rb
|
395
431
|
- spec/lib/pact/provider/pact_spec_runner_spec.rb
|
396
432
|
- spec/lib/pact/provider/provider_state_spec.rb
|
433
|
+
- spec/lib/pact/provider/request_spec.rb
|
397
434
|
- spec/lib/pact/provider/rspec_spec.rb
|
398
435
|
- spec/lib/pact/provider/test_methods_spec.rb
|
399
436
|
- spec/lib/pact/reification_spec.rb
|
400
|
-
- spec/lib/pact/request_spec.rb
|
401
437
|
- spec/lib/pact/term_spec.rb
|
402
438
|
- spec/lib/pact/verification_task_spec.rb
|
403
439
|
- spec/spec_helper.rb
|
@@ -406,5 +442,6 @@ test_files:
|
|
406
442
|
- spec/support/consumer_contract_template.json
|
407
443
|
- spec/support/factories.rb
|
408
444
|
- spec/support/pact_helper.rb
|
445
|
+
- spec/support/shared_examples_for_request.rb
|
409
446
|
- spec/support/test_app_fail.json
|
410
447
|
- spec/support/test_app_pass.json
|
data/lib/pact/consumer/dsl.rb
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
require_relative 'consumer_contract_builders'
|
2
|
-
|
3
|
-
module Pact::Consumer
|
4
|
-
module DSL
|
5
|
-
|
6
|
-
module Configuration
|
7
|
-
def add_provider_verification &block
|
8
|
-
provider_verifications << block
|
9
|
-
end
|
10
|
-
def provider_verifications
|
11
|
-
@provider_verifications ||= []
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def service_consumer name, &block
|
16
|
-
ServiceConsumerDSL.new(name, &block).create_service_consumer
|
17
|
-
end
|
18
|
-
|
19
|
-
class ServiceConsumerDSL
|
20
|
-
|
21
|
-
def initialize name, &block
|
22
|
-
@name = name
|
23
|
-
consumer = Pact::ServiceConsumer.new name: @name
|
24
|
-
@app = nil
|
25
|
-
@port = nil
|
26
|
-
instance_eval(&block)
|
27
|
-
end
|
28
|
-
|
29
|
-
def validate
|
30
|
-
raise "Please provide a consumer name" unless (@name && !@name.empty?)
|
31
|
-
raise "Please provide a port for the consumer app" if @app && !@port
|
32
|
-
end
|
33
|
-
|
34
|
-
def app app
|
35
|
-
@app = app
|
36
|
-
end
|
37
|
-
|
38
|
-
def port port
|
39
|
-
@port = port
|
40
|
-
end
|
41
|
-
|
42
|
-
def has_pact_with service_provider_name, &block
|
43
|
-
Provider.new(service_provider_name, @name, &block).create_consumer_contract_builder
|
44
|
-
end
|
45
|
-
|
46
|
-
def create_service_consumer
|
47
|
-
validate
|
48
|
-
register_consumer_app if @app
|
49
|
-
end
|
50
|
-
|
51
|
-
def register_consumer_app
|
52
|
-
Pact::Consumer::AppManager.instance.register @app, @port
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
#OLD ####
|
60
|
-
def with_provider name, &block
|
61
|
-
Provider.new(name, &block).create_consumer_contract_builder
|
62
|
-
end
|
63
|
-
|
64
|
-
alias_method :with_service_provider, :with_provider
|
65
|
-
|
66
|
-
class Provider
|
67
|
-
def initialize name, consumer_name = Pact.configuration.consumer.name, &block
|
68
|
-
@name = name
|
69
|
-
@service = nil
|
70
|
-
@consumer_name = consumer_name
|
71
|
-
instance_eval(&block)
|
72
|
-
end
|
73
|
-
|
74
|
-
def service name, &block
|
75
|
-
@service = Service.new(name, &block)
|
76
|
-
end
|
77
|
-
|
78
|
-
alias_method :mock_service, :service
|
79
|
-
|
80
|
-
def create_consumer_contract_builder
|
81
|
-
validate
|
82
|
-
consumer_contract_builder_from_attributes
|
83
|
-
end
|
84
|
-
|
85
|
-
def validate
|
86
|
-
raise "Please configure a service for #{@name}" unless @service
|
87
|
-
end
|
88
|
-
|
89
|
-
def consumer_contract_builder_from_attributes
|
90
|
-
consumer_contract_builder_fields = {
|
91
|
-
:consumer_name => @consumer_name,
|
92
|
-
:provider_name => @name,
|
93
|
-
:pactfile_write_mode => Pact.configuration.pactfile_write_mode
|
94
|
-
}
|
95
|
-
@service.configure_consumer_contract_builder consumer_contract_builder_fields
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
class Service
|
100
|
-
def initialize name, &block
|
101
|
-
@name = name
|
102
|
-
@port = nil
|
103
|
-
@standalone = false
|
104
|
-
@verify = true
|
105
|
-
instance_eval(&block)
|
106
|
-
end
|
107
|
-
|
108
|
-
def port port
|
109
|
-
@port = port
|
110
|
-
end
|
111
|
-
|
112
|
-
def standalone standalone
|
113
|
-
@standalone = standalone
|
114
|
-
end
|
115
|
-
|
116
|
-
def verify verify
|
117
|
-
@verify = verify
|
118
|
-
end
|
119
|
-
|
120
|
-
def configure_consumer_contract_builder consumer_contract_builder_fields
|
121
|
-
validate
|
122
|
-
unless @standalone
|
123
|
-
AppManager.instance.register_mock_service_for consumer_contract_builder_fields[:provider_name], "http://localhost:#{@port}"
|
124
|
-
end
|
125
|
-
consumer_contract_builder = Pact::Consumer::ConsumerContractBuilder.new consumer_contract_builder_fields.merge({port: @port})
|
126
|
-
create_mock_services_module_method consumer_contract_builder
|
127
|
-
setup_verification(consumer_contract_builder) if @verify
|
128
|
-
consumer_contract_builder
|
129
|
-
end
|
130
|
-
|
131
|
-
|
132
|
-
def setup_verification consumer_contract_builder
|
133
|
-
Pact.configuration.add_provider_verification do | example_description |
|
134
|
-
consumer_contract_builder.verify example_description
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
private
|
139
|
-
|
140
|
-
# This makes the consumer_contract_builder available via a module method with the given identifier
|
141
|
-
# as the method name.
|
142
|
-
# I feel this should be defined somewhere else, but I'm not sure where
|
143
|
-
def create_mock_services_module_method consumer_contract_builder
|
144
|
-
Pact::Consumer::ConsumerContractBuilders.send(:define_method, @name.to_sym) do
|
145
|
-
consumer_contract_builder
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def validate
|
150
|
-
raise "Please provide a port for service #{@name}" unless @port
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
Pact.send(:extend, Pact::Consumer::DSL)
|
157
|
-
Pact::Configuration.send(:include, Pact::Consumer::DSL::Configuration)
|