Skip to content

Commit 1b960bf

Browse files
committed
fix: parse expected interactions with configured pact specification version
1 parent 9c20eda commit 1b960bf

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

lib/pact/mock_service/request_handlers.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def initialize name, logger, session, options
2727
SessionDelete.new(name, logger, session),
2828
MissingInteractionsGet.new(name, logger, session),
2929
VerificationGet.new(name, logger, session),
30-
InteractionPost.new(name, logger, session),
31-
InteractionsPut.new(name, logger, session),
30+
InteractionPost.new(name, logger, session, Pact::SpecificationVersion.new(options[:pact_specification_version])),
31+
InteractionsPut.new(name, logger, session, Pact::SpecificationVersion.new(options[:pact_specification_version])),
3232
InteractionDelete.new(name, logger, session),
3333
LogGet.new(name, logger),
3434
PactPost.new(name, logger, session),

lib/pact/mock_service/request_handlers/interaction_post.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ module MockService
66
module RequestHandlers
77
class InteractionPost < BaseAdministrationRequestHandler
88

9-
def initialize name, logger, session
9+
def initialize name, logger, session, pact_specification_version
1010
super name, logger
1111
@session = session
12+
@pact_specification_version = pact_specification_version
1213
end
1314

1415
def request_path
@@ -21,7 +22,8 @@ def request_method
2122

2223
def respond env
2324
request_body = env['rack.input'].string
24-
interaction = Interaction.from_hash(JSON.load(request_body)) # Load creates the Pact::XXX classes
25+
parsing_options = { pact_specification_version: pact_specification_version }
26+
interaction = Interaction.from_hash(JSON.load(request_body), parsing_options) # Load creates the Pact::XXX classes
2527

2628
begin
2729
session.add_expected_interaction interaction
@@ -34,7 +36,7 @@ def respond env
3436

3537
private
3638

37-
attr_accessor :session
39+
attr_accessor :session, :pact_specification_version
3840
end
3941
end
4042
end

lib/pact/mock_service/request_handlers/interactions_put.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ module MockService
88
module RequestHandlers
99
class InteractionsPut < BaseAdministrationRequestHandler
1010

11-
def initialize name, logger, session
11+
def initialize name, logger, session, pact_specification_version
1212
super name, logger
1313
@session = session
14+
@pact_specification_version = pact_specification_version
1415
end
1516

1617
def request_path
@@ -23,7 +24,8 @@ def request_method
2324

2425
def respond env
2526
request_body = JSON.load(env['rack.input'].string)
26-
interactions = request_body['interactions'].collect { | hash | Interaction.from_hash(hash) }
27+
parsing_options = { pact_specification_version: pact_specification_version }
28+
interactions = request_body['interactions'].collect { | hash | Interaction.from_hash(hash, parsing_options) }
2729
begin
2830
session.set_expected_interactions interactions
2931
text_response('Registered interactions')
@@ -34,7 +36,7 @@ def respond env
3436

3537
private
3638

37-
attr_accessor :session
39+
attr_accessor :session, :pact_specification_version
3840

3941
end
4042
end

spec/lib/pact/mock_service/request_handlers/interaction_post_spec.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module RequestHandlers
66
describe InteractionPost do
77
let(:session) { instance_double('Pact::MockService::Session') }
88
let(:logger) { double('Logger').as_null_object }
9+
let(:pact_specification_version) { Pact::SpecificationVersion.new("2") }
910
let(:interaction_json) {
1011
{
1112
description: "some description",
@@ -21,7 +22,7 @@ module RequestHandlers
2122
}
2223
end
2324

24-
subject { described_class.new '', logger, session }
25+
subject { described_class.new '', logger, session, pact_specification_version }
2526

2627
context "adding the interaction will raise SameSameButDifferentError" do
2728
let(:message) { "my message" }

0 commit comments

Comments
 (0)