pact 1.4.0.rc3 → 1.4.0.rc4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +7 -6
- data/lib/pact/consumer/interaction_builder.rb +1 -1
- data/lib/pact/provider/configuration/configuration_extension.rb +0 -9
- data/lib/pact/version.rb +1 -1
- data/pact.gemspec +2 -2
- data/spec/integration/consumer_with_form_hash_spec.rb +62 -0
- data/spec/integration/consumer_with_form_spec.rb +50 -0
- data/spec/integration/consumer_with_params_hash_spec.rb +19 -8
- data/spec/lib/pact/provider/configuration/configuration_extension_spec.rb +1 -14
- metadata +11 -13
- data/spec/lib/pact/consumer/mock_service_client_spec.rb +0 -88
- data/spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb +0 -54
- data/spec/lib/pact/consumer_contract/consumer_contract_writer_spec.rb +0 -111
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@ Do this to generate your change history
|
|
|
2
2
|
|
|
3
3
|
git log --pretty=format:' * %h - %s (%an, %ad)'
|
|
4
4
|
|
|
5
|
+
### 1.4.0.rc4 (22 October 2014)
|
|
6
|
+
|
|
7
|
+
* e56775a - Upgraded pact support gems to allow form bodies to be specified as Hashes with Pact::Terms (bethesque, Wed Oct 22 15:31:30 2014 +1100)
|
|
8
|
+
|
|
5
9
|
### 1.4.0.rc3 (17 October 2014)
|
|
6
10
|
|
|
7
11
|
* 602906f - Upped pact-support version to allow queries specified as hashes. (bethesque, Fri Oct 17 14:30:39 2014 +1100)
|
data/Gemfile.lock
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
pact (1.4.0.
|
|
4
|
+
pact (1.4.0.rc4)
|
|
5
5
|
awesome_print (~> 1.1)
|
|
6
6
|
find_a_port (~> 1.0.1)
|
|
7
7
|
json
|
|
8
|
-
pact-mock_service (~> 0.0
|
|
9
|
-
pact-support (~> 0.
|
|
8
|
+
pact-mock_service (~> 0.1.0)
|
|
9
|
+
pact-support (~> 0.1.2)
|
|
10
10
|
rack-test (~> 0.6.2)
|
|
11
11
|
randexp (~> 0.1.7)
|
|
12
12
|
rspec (>= 2.14)
|
|
@@ -39,17 +39,18 @@ GEM
|
|
|
39
39
|
method_source (0.8.2)
|
|
40
40
|
minitest (5.3.4)
|
|
41
41
|
multipart-post (2.0.0)
|
|
42
|
-
pact-mock_service (0.0
|
|
42
|
+
pact-mock_service (0.1.0)
|
|
43
43
|
awesome_print (~> 1.1)
|
|
44
44
|
find_a_port (~> 1.0.1)
|
|
45
45
|
json
|
|
46
|
+
pact-support (~> 0.1.1)
|
|
46
47
|
rack
|
|
47
48
|
rack-test (~> 0.6.2)
|
|
48
49
|
rspec (>= 2.14)
|
|
49
50
|
term-ansicolor (~> 1.0)
|
|
50
51
|
thor
|
|
51
52
|
webrick
|
|
52
|
-
pact-support (0.
|
|
53
|
+
pact-support (0.1.2)
|
|
53
54
|
awesome_print (~> 1.1)
|
|
54
55
|
find_a_port (~> 1.0.1)
|
|
55
56
|
json
|
|
@@ -71,7 +72,7 @@ GEM
|
|
|
71
72
|
rspec-core (~> 3.1.0)
|
|
72
73
|
rspec-expectations (~> 3.1.0)
|
|
73
74
|
rspec-mocks (~> 3.1.0)
|
|
74
|
-
rspec-core (3.1.
|
|
75
|
+
rspec-core (3.1.7)
|
|
75
76
|
rspec-support (~> 3.1.0)
|
|
76
77
|
rspec-expectations (3.1.2)
|
|
77
78
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
@@ -37,15 +37,6 @@ module Pact
|
|
|
37
37
|
@config_ru_path = config_ru_path
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
def color_enabled
|
|
41
|
-
# Can't use ||= when the variable might be false, it will execute the expression if it's false
|
|
42
|
-
defined?(@color_enabled) ? @color_enabled : true
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def color_enabled= color_enabled
|
|
46
|
-
@color_enabled = color_enabled
|
|
47
|
-
end
|
|
48
|
-
|
|
49
40
|
def include mod
|
|
50
41
|
Pact::Provider::State::ProviderStateConfiguredModules.instance_eval do
|
|
51
42
|
include mod
|
data/lib/pact/version.rb
CHANGED
data/pact.gemspec
CHANGED
|
@@ -28,8 +28,8 @@ Gem::Specification.new do |gem|
|
|
|
28
28
|
gem.add_runtime_dependency 'webrick'
|
|
29
29
|
gem.add_runtime_dependency 'term-ansicolor', '~> 1.0'
|
|
30
30
|
|
|
31
|
-
gem.add_runtime_dependency 'pact-support', '~> 0.
|
|
32
|
-
gem.add_runtime_dependency 'pact-mock_service', '~> 0.0
|
|
31
|
+
gem.add_runtime_dependency 'pact-support', '~> 0.1.2'
|
|
32
|
+
gem.add_runtime_dependency 'pact-mock_service', '~> 0.1.0'
|
|
33
33
|
|
|
34
34
|
gem.add_development_dependency 'rake', '~> 10.0.3'
|
|
35
35
|
gem.add_development_dependency 'webmock', '~> 1.18.0'
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'pact/consumer'
|
|
4
|
+
require 'pact/consumer/rspec'
|
|
5
|
+
require 'faraday'
|
|
6
|
+
load 'pact/consumer/world.rb'
|
|
7
|
+
|
|
8
|
+
describe "A service consumer side of a pact", :pact => true do
|
|
9
|
+
|
|
10
|
+
let(:body) { 'That is some good Mallory.' }
|
|
11
|
+
|
|
12
|
+
context 'submitting a form specified as a Hash' do
|
|
13
|
+
|
|
14
|
+
before :all do
|
|
15
|
+
Pact.clear_configuration
|
|
16
|
+
|
|
17
|
+
Pact.service_consumer "Consumer" do
|
|
18
|
+
has_pact_with "Zebra Service" do
|
|
19
|
+
mock_service :zebra_service_4 do
|
|
20
|
+
port 1245
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
before do
|
|
27
|
+
|
|
28
|
+
zebra_service_4.
|
|
29
|
+
given("the zebras like using forms").
|
|
30
|
+
upon_receiving("a create Mallory request").with({
|
|
31
|
+
method: :post,
|
|
32
|
+
path: '/mallory',
|
|
33
|
+
headers: {'Content-Type' => 'application/x-www-form-urlencoded'},
|
|
34
|
+
body: {
|
|
35
|
+
param1: Pact::Term.new(generate: 'woger', matcher: /w/),
|
|
36
|
+
param2: 'penguin'
|
|
37
|
+
}
|
|
38
|
+
}).
|
|
39
|
+
will_respond_with({
|
|
40
|
+
status: 200
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
let(:url) { zebra_service_4.mock_service_base_url + "/mallory" }
|
|
46
|
+
let(:response) { Faraday.post url, param2: 'penguin', param1: 'wiffle' }
|
|
47
|
+
let(:pact_json) { response; zebra_service_4.write_pact }
|
|
48
|
+
|
|
49
|
+
it "matches form data" do
|
|
50
|
+
expect(response.status).to eq 200
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "does not include any Pact::Terms" do
|
|
54
|
+
expect(pact_json).to_not include "Pact::Term"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "includes the reified form" do
|
|
58
|
+
expect(pact_json).to include "param1=woger"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'pact/consumer'
|
|
4
|
+
require 'pact/consumer/rspec'
|
|
5
|
+
require 'faraday'
|
|
6
|
+
load 'pact/consumer/world.rb'
|
|
7
|
+
|
|
8
|
+
describe "A service consumer side of a pact", :pact => true do
|
|
9
|
+
|
|
10
|
+
let(:body) { 'That is some good Mallory.' }
|
|
11
|
+
|
|
12
|
+
context 'submitting a form' do
|
|
13
|
+
|
|
14
|
+
before :all do
|
|
15
|
+
Pact.clear_configuration
|
|
16
|
+
|
|
17
|
+
Pact.service_consumer "Consumer" do
|
|
18
|
+
has_pact_with "Zebra Service" do
|
|
19
|
+
mock_service :zebra_service_3 do
|
|
20
|
+
port 1243
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
before do
|
|
27
|
+
|
|
28
|
+
zebra_service_3.
|
|
29
|
+
given("the zebras like using forms").
|
|
30
|
+
upon_receiving("a create Mallory request").with({
|
|
31
|
+
method: :post,
|
|
32
|
+
path: '/mallory',
|
|
33
|
+
headers: {'Content-Type' => 'application/x-www-form-urlencoded'},
|
|
34
|
+
body: "param1=wiffle¶m2=penguin"
|
|
35
|
+
}).
|
|
36
|
+
will_respond_with({
|
|
37
|
+
status: 200
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
let(:url) { zebra_service_3.mock_service_base_url + "/mallory" }
|
|
43
|
+
|
|
44
|
+
it "matches form data" do
|
|
45
|
+
response = Faraday.post url, param2: 'penguin', param1: 'wiffle'
|
|
46
|
+
expect(response.status).to eq 200
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -10,10 +10,10 @@ describe "A service consumer side of a pact", :pact => true do
|
|
|
10
10
|
# Helper to make Faraday requests.
|
|
11
11
|
# Faraday::FlatParamsEncoder may only be needed with our current version of Faraday 0.9
|
|
12
12
|
# and ensures that when there are multiple parameters of the same name, they are encoded properly. e.g. colour=blue&colour=green
|
|
13
|
-
def faraday_mallory(base_url,params)
|
|
13
|
+
def faraday_mallory(base_url,params, headers = {})
|
|
14
14
|
(Faraday.new base_url, :request => {
|
|
15
15
|
:params_encoder => Faraday::FlatParamsEncoder,
|
|
16
|
-
}).get '/mallory', params, {'Accept' => 'application/json'}
|
|
16
|
+
}).get '/mallory', params, {'Accept' => 'application/json'}.merge(headers)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
let(:body) { 'That is some good Mallory.' }
|
|
@@ -77,7 +77,7 @@ describe "A service consumer side of a pact", :pact => true do
|
|
|
77
77
|
|
|
78
78
|
context "and a complex request matching Pact Terms and multiple instances of the same parameter" do
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
before :all do
|
|
81
81
|
Pact.clear_configuration
|
|
82
82
|
Pact.service_consumer "Consumer" do
|
|
83
83
|
has_pact_with "Zebra Service" do
|
|
@@ -87,13 +87,16 @@ describe "A service consumer side of a pact", :pact => true do
|
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
before do
|
|
90
93
|
zebra_service.
|
|
91
94
|
given(:the_zebras_are_here).
|
|
92
95
|
upon_receiving("a retrieve Mallory request").
|
|
93
96
|
with({
|
|
94
97
|
method: :get,
|
|
95
98
|
path: '/mallory',
|
|
96
|
-
headers: {'Accept' => 'application/json'},
|
|
99
|
+
headers: {'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'},
|
|
97
100
|
query: { size: ['small',Pact::Term.new(matcher: /med.*/, generate: 'medium'),'large'], colour: 'brown', weight: '5'}
|
|
98
101
|
}).
|
|
99
102
|
will_respond_with({
|
|
@@ -101,11 +104,19 @@ describe "A service consumer side of a pact", :pact => true do
|
|
|
101
104
|
headers: { 'Content-Type' => 'application/json' },
|
|
102
105
|
body: Pact::Term.new(matcher: /Mallory/, generate: body)
|
|
103
106
|
})
|
|
104
|
-
|
|
105
|
-
expect(response.body).to eq body
|
|
107
|
+
end
|
|
106
108
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
let(:response) do
|
|
110
|
+
faraday_mallory(
|
|
111
|
+
zebra_service.mock_service_base_url,
|
|
112
|
+
{ weight: 5, size: ['small','medium','large'], colour: 'brown'},
|
|
113
|
+
{'Content-Type' => 'application/x-www-form-urlencoded'}
|
|
114
|
+
)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "goes like this" do
|
|
118
|
+
expect(response.body).to eq body
|
|
109
119
|
end
|
|
120
|
+
|
|
110
121
|
end
|
|
111
122
|
end
|
|
@@ -11,20 +11,7 @@ module Pact
|
|
|
11
11
|
|
|
12
12
|
subject { Object.new.extend(ConfigurationExtension) }
|
|
13
13
|
|
|
14
|
-
describe "#color_enabled" do
|
|
15
|
-
|
|
16
|
-
it "sets color_enabled to be true by default" do
|
|
17
|
-
expect(subject.color_enabled).to be true
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "allows configuration of colour_enabled" do
|
|
21
|
-
subject.color_enabled = false
|
|
22
|
-
expect(subject.color_enabled).to be false
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
end
|
|
26
|
-
|
|
27
14
|
end
|
|
28
15
|
end
|
|
29
16
|
end
|
|
30
|
-
end
|
|
17
|
+
end
|
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.4.0.
|
|
4
|
+
version: 1.4.0.rc4
|
|
5
5
|
prerelease: 6
|
|
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: 2014-10-
|
|
16
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
|
17
17
|
dependencies:
|
|
18
18
|
- !ruby/object:Gem::Dependency
|
|
19
19
|
name: randexp
|
|
@@ -166,7 +166,7 @@ dependencies:
|
|
|
166
166
|
requirements:
|
|
167
167
|
- - ~>
|
|
168
168
|
- !ruby/object:Gem::Version
|
|
169
|
-
version: 0.
|
|
169
|
+
version: 0.1.2
|
|
170
170
|
type: :runtime
|
|
171
171
|
prerelease: false
|
|
172
172
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -174,7 +174,7 @@ dependencies:
|
|
|
174
174
|
requirements:
|
|
175
175
|
- - ~>
|
|
176
176
|
- !ruby/object:Gem::Version
|
|
177
|
-
version: 0.
|
|
177
|
+
version: 0.1.2
|
|
178
178
|
- !ruby/object:Gem::Dependency
|
|
179
179
|
name: pact-mock_service
|
|
180
180
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -182,7 +182,7 @@ dependencies:
|
|
|
182
182
|
requirements:
|
|
183
183
|
- - ~>
|
|
184
184
|
- !ruby/object:Gem::Version
|
|
185
|
-
version: 0.0
|
|
185
|
+
version: 0.1.0
|
|
186
186
|
type: :runtime
|
|
187
187
|
prerelease: false
|
|
188
188
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -190,7 +190,7 @@ dependencies:
|
|
|
190
190
|
requirements:
|
|
191
191
|
- - ~>
|
|
192
192
|
- !ruby/object:Gem::Version
|
|
193
|
-
version: 0.0
|
|
193
|
+
version: 0.1.0
|
|
194
194
|
- !ruby/object:Gem::Dependency
|
|
195
195
|
name: rake
|
|
196
196
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -423,6 +423,8 @@ files:
|
|
|
423
423
|
- spec/integration/consumer_more_than_one_matching_interaction_spec.rb
|
|
424
424
|
- spec/integration/consumer_no_matching_interaction_spec.rb
|
|
425
425
|
- spec/integration/consumer_with_a_provider_state_spec.rb
|
|
426
|
+
- spec/integration/consumer_with_form_hash_spec.rb
|
|
427
|
+
- spec/integration/consumer_with_form_spec.rb
|
|
426
428
|
- spec/integration/consumer_with_params_hash_spec.rb
|
|
427
429
|
- spec/integration/pact/consumer_configuration_spec.rb
|
|
428
430
|
- spec/integration/pact/provider_configuration_spec.rb
|
|
@@ -439,10 +441,7 @@ files:
|
|
|
439
441
|
- spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb
|
|
440
442
|
- spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb
|
|
441
443
|
- spec/lib/pact/consumer/mock_service/verification_get_spec.rb
|
|
442
|
-
- spec/lib/pact/consumer/mock_service_client_spec.rb
|
|
443
|
-
- spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
|
|
444
444
|
- spec/lib/pact/consumer/service_consumer_spec.rb
|
|
445
|
-
- spec/lib/pact/consumer_contract/consumer_contract_writer_spec.rb
|
|
446
445
|
- spec/lib/pact/doc/generator_spec.rb
|
|
447
446
|
- spec/lib/pact/doc/interaction_view_model_spec.rb
|
|
448
447
|
- spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb
|
|
@@ -511,7 +510,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
511
510
|
version: '0'
|
|
512
511
|
segments:
|
|
513
512
|
- 0
|
|
514
|
-
hash:
|
|
513
|
+
hash: 2889901042429282907
|
|
515
514
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
516
515
|
none: false
|
|
517
516
|
requirements:
|
|
@@ -534,6 +533,8 @@ test_files:
|
|
|
534
533
|
- spec/integration/consumer_more_than_one_matching_interaction_spec.rb
|
|
535
534
|
- spec/integration/consumer_no_matching_interaction_spec.rb
|
|
536
535
|
- spec/integration/consumer_with_a_provider_state_spec.rb
|
|
536
|
+
- spec/integration/consumer_with_form_hash_spec.rb
|
|
537
|
+
- spec/integration/consumer_with_form_spec.rb
|
|
537
538
|
- spec/integration/consumer_with_params_hash_spec.rb
|
|
538
539
|
- spec/integration/pact/consumer_configuration_spec.rb
|
|
539
540
|
- spec/integration/pact/provider_configuration_spec.rb
|
|
@@ -550,10 +551,7 @@ test_files:
|
|
|
550
551
|
- spec/lib/pact/consumer/mock_service/interaction_replay_spec.rb
|
|
551
552
|
- spec/lib/pact/consumer/mock_service/rack_request_helper_spec.rb
|
|
552
553
|
- spec/lib/pact/consumer/mock_service/verification_get_spec.rb
|
|
553
|
-
- spec/lib/pact/consumer/mock_service_client_spec.rb
|
|
554
|
-
- spec/lib/pact/consumer/mock_service_interaction_expectation_spec.rb
|
|
555
554
|
- spec/lib/pact/consumer/service_consumer_spec.rb
|
|
556
|
-
- spec/lib/pact/consumer_contract/consumer_contract_writer_spec.rb
|
|
557
555
|
- spec/lib/pact/doc/generator_spec.rb
|
|
558
556
|
- spec/lib/pact/doc/interaction_view_model_spec.rb
|
|
559
557
|
- spec/lib/pact/doc/markdown/consumer_contract_renderer_spec.rb
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'pact/consumer/mock_service_client'
|
|
3
|
-
|
|
4
|
-
module Pact
|
|
5
|
-
module Consumer
|
|
6
|
-
describe MockServiceClient do
|
|
7
|
-
|
|
8
|
-
subject { MockServiceClient.new(4444) }
|
|
9
|
-
|
|
10
|
-
let(:administration_headers) { {'X-Pact-Mock-Service' => 'true'} }
|
|
11
|
-
|
|
12
|
-
describe "#add_expected_interaction" do
|
|
13
|
-
let(:interaction) { InteractionFactory.create }
|
|
14
|
-
let(:request_body) { MockServiceInteractionExpectation.new(interaction).to_json }
|
|
15
|
-
|
|
16
|
-
context "when successful" do
|
|
17
|
-
let!(:post_interaction) do
|
|
18
|
-
stub_request(:post, "localhost:4444/interactions").
|
|
19
|
-
with(body: request_body, headers: administration_headers.merge('Content-Type' => "application/json")).
|
|
20
|
-
to_return(status: 200)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "sets up the expected interaction on the mock server" do
|
|
24
|
-
subject.add_expected_interaction interaction
|
|
25
|
-
expect(post_interaction).to have_been_made
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe "#verify" do
|
|
32
|
-
|
|
33
|
-
context "when all interactions are successfully verified" do
|
|
34
|
-
|
|
35
|
-
let!(:get_verification) do
|
|
36
|
-
stub_request(:get, "localhost:4444/interactions/verification?example_description=some%20example").
|
|
37
|
-
with(headers: administration_headers).
|
|
38
|
-
to_return(status: 200)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "does not throw an error" do
|
|
42
|
-
subject.verify "some example"
|
|
43
|
-
expect(get_verification).to have_been_made
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe ".clear_interactions" do
|
|
49
|
-
let!(:delete_verifications) do
|
|
50
|
-
stub_request(:delete, "localhost:4444/interactions?example_description=some%20example").
|
|
51
|
-
with(headers: administration_headers).
|
|
52
|
-
to_return(status: 200)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "deletes the interactions" do
|
|
56
|
-
MockServiceClient.clear_interactions 4444, "some example"
|
|
57
|
-
expect(delete_verifications).to have_been_made
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
describe "#write_pact" do
|
|
62
|
-
let(:consumer_contract_details) { {consumer: {name: 'Consumer'}, provider: {name: 'Provider'}, pactfile_write_mode: 'update'} }
|
|
63
|
-
let(:pact) { {a: 'pact'}.to_json }
|
|
64
|
-
|
|
65
|
-
let!(:post_pact) do
|
|
66
|
-
stub_request(:post, "localhost:4444/pact").
|
|
67
|
-
with(headers: administration_headers.merge('Content-Type' => "application/json"), body: consumer_contract_details).
|
|
68
|
-
to_return(status: 200, body: pact)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "deletes the interactions" do
|
|
72
|
-
expect(subject.write_pact(consumer_contract_details)).to eq pact
|
|
73
|
-
expect(post_pact).to have_been_made
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
describe "#log" do
|
|
79
|
-
it "sends a log request to the mock server"
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
describe "#wait_for_interactions" do
|
|
83
|
-
it "waits until there are no missing interactions"
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'pact/consumer/mock_service_interaction_expectation'
|
|
3
|
-
|
|
4
|
-
describe Pact::Consumer::MockServiceInteractionExpectation do
|
|
5
|
-
describe "as_json" do
|
|
6
|
-
|
|
7
|
-
let(:options ) { {} }
|
|
8
|
-
let(:request_as_json) { {a: 'request'} }
|
|
9
|
-
let(:request) { instance_double('Pact::Request::Expected', :as_json => request_as_json, :options => options)}
|
|
10
|
-
let(:response) { double('response') }
|
|
11
|
-
let(:generated_response ) { double('generated_response', :to_json => 'generated_response') }
|
|
12
|
-
let(:interaction) { instance_double('Pact::Interaction', :description => 'description', :request => request, :response => response, :provider_state => 'some state') }
|
|
13
|
-
subject { described_class.new(interaction)}
|
|
14
|
-
let(:expected_hash) { {:response => generated_response, :request => as_json_with_options, :description => '' } }
|
|
15
|
-
|
|
16
|
-
before do
|
|
17
|
-
allow(Pact::Reification).to receive(:from_term).with(response).and_return(generated_response)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "includes the response" do
|
|
21
|
-
expect(subject.as_json[:response]).to eq response
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "includes the options in the request" do
|
|
25
|
-
expect(subject.as_json[:request]).to eq request_as_json
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "includes the provider state" do
|
|
29
|
-
expect(subject.as_json[:provider_state]).to eq 'some state'
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "includes the description" do
|
|
33
|
-
expect(subject.as_json[:description]).to eq 'description'
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "doesn't have any other keys" do
|
|
37
|
-
expect(subject.as_json.keys).to eq [:description, :provider_state, :request, :response]
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
context "without options" do
|
|
41
|
-
it "does not include the options key" do
|
|
42
|
-
expect(subject.as_json.key?(:options)).to be false
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context "with options" do
|
|
47
|
-
let(:options) { {:opts => 'blah'} }
|
|
48
|
-
it "includes the options in the request hash" do
|
|
49
|
-
expect(subject.as_json[:request][:options]).to eq options
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
end
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'pact/consumer_contract/consumer_contract_writer'
|
|
3
|
-
|
|
4
|
-
module Pact
|
|
5
|
-
|
|
6
|
-
describe ConsumerContractWriter do
|
|
7
|
-
|
|
8
|
-
let(:support_pact_file) { './spec/support/a_consumer-a_provider.json' }
|
|
9
|
-
let(:consumer_name) { 'a consumer' }
|
|
10
|
-
let(:provider_name) { 'a provider' }
|
|
11
|
-
|
|
12
|
-
before do
|
|
13
|
-
Pact.clear_configuration
|
|
14
|
-
allow(Pact.configuration).to receive(:pact_dir).and_return(File.expand_path(tmp_pact_dir))
|
|
15
|
-
FileUtils.rm_rf tmp_pact_dir
|
|
16
|
-
FileUtils.mkdir_p tmp_pact_dir
|
|
17
|
-
FileUtils.cp support_pact_file, "#{tmp_pact_dir}/a_consumer-a_provider.json"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
let(:existing_interactions) { ConsumerContract.from_json(File.read(support_pact_file)).interactions }
|
|
21
|
-
let(:new_interactions) { [InteractionFactory.create] }
|
|
22
|
-
let(:tmp_pact_dir) {"./tmp/pacts"}
|
|
23
|
-
let(:logger) { double("logger").as_null_object }
|
|
24
|
-
let(:pactfile_write_mode) {:overwrite}
|
|
25
|
-
let(:consumer_contract_details) {
|
|
26
|
-
{
|
|
27
|
-
consumer: {name: consumer_name},
|
|
28
|
-
provider: {name: provider_name},
|
|
29
|
-
pactfile_write_mode: pactfile_write_mode,
|
|
30
|
-
interactions: new_interactions
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let(:consumer_contract_writer) { ConsumerContractWriter.new(consumer_contract_details, logger) }
|
|
35
|
-
|
|
36
|
-
describe "consumer_contract" do
|
|
37
|
-
|
|
38
|
-
let(:subject) { consumer_contract_writer.consumer_contract }
|
|
39
|
-
|
|
40
|
-
context "when overwriting pact" do
|
|
41
|
-
|
|
42
|
-
it "it uses only the interactions from the current test run" do
|
|
43
|
-
expect(consumer_contract_writer.consumer_contract.interactions).to eq new_interactions
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context "when updating pact" do
|
|
49
|
-
|
|
50
|
-
let(:pactfile_write_mode) {:update}
|
|
51
|
-
|
|
52
|
-
it "merges the interactions from the current test run with the interactions from the existing file" do
|
|
53
|
-
allow_any_instance_of(ConsumerContractWriter).to receive(:info_and_puts)
|
|
54
|
-
expect(consumer_contract_writer.consumer_contract.interactions).to eq existing_interactions + new_interactions
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
let(:line0) { /\*/ }
|
|
58
|
-
let(:line1) { /Updating existing file/ }
|
|
59
|
-
let(:line2) { /Only interactions defined in this test run will be updated/ }
|
|
60
|
-
let(:line3) { /As interactions are identified by description and provider state/ }
|
|
61
|
-
|
|
62
|
-
it "logs a description message" do
|
|
63
|
-
expect($stdout).to receive(:puts).with(line0).twice
|
|
64
|
-
expect($stdout).to receive(:puts).with(line1)
|
|
65
|
-
expect($stdout).to receive(:puts).with(line2)
|
|
66
|
-
expect($stdout).to receive(:puts).with(line3)
|
|
67
|
-
expect(logger).to receive(:info).with(line0).twice
|
|
68
|
-
expect(logger).to receive(:info).with(line1)
|
|
69
|
-
expect(logger).to receive(:info).with(line2)
|
|
70
|
-
expect(logger).to receive(:info).with(line3)
|
|
71
|
-
consumer_contract_writer.consumer_contract
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
context "when an error occurs deserializing the existing pactfile" do
|
|
76
|
-
|
|
77
|
-
let(:pactfile_write_mode) {:update}
|
|
78
|
-
let(:error) { RuntimeError.new('some error')}
|
|
79
|
-
let(:line1) { /Could not load existing consumer contract from .* due to some error/ }
|
|
80
|
-
let(:line2) {'Creating a new file.'}
|
|
81
|
-
|
|
82
|
-
before do
|
|
83
|
-
allow(ConsumerContract).to receive(:from_json).and_raise(error)
|
|
84
|
-
allow($stderr).to receive(:puts)
|
|
85
|
-
allow(logger).to receive(:puts)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it "logs the error" do
|
|
89
|
-
expect($stderr).to receive(:puts).with(line1)
|
|
90
|
-
expect($stderr).to receive(:puts).with(line2)
|
|
91
|
-
expect(logger).to receive(:warn).with(line1)
|
|
92
|
-
expect(logger).to receive(:warn).with(line2)
|
|
93
|
-
consumer_contract_writer.consumer_contract
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it "uses the new interactions" do
|
|
97
|
-
expect(consumer_contract_writer.consumer_contract.interactions).to eq new_interactions
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
describe "write" do
|
|
103
|
-
it "writes the pact file" do
|
|
104
|
-
expect_any_instance_of(ConsumerContract).to receive(:update_pactfile)
|
|
105
|
-
consumer_contract_writer.write
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
end
|