-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: locate matching rules correctly for v3 pacts
- Loading branch information
Showing
8 changed files
with
204 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
require 'pact/matching_rules/extract' | ||
require 'pact/matching_rules/merge' | ||
require 'pact/matching_rules/v3/merge' | ||
|
||
module Pact | ||
module MatchingRules | ||
|
||
# @api public Used by pact-mock_service | ||
def self.extract object_graph | ||
def self.extract object_graph, options = {} | ||
Extract.(object_graph) | ||
end | ||
|
||
def self.merge object_graph, matching_rules | ||
Merge.(object_graph, matching_rules) | ||
def self.merge object_graph, matching_rules, options = {} | ||
case options[:pact_specification_version].segments.first | ||
when nil | ||
Pact.configuration.error_stream.puts "No pact specification version found, using v2 code to parse contract" | ||
Merge.(object_graph, matching_rules) | ||
when 1, 2 | ||
Merge.(object_graph, matching_rules) | ||
when 3 | ||
V3::Merge.(object_graph, matching_rules) | ||
else | ||
Pact.configuration.error_stream.puts "This code only knows how to parse v3 pacts, attempting to parse v#{options[:pact_specification_version]} pact using v3 code." | ||
V3::Merge.(object_graph, matching_rules) | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"consumer": { | ||
"name": "consumer" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "a test request", | ||
"providerState": "the weather is sunny", | ||
"request": { | ||
"method": "get", | ||
"path": "/foo" | ||
}, | ||
"response": { | ||
"body": { | ||
"foo": "bar" | ||
}, | ||
"matchingRules": { | ||
"body": { | ||
"$.foo": { | ||
"matchers": [{ "match": "type" }] | ||
} | ||
} | ||
}, | ||
"status": 200 | ||
} | ||
} | ||
], | ||
"provider": { | ||
"name": "provider" | ||
}, | ||
"metadata": { | ||
"pactSpecification": { | ||
"version": "3.0" | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
spec/lib/pact/consumer_contract/http_consumer_contract_parser_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'pact/consumer_contract/http_consumer_contract_parser' | ||
|
||
module Pact | ||
describe HttpConsumerContractParser do | ||
describe "#call integration test" do | ||
subject { HttpConsumerContractParser.new.call(pact_hash) } | ||
|
||
context "with a v3 pact" do | ||
let(:pact_hash) { load_json_fixture('pact-http-v3.json') } | ||
|
||
it "correctly parses the pact" do | ||
expect(subject.interactions.first.response.body['foo']).to be_a(Pact::SomethingLike) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
require 'pact/matching_rules' | ||
|
||
module Pact | ||
module MatchingRules | ||
describe ".merge" do | ||
before do | ||
allow(V3::Merge).to receive(:call) | ||
allow(Merge).to receive(:call) | ||
allow(Pact.configuration.error_stream).to receive(:puts) | ||
end | ||
|
||
let(:object) { double('object') } | ||
let(:rules) { double('rules') } | ||
let(:options) { { pact_specification_version: Gem::Version.new(pact_specification_version) } } | ||
|
||
subject { MatchingRules.merge(object, rules, options)} | ||
|
||
context "when the pact_specification_version is nil" do | ||
let(:pact_specification_version) { nil } | ||
|
||
it "prints a warning" do | ||
expect(Pact.configuration.error_stream).to receive(:puts).with(/No pact specification version found/) | ||
subject | ||
end | ||
|
||
it "calls Merge" do | ||
expect(Merge).to receive(:call) | ||
subject | ||
end | ||
end | ||
|
||
context "when the pact_specification_version starts with '1.'" do | ||
let(:pact_specification_version) { "1.0" } | ||
|
||
it "calls Merge" do | ||
expect(Merge).to receive(:call) | ||
subject | ||
end | ||
end | ||
|
||
context "when the pact_specification_version is with '1'" do | ||
let(:pact_specification_version) { "1" } | ||
|
||
it "calls Merge" do | ||
expect(Merge).to receive(:call) | ||
subject | ||
end | ||
end | ||
|
||
context "when the pact_specification_version starts with '2.'" do | ||
let(:pact_specification_version) { "2.0" } | ||
|
||
it "calls Merge" do | ||
expect(Merge).to receive(:call) | ||
subject | ||
end | ||
end | ||
|
||
context "when the pact_specification_version starts with '3.'" do | ||
let(:pact_specification_version) { "3.0" } | ||
|
||
it "calls V3::Merge" do | ||
expect(V3::Merge).to receive(:call) | ||
subject | ||
end | ||
end | ||
|
||
context "when the pact_specification_version starts with '4.'" do | ||
let(:pact_specification_version) { "4.0" } | ||
|
||
it "prints a warning" do | ||
expect(Pact.configuration.error_stream).to receive(:puts).with(/only knows how to parse v3 pacts/) | ||
subject | ||
end | ||
|
||
it "calls V3::Merge" do | ||
expect(V3::Merge).to receive(:call) | ||
subject | ||
end | ||
end | ||
|
||
context "when the pact_specification_version is with '11'" do | ||
let(:pact_specification_version) { "11" } | ||
|
||
it "prints a warning" do | ||
expect(Pact.configuration.error_stream).to receive(:puts).with(/only knows how to parse v3 pacts/) | ||
subject | ||
end | ||
|
||
it "calls V3::Merge" do | ||
expect(V3::Merge).to receive(:call) | ||
subject | ||
end | ||
end | ||
end | ||
end | ||
end |