pact 1.4.0.rc2 → 1.4.0.rc3

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 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.rc3 (17 October 2014)
6
+
7
+ * 602906f - Upped pact-support version to allow queries specified as hashes. (bethesque, Fri Oct 17 14:30:39 2014 +1100)
8
+
5
9
  ### 1.4.0.rc2 (12 October 2014)
6
10
 
7
11
  * 61036fc - Updating pact-support version (bethesque, Sun Oct 12 14:39:36 2014 +1100)
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pact (1.4.0.rc2)
4
+ pact (1.4.0.rc3)
5
5
  awesome_print (~> 1.1)
6
6
  find_a_port (~> 1.0.1)
7
7
  json
8
8
  pact-mock_service (~> 0.0.1)
9
- pact-support (~> 0.0.2)
9
+ pact-support (~> 0.0.3)
10
10
  rack-test (~> 0.6.2)
11
11
  randexp (~> 0.1.7)
12
12
  rspec (>= 2.14)
@@ -49,7 +49,7 @@ GEM
49
49
  term-ansicolor (~> 1.0)
50
50
  thor
51
51
  webrick
52
- pact-support (0.0.2)
52
+ pact-support (0.0.3)
53
53
  awesome_print (~> 1.1)
54
54
  find_a_port (~> 1.0.1)
55
55
  json
data/lib/pact/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pact
2
- VERSION = "1.4.0.rc2"
2
+ VERSION = "1.4.0.rc3"
3
3
  end
data/pact.gemspec CHANGED
@@ -28,10 +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
- unless ENV['X_PACT_DEVELOPMENT']
32
- gem.add_runtime_dependency 'pact-support', '~> 0.0.2'
33
- gem.add_runtime_dependency 'pact-mock_service', '~> 0.0.1'
34
- end
31
+ gem.add_runtime_dependency 'pact-support', '~> 0.0.3'
32
+ gem.add_runtime_dependency 'pact-mock_service', '~> 0.0.1'
35
33
 
36
34
  gem.add_development_dependency 'rake', '~> 10.0.3'
37
35
  gem.add_development_dependency 'webmock', '~> 1.18.0'
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'pact/consumer'
3
+ require 'pact/consumer/rspec'
4
+ load 'pact/consumer/world.rb'
5
+
6
+ describe "A service consumer side of a pact", :pact => true do
7
+
8
+ context "with an asynchronous interaction with provider" do
9
+ before do
10
+ Pact.clear_configuration
11
+
12
+ Pact.service_consumer "Consumer" do
13
+ has_pact_with "Zebra Service" do
14
+ mock_service :zebra_service do
15
+ verify true
16
+ port 1239
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ it "goes like this" do
23
+ zebra_service.
24
+ given(:the_zebras_are_here).
25
+ upon_receiving("a retrieve Mallory request").
26
+ with({
27
+ method: :get,
28
+ path: '/mallory'
29
+ }).
30
+ will_respond_with({status: 200})
31
+
32
+ async_interaction { Net::HTTP.get_response(URI('http://localhost:1239/mallory')) }
33
+
34
+ zebra_service.wait_for_interactions wait_max_seconds: 1, poll_interval: 0.1
35
+ end
36
+
37
+ def async_interaction
38
+ Thread.new do
39
+ sleep 0.2
40
+ yield
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,49 @@
1
+ require 'pact/consumer'
2
+ require 'pact/consumer/rspec'
3
+ load 'pact/consumer/world.rb'
4
+
5
+ describe "A service consumer side of a pact", :pact => true do
6
+
7
+ context "with more than one matching interaction found" do
8
+ let(:expected_response) do
9
+ {"message"=>"Multiple interaction found for GET /path", "matching_interactions"=>[{"description"=>"a request", "request"=>{"method"=>"get", "path"=>"/path", "body"=>{"a"=>"some body"}, "headers"=>{"Content-Type"=>"application/json"}}}, {"description"=>"an identical request", "request"=>{"method"=>"get", "path"=>"/path", "body"=>{"a"=>"some body"}, "headers"=>{"Content-Type"=>"application/json"}}}]}
10
+ end
11
+
12
+ it "returns an error" do
13
+ Pact.clear_configuration
14
+ Pact.clear_consumer_world
15
+
16
+ Pact.service_consumer "Consumer" do
17
+ has_pact_with "Mary Service" do
18
+ mock_service :mary_service do
19
+ verify false
20
+ port 1237
21
+ end
22
+ end
23
+ end
24
+
25
+ mary_service
26
+ .given("something")
27
+ .upon_receiving("a request")
28
+ .with(method: 'get', path: '/path', body: {a: 'some body'}, headers: {'Content-Type' => 'application/json'})
29
+ .will_respond_with(status: 200)
30
+
31
+
32
+ mary_service
33
+ .upon_receiving("an identical request")
34
+ .with(method: 'get', path: '/path', body: {a: 'some body'}, headers: {'Content-Type' => 'application/json'})
35
+ .will_respond_with(status: 200)
36
+
37
+ uri = URI('http://localhost:1237/path')
38
+ post_req = Net::HTTP::Get.new(uri.path)
39
+ post_req['Content-Type'] = "application/json"
40
+ post_req.body = {a: "some body"}.to_json
41
+ response = Net::HTTP.start(uri.hostname, uri.port) do |http|
42
+ http.request post_req
43
+ end
44
+
45
+ expect(JSON.load(response.body)).to eq expected_response
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,53 @@
1
+ require 'pact/consumer'
2
+ require 'pact/consumer/rspec'
3
+ load 'pact/consumer/world.rb'
4
+
5
+ describe "A service consumer side of a pact", :pact => true do
6
+ context "with no matching interaction found" do
7
+
8
+ let(:expected_response) do
9
+ {
10
+ "message"=>"No interaction found for GET /path",
11
+ "interaction_diffs"=>[{
12
+ "description" => "a request that will not be properly matched",
13
+ "provider_state" => "something",
14
+ "body"=>{
15
+ "a"=>{
16
+ "EXPECTED"=>"some body",
17
+ "ACTUAL"=>"not matching body"
18
+ }
19
+ }
20
+ }]
21
+ }
22
+ end
23
+
24
+ it "returns an error" do
25
+ Pact.clear_configuration
26
+
27
+ Pact.service_consumer "Consumer" do
28
+ has_pact_with "Mary Service" do
29
+ mock_service :mary_service do
30
+ verify false
31
+ port 1236
32
+ end
33
+ end
34
+ end
35
+
36
+ mary_service
37
+ .given("something")
38
+ .upon_receiving("a request that will not be properly matched")
39
+ .with(method: 'get', path: '/path', body: {a: 'some body'}, headers: {'Content-Type' => 'application/json'})
40
+ .will_respond_with(status: 200)
41
+
42
+ uri = URI('http://localhost:1236/path')
43
+ post_req = Net::HTTP::Get.new(uri.path)
44
+ post_req['Content-Type'] = "application/json"
45
+ post_req.body = {a: "not matching body"}.to_json
46
+ response = Net::HTTP.start(uri.hostname, uri.port) do |http|
47
+ http.request post_req
48
+ end
49
+
50
+ expect(JSON.load(response.body)).to eq expected_response
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,44 @@
1
+ require 'pact/consumer'
2
+ require 'pact/consumer/rspec'
3
+ load 'pact/consumer/world.rb'
4
+ require 'faraday'
5
+
6
+ describe "A service consumer side of a pact", :pact => true do
7
+ context "with a provider state" do
8
+ before do
9
+ Pact.clear_configuration
10
+
11
+ Pact.service_consumer "Consumer" do
12
+ has_pact_with "Zebra Service" do
13
+ mock_service :zebra_service do
14
+ verify false
15
+ port 1235
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ let(:body) { 'That is some good Mallory.' }
22
+
23
+ it "goes like this" do
24
+ zebra_service.
25
+ given(:the_zebras_are_here).
26
+ upon_receiving("a retrieve Mallory request").with({
27
+ method: :get,
28
+ path: '/mallory',
29
+ headers: {'Accept' => 'text/html'}
30
+ }).
31
+ will_respond_with({
32
+ status: 200,
33
+ headers: { 'Content-Type' => 'text/html' },
34
+ body: Pact::Term.new(matcher: /Mallory/, generate: body)
35
+ })
36
+
37
+ response = Faraday.get(zebra_service.mock_service_base_url + "/mallory", nil, {'Accept' => 'text/html'})
38
+ expect(response.body).to eq body
39
+
40
+ interactions = Pact::ConsumerContract.from_json(zebra_service.write_pact).interactions
41
+ expect(interactions.first.provider_state).to eq("the_zebras_are_here")
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,111 @@
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
+ # Helper to make Faraday requests.
11
+ # Faraday::FlatParamsEncoder may only be needed with our current version of Faraday 0.9
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)
14
+ (Faraday.new base_url, :request => {
15
+ :params_encoder => Faraday::FlatParamsEncoder,
16
+ }).get '/mallory', params, {'Accept' => 'application/json'}
17
+ end
18
+
19
+ let(:body) { 'That is some good Mallory.' }
20
+
21
+ context 'When expecting multiple instances of the same parameter in the query' do
22
+
23
+ before :all do
24
+ Pact.clear_configuration
25
+
26
+ Pact.service_consumer "Consumer" do
27
+ has_pact_with "Zebra Service" do
28
+ mock_service :zebra_service2 do
29
+ verify false
30
+ port 1241
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ before do
37
+
38
+ zebra_service2.
39
+ given(:the_zebras_are_here).
40
+ upon_receiving("a retrieve Mallory request").with({
41
+ method: :get,
42
+ path: '/mallory',
43
+ headers: {'Accept' => 'application/json'},
44
+ query: {colour: 'brown', size: ['small', 'large']}
45
+ }).
46
+ will_respond_with({
47
+ status: 200,
48
+ headers: { 'Content-Type' => 'application/json' },
49
+ body: Pact::Term.new(matcher: /Mallory/, generate: body)
50
+ })
51
+
52
+ end
53
+
54
+ it "matches when all instances are provided" do
55
+ response= faraday_mallory(zebra_service2.mock_service_base_url, { size: ['small','large'], colour: 'brown'})
56
+ expect(response.body).to eq body
57
+
58
+ interactions = Pact::ConsumerContract.from_json(zebra_service2.write_pact).interactions
59
+ expect(interactions.first.provider_state).to eq("the_zebras_are_here")
60
+ end
61
+
62
+ it "does not match when only the first instance is provided" do
63
+ response = Faraday.get(zebra_service2.mock_service_base_url + "/mallory?colour=brown&size=small", nil, {'Accept' => 'application/json'})
64
+ expect(response.body).not_to eq body
65
+ end
66
+
67
+ it "does not match when only the last instance is provided" do
68
+ response = Faraday.get(zebra_service2.mock_service_base_url + "/mallory?colour=brown&size=large", nil, {'Accept' => 'application/json'})
69
+ expect(response.body).not_to eq body
70
+ end
71
+
72
+ it "does not match when they are out of order" do
73
+ response= faraday_mallory(zebra_service2.mock_service_base_url, { size: ['large','small'], colour: 'brown'})
74
+ expect(response.body).not_to eq body
75
+ end
76
+ end
77
+
78
+ context "and a complex request matching Pact Terms and multiple instances of the same parameter" do
79
+
80
+ it "goes like this" do
81
+ Pact.clear_configuration
82
+ Pact.service_consumer "Consumer" do
83
+ has_pact_with "Zebra Service" do
84
+ mock_service :zebra_service do
85
+ verify false
86
+ port 1242
87
+ end
88
+ end
89
+ end
90
+ zebra_service.
91
+ given(:the_zebras_are_here).
92
+ upon_receiving("a retrieve Mallory request").
93
+ with({
94
+ method: :get,
95
+ path: '/mallory',
96
+ headers: {'Accept' => 'application/json'},
97
+ query: { size: ['small',Pact::Term.new(matcher: /med.*/, generate: 'medium'),'large'], colour: 'brown', weight: '5'}
98
+ }).
99
+ will_respond_with({
100
+ status: 200,
101
+ headers: { 'Content-Type' => 'application/json' },
102
+ body: Pact::Term.new(matcher: /Mallory/, generate: body)
103
+ })
104
+ response = faraday_mallory(zebra_service.mock_service_base_url, { weight: 5, size: ['small','medium','large'], colour: 'brown'})
105
+ expect(response.body).to eq body
106
+
107
+ interactions = Pact::ConsumerContract.from_json(zebra_service.write_pact).interactions
108
+ expect(interactions.first.provider_state).to eq("the_zebras_are_here")
109
+ end
110
+ end
111
+ 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.rc2
4
+ version: 1.4.0.rc3
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-12 00:00:00.000000000 Z
16
+ date: 2014-10-17 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.0.2
169
+ version: 0.0.3
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.0.2
177
+ version: 0.0.3
178
178
  - !ruby/object:Gem::Dependency
179
179
  name: pact-mock_service
180
180
  requirement: !ruby/object:Gem::Requirement
@@ -419,7 +419,11 @@ files:
419
419
  - spec/features/consumption_spec.rb
420
420
  - spec/features/production_spec.rb
421
421
  - spec/features/provider_states/zebras.rb
422
- - spec/integration/consumer_spec.rb
422
+ - spec/integration/consumer_async_request_spec.rb
423
+ - spec/integration/consumer_more_than_one_matching_interaction_spec.rb
424
+ - spec/integration/consumer_no_matching_interaction_spec.rb
425
+ - spec/integration/consumer_with_a_provider_state_spec.rb
426
+ - spec/integration/consumer_with_params_hash_spec.rb
423
427
  - spec/integration/pact/consumer_configuration_spec.rb
424
428
  - spec/integration/pact/provider_configuration_spec.rb
425
429
  - spec/lib/pact/cli_spec.rb
@@ -507,7 +511,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
507
511
  version: '0'
508
512
  segments:
509
513
  - 0
510
- hash: 2508150550724999576
514
+ hash: 2688969630931365840
511
515
  required_rubygems_version: !ruby/object:Gem::Requirement
512
516
  none: false
513
517
  requirements:
@@ -526,7 +530,11 @@ test_files:
526
530
  - spec/features/consumption_spec.rb
527
531
  - spec/features/production_spec.rb
528
532
  - spec/features/provider_states/zebras.rb
529
- - spec/integration/consumer_spec.rb
533
+ - spec/integration/consumer_async_request_spec.rb
534
+ - spec/integration/consumer_more_than_one_matching_interaction_spec.rb
535
+ - spec/integration/consumer_no_matching_interaction_spec.rb
536
+ - spec/integration/consumer_with_a_provider_state_spec.rb
537
+ - spec/integration/consumer_with_params_hash_spec.rb
530
538
  - spec/integration/pact/consumer_configuration_spec.rb
531
539
  - spec/integration/pact/provider_configuration_spec.rb
532
540
  - spec/lib/pact/cli_spec.rb
@@ -1,212 +0,0 @@
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
- context "with more than one matching interaction found" do
11
- let(:expected_response) do
12
- {"message"=>"Multiple interaction found for GET /path", "matching_interactions"=>[{"description"=>"a request", "request"=>{"method"=>"get", "path"=>"/path", "body"=>{"a"=>"some body"}, "headers"=>{"Content-Type"=>"application/json"}}}, {"description"=>"an identical request", "request"=>{"method"=>"get", "path"=>"/path", "body"=>{"a"=>"some body"}, "headers"=>{"Content-Type"=>"application/json"}}}]}
13
- end
14
-
15
- it "returns an error" do
16
- Pact.clear_configuration
17
- Pact.clear_consumer_world
18
-
19
- Pact.service_consumer "Consumer" do
20
- has_pact_with "Mary Service" do
21
- mock_service :mary_service do
22
- verify false
23
- port 1237
24
- end
25
- end
26
- end
27
-
28
- mary_service
29
- .given("something")
30
- .upon_receiving("a request")
31
- .with(method: 'get', path: '/path', body: {a: 'some body'}, headers: {'Content-Type' => 'application/json'})
32
- .will_respond_with(status: 200)
33
-
34
-
35
- mary_service
36
- .upon_receiving("an identical request")
37
- .with(method: 'get', path: '/path', body: {a: 'some body'}, headers: {'Content-Type' => 'application/json'})
38
- .will_respond_with(status: 200)
39
-
40
- uri = URI('http://localhost:1237/path')
41
- post_req = Net::HTTP::Get.new(uri.path)
42
- post_req['Content-Type'] = "application/json"
43
- post_req.body = {a: "some body"}.to_json
44
- response = Net::HTTP.start(uri.hostname, uri.port) do |http|
45
- http.request post_req
46
- end
47
-
48
- expect(JSON.load(response.body)).to eq expected_response
49
- end
50
-
51
- end
52
-
53
- context "with no matching interaction found" do
54
-
55
- let(:expected_response) do
56
- {
57
- "message"=>"No interaction found for GET /path",
58
- "interaction_diffs"=>[{
59
- "description" => "a request that will not be properly matched",
60
- "provider_state" => "something",
61
- "body"=>{
62
- "a"=>{
63
- "EXPECTED"=>"some body",
64
- "ACTUAL"=>"not matching body"
65
- }
66
- }
67
- }]
68
- }
69
- end
70
-
71
- it "returns an error" do
72
- Pact.clear_configuration
73
-
74
- Pact.service_consumer "Consumer" do
75
- has_pact_with "Mary Service" do
76
- mock_service :mary_service do
77
- verify false
78
- port 1236
79
- end
80
- end
81
- end
82
-
83
- mary_service
84
- .given("something")
85
- .upon_receiving("a request that will not be properly matched")
86
- .with(method: 'get', path: '/path', body: {a: 'some body'}, headers: {'Content-Type' => 'application/json'})
87
- .will_respond_with(status: 200)
88
-
89
- uri = URI('http://localhost:1236/path')
90
- post_req = Net::HTTP::Get.new(uri.path)
91
- post_req['Content-Type'] = "application/json"
92
- post_req.body = {a: "not matching body"}.to_json
93
- response = Net::HTTP.start(uri.hostname, uri.port) do |http|
94
- http.request post_req
95
- end
96
-
97
- expect(JSON.load(response.body)).to eq expected_response
98
- end
99
- end
100
-
101
- context "with a provider state" do
102
- before do
103
- Pact.clear_configuration
104
-
105
- Pact.service_consumer "Consumer" do
106
- has_pact_with "Zebra Service" do
107
- mock_service :zebra_service do
108
- verify false
109
- port 1235
110
- end
111
- end
112
- end
113
- end
114
-
115
- let(:body) { 'That is some good Mallory.' }
116
-
117
- it "goes like this" do
118
- zebra_service.
119
- given(:the_zebras_are_here).
120
- upon_receiving("a retrieve Mallory request").with({
121
- method: :get,
122
- path: '/mallory',
123
- headers: {'Accept' => 'text/html'}
124
- }).
125
- will_respond_with({
126
- status: 200,
127
- headers: { 'Content-Type' => 'text/html' },
128
- body: Pact::Term.new(matcher: /Mallory/, generate: body)
129
- })
130
-
131
- response = Faraday.get(zebra_service.mock_service_base_url + "/mallory", nil, {'Accept' => 'text/html'})
132
- expect(response.body).to eq body
133
-
134
- interactions = Pact::ConsumerContract.from_json(zebra_service.write_pact).interactions
135
- expect(interactions.first.provider_state).to eq("the_zebras_are_here")
136
- end
137
- end
138
-
139
- context "with multiple headers" do
140
- before do
141
- Pact.clear_configuration
142
- Pact.service_consumer "Consumer" do
143
- has_pact_with "Multi Headers Service" do
144
- mock_service :multi_headers_service do
145
- verify true
146
- port 1240
147
- end
148
- end
149
- end
150
-
151
- multi_headers_service.
152
- given("there are multiple headers").
153
- upon_receiving("a request with multiple headers").
154
- with(method: :get, path: '/something', headers: {'X-Something' => "1, 2"}).
155
- will_respond_with(status: 200)
156
-
157
- uri = URI('http://localhost:1240/something')
158
- post_req = Net::HTTP::Get.new(uri.path)
159
- post_req.add_field('X-Something', '1')
160
- post_req.add_field('X-Something', '2')
161
- response = Net::HTTP.start(uri.hostname, uri.port) do |http|
162
- http.request post_req
163
- end
164
- end
165
-
166
- it "handles multiple headers with the same name in a comma separated list" do
167
- interactions = Pact::ConsumerContract.from_json(multi_headers_service.write_pact).interactions
168
- expect(interactions.first.request.headers['X-Something']).to eq("1, 2")
169
- end
170
-
171
- end
172
-
173
- context "with a async interaction with provider" do
174
- before do
175
- Pact.clear_configuration
176
-
177
- Pact.service_consumer "Consumer" do
178
- has_pact_with "Zebra Service" do
179
- mock_service :zebra_service do
180
- verify true
181
- port 1239
182
- end
183
- end
184
- end
185
- end
186
-
187
- it "goes like this" do
188
- zebra_service.
189
- given(:the_zebras_are_here).
190
- upon_receiving("a retrieve Mallory request").
191
- with({
192
- method: :get,
193
- path: '/mallory'
194
- }).
195
- will_respond_with({status: 200})
196
-
197
- async_interaction { Net::HTTP.get_response(URI('http://localhost:1239/mallory'))}
198
-
199
- zebra_service.wait_for_interactions wait_max_seconds: 1, poll_interval: 0.1
200
- end
201
-
202
- def async_interaction
203
- Thread.new do
204
- sleep 0.2
205
- yield
206
- end
207
- end
208
-
209
- end
210
-
211
- end
212
-