pact-support 1.7.2 → 1.8.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/pact/consumer_contract/interaction.rb +13 -7
- data/lib/pact/consumer_contract/interaction_v2_parser.rb +7 -1
- data/lib/pact/consumer_contract/interaction_v3_parser.rb +13 -1
- data/lib/pact/consumer_contract/provider_state.rb +34 -0
- data/lib/pact/consumer_contract/query.rb +0 -2
- data/lib/pact/consumer_contract/query_hash.rb +4 -0
- data/lib/pact/support/version.rb +1 -1
- data/spec/lib/pact/consumer_contract/interaction_spec.rb +2 -3
- data/spec/lib/pact/consumer_contract/interaction_v2_parser_spec.rb +54 -0
- data/spec/lib/pact/consumer_contract/interaction_v3_parser_spec.rb +48 -0
- data/spec/support/factories.rb +5 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e798766a40ccdcb43c8aed0bfbb4ee222c266db
|
4
|
+
data.tar.gz: fb9ab7ab4bac90b552b8c993ff582f035b5a9e00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d0363e0c4f19d960c4301cb96918d0eed195bd149eef1f4ce0ea4707c7629abf24a7c496e1918fb73f7b806bfea730e5a28397b972ea69a947e332bd2cd7cff
|
7
|
+
data.tar.gz: 0ec07b703a4abe989d0507d2f91f0aa96a76b16142e2115abca1ca355d1b0e4333e733c9d0f9142c33674116995a907ca58781d0b07ba970625253a4eebe1df6
|
data/CHANGELOG.md
CHANGED
@@ -5,13 +5,14 @@ module Pact
|
|
5
5
|
class Interaction
|
6
6
|
include ActiveSupportSupport
|
7
7
|
|
8
|
-
attr_accessor :description, :request, :response, :provider_state
|
8
|
+
attr_accessor :description, :request, :response, :provider_state, :provider_states
|
9
9
|
|
10
10
|
def initialize attributes = {}
|
11
11
|
@description = attributes[:description]
|
12
12
|
@request = attributes[:request]
|
13
13
|
@response = attributes[:response]
|
14
14
|
@provider_state = attributes[:provider_state] || attributes[:providerState]
|
15
|
+
@provider_states = attributes[:provider_states]
|
15
16
|
end
|
16
17
|
|
17
18
|
def self.from_hash hash, options = {}
|
@@ -19,12 +20,17 @@ module Pact
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def to_hash
|
22
|
-
{
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
h = { description: description }
|
24
|
+
|
25
|
+
if provider_states
|
26
|
+
h[:provider_states] = provider_states.collect(&:to_hash)
|
27
|
+
else
|
28
|
+
h[:provider_state] = provider_state
|
29
|
+
end
|
30
|
+
|
31
|
+
h[:request] = request.to_hash
|
32
|
+
h[:response] = response.to_hash
|
33
|
+
h
|
28
34
|
end
|
29
35
|
|
30
36
|
def http?
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'pact/consumer_contract/request'
|
2
2
|
require 'pact/consumer_contract/response'
|
3
|
+
require 'pact/consumer_contract/provider_state'
|
3
4
|
require 'pact/symbolize_keys'
|
4
5
|
require 'pact/matching_rules'
|
5
6
|
require 'pact/errors'
|
@@ -12,7 +13,8 @@ module Pact
|
|
12
13
|
def self.call hash, options
|
13
14
|
request = parse_request(hash['request'], options)
|
14
15
|
response = parse_response(hash['response'], options)
|
15
|
-
|
16
|
+
provider_states = parse_provider_states(hash['providerState'] || hash['provider_state'])
|
17
|
+
Interaction.new(symbolize_keys(hash).merge(request: request, response: response, provider_states: provider_states))
|
16
18
|
end
|
17
19
|
|
18
20
|
def self.parse_request request_hash, options
|
@@ -24,5 +26,9 @@ module Pact
|
|
24
26
|
response_hash = Pact::MatchingRules.merge(response_hash, response_hash['matchingRules'], options)
|
25
27
|
Pact::Response.from_hash(response_hash)
|
26
28
|
end
|
29
|
+
|
30
|
+
def self.parse_provider_states provider_state_name
|
31
|
+
provider_state_name ? [Pact::ProviderState.new(provider_state_name)] : []
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'pact/consumer_contract/request'
|
2
2
|
require 'pact/consumer_contract/response'
|
3
|
+
require 'pact/consumer_contract/provider_state'
|
3
4
|
require 'pact/symbolize_keys'
|
4
5
|
require 'pact/matching_rules'
|
5
6
|
require 'pact/errors'
|
@@ -13,7 +14,12 @@ module Pact
|
|
13
14
|
def self.call hash, options
|
14
15
|
request = parse_request(hash['request'], options)
|
15
16
|
response = parse_response(hash['response'], options)
|
16
|
-
|
17
|
+
provider_states = parse_provider_states(hash['providerStates'])
|
18
|
+
provider_state = provider_states.any? ? provider_states.first.name : nil
|
19
|
+
if provider_states && provider_states.size > 1
|
20
|
+
Pact.configuration.error_stream.puts("WARN: Currently only 1 provider state is supported. Ignoring ")
|
21
|
+
end
|
22
|
+
Interaction.new(symbolize_keys(hash).merge(request: request, response: response, provider_states: provider_states, provider_state: provider_state))
|
17
23
|
end
|
18
24
|
|
19
25
|
def self.parse_request request_hash, options
|
@@ -57,5 +63,11 @@ module Pact
|
|
57
63
|
string_with_matching_rules = StringWithMatchingRules.new(response_hash['body'], options[:pact_specification_version], response_matching_rules)
|
58
64
|
Pact::Response.from_hash(response_hash.merge('body' => string_with_matching_rules))
|
59
65
|
end
|
66
|
+
|
67
|
+
def self.parse_provider_states provider_states
|
68
|
+
(provider_states || []).collect do | provider_state_hash |
|
69
|
+
Pact::ProviderState.new(provider_state_hash['name'], provider_state_hash['params'])
|
70
|
+
end
|
71
|
+
end
|
60
72
|
end
|
61
73
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Pact
|
2
|
+
class ProviderState
|
3
|
+
|
4
|
+
attr_reader :name, :params
|
5
|
+
|
6
|
+
def initialize name, params = {}
|
7
|
+
@name = name
|
8
|
+
@params = params
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.from_hash(hash)
|
12
|
+
new(hash["name"], hash["params"])
|
13
|
+
end
|
14
|
+
|
15
|
+
def ==(other)
|
16
|
+
other.is_a?(Pact::ProviderState) && other.name == self.name && other.params == self.params
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_hash
|
20
|
+
{
|
21
|
+
"name" => name,
|
22
|
+
"params" => params
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_json(opts = {})
|
27
|
+
as_json(opts).to_json(opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
def as_json(opts = {})
|
31
|
+
to_hash
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/pact/support/version.rb
CHANGED
@@ -38,12 +38,14 @@ module Pact
|
|
38
38
|
|
39
39
|
describe "matches_criteria?" do
|
40
40
|
subject { InteractionFactory.create(:description => 'a request for food') }
|
41
|
+
|
41
42
|
context "by description" do
|
42
43
|
context "when the interaction matches" do
|
43
44
|
it "returns true" do
|
44
45
|
expect(subject.matches_criteria?(:description => /request.*food/)).to be true
|
45
46
|
end
|
46
47
|
end
|
48
|
+
|
47
49
|
context "when the interaction does not match" do
|
48
50
|
it "returns false" do
|
49
51
|
expect(subject.matches_criteria?(:description => /blah/)).to be false
|
@@ -52,10 +54,7 @@ module Pact
|
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
|
-
|
56
|
-
|
57
57
|
describe "request_modifies_resource_without_checking_response_body?" do
|
58
|
-
|
59
58
|
let(:interaction) { Interaction.new(request: request, response: response)}
|
60
59
|
|
61
60
|
subject { interaction.request_modifies_resource_without_checking_response_body?}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'pact/consumer_contract/interaction_v2_parser'
|
2
|
+
|
3
|
+
module Pact
|
4
|
+
describe InteractionV2Parser do
|
5
|
+
describe ".call" do
|
6
|
+
let(:interaction_hash) do
|
7
|
+
{
|
8
|
+
"description" => "description",
|
9
|
+
"request" => { "method" => "GET", "path" => "/" },
|
10
|
+
"response" => { "status" => 200 },
|
11
|
+
"providerState" => "foo"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:options) do
|
16
|
+
{
|
17
|
+
pact_specification_version: Pact::SpecificationVersion.new("3.0")
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
subject { InteractionV2Parser.call(interaction_hash, options) }
|
22
|
+
|
23
|
+
describe "provider_states" do
|
24
|
+
it "returns an array of provider states with size 1" do
|
25
|
+
expect(subject.provider_states.size).to eq 1
|
26
|
+
end
|
27
|
+
|
28
|
+
it "sets the name of the provider state to the string provided" do
|
29
|
+
expect(subject.provider_states.first.name)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sets the params to an empty hash" do
|
33
|
+
expect(subject.provider_states.first.params).to eq({})
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when the providerState is nil" do
|
37
|
+
before do
|
38
|
+
interaction_hash["providerState"] = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns an empty list" do
|
42
|
+
expect(subject.provider_states).to be_empty
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "provider_state" do
|
48
|
+
it "sets the name from the hash" do
|
49
|
+
expect(subject.provider_state).to eq "foo"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'pact/consumer_contract/interaction_v3_parser'
|
2
|
+
|
3
|
+
module Pact
|
4
|
+
describe InteractionV3Parser do
|
5
|
+
describe ".call" do
|
6
|
+
|
7
|
+
let(:interaction_hash) do
|
8
|
+
{
|
9
|
+
"description" => "description",
|
10
|
+
"request" => { "method" => "GET", "path" => "/" },
|
11
|
+
"response" => { "status" => 200 },
|
12
|
+
"providerStates" => [{
|
13
|
+
"name" => "foo",
|
14
|
+
"params" => {"a" => "b"}
|
15
|
+
}]
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:options) do
|
20
|
+
{
|
21
|
+
pact_specification_version: Pact::SpecificationVersion.new("3.0")
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
subject { InteractionV3Parser.call(interaction_hash, options) }
|
26
|
+
|
27
|
+
describe "provider_states" do
|
28
|
+
it "parses the array of provider states" do
|
29
|
+
expect(subject.provider_states.size).to eq 1
|
30
|
+
end
|
31
|
+
|
32
|
+
it "parses the name of each" do
|
33
|
+
expect(subject.provider_states.first.name)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "parses the params of each" do
|
37
|
+
expect(subject.provider_states.first.params).to eq "a" => "b"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "provider_state" do
|
42
|
+
it "sets the provider_state string to the name of the first providerState for backwards compatibility while we implement v3" do
|
43
|
+
expect(subject.provider_state).to eq "foo"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/support/factories.rb
CHANGED
@@ -40,6 +40,11 @@ class InteractionFactory
|
|
40
40
|
'body' => {a: 'response body'}
|
41
41
|
}
|
42
42
|
}
|
43
|
+
|
44
|
+
if hash.key?(:provider_states) || hash.key?('provider_states')
|
45
|
+
defaults.delete('provider_state')
|
46
|
+
end
|
47
|
+
|
43
48
|
Pact::Interaction.from_hash(stringify_keys(deep_merge(defaults, stringify_keys(hash))))
|
44
49
|
end
|
45
50
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Fraser
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2018-
|
15
|
+
date: 2018-10-03 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: randexp
|
@@ -274,6 +274,7 @@ files:
|
|
274
274
|
- lib/pact/consumer_contract/interaction_v2_parser.rb
|
275
275
|
- lib/pact/consumer_contract/interaction_v3_parser.rb
|
276
276
|
- lib/pact/consumer_contract/pact_file.rb
|
277
|
+
- lib/pact/consumer_contract/provider_state.rb
|
277
278
|
- lib/pact/consumer_contract/query.rb
|
278
279
|
- lib/pact/consumer_contract/query_hash.rb
|
279
280
|
- lib/pact/consumer_contract/query_string.rb
|
@@ -348,6 +349,8 @@ files:
|
|
348
349
|
- spec/lib/pact/consumer_contract/http_consumer_contract_parser_spec.rb
|
349
350
|
- spec/lib/pact/consumer_contract/interaction_parser_spec.rb
|
350
351
|
- spec/lib/pact/consumer_contract/interaction_spec.rb
|
352
|
+
- spec/lib/pact/consumer_contract/interaction_v2_parser_spec.rb
|
353
|
+
- spec/lib/pact/consumer_contract/interaction_v3_parser_spec.rb
|
351
354
|
- spec/lib/pact/consumer_contract/pact_file_spec.rb
|
352
355
|
- spec/lib/pact/consumer_contract/query_hash_spec.rb
|
353
356
|
- spec/lib/pact/consumer_contract/query_string_spec.rb
|
@@ -456,6 +459,8 @@ test_files:
|
|
456
459
|
- spec/lib/pact/consumer_contract/http_consumer_contract_parser_spec.rb
|
457
460
|
- spec/lib/pact/consumer_contract/interaction_parser_spec.rb
|
458
461
|
- spec/lib/pact/consumer_contract/interaction_spec.rb
|
462
|
+
- spec/lib/pact/consumer_contract/interaction_v2_parser_spec.rb
|
463
|
+
- spec/lib/pact/consumer_contract/interaction_v3_parser_spec.rb
|
459
464
|
- spec/lib/pact/consumer_contract/pact_file_spec.rb
|
460
465
|
- spec/lib/pact/consumer_contract/query_hash_spec.rb
|
461
466
|
- spec/lib/pact/consumer_contract/query_string_spec.rb
|