Skip to content

Commit 74e9568

Browse files
committed
feat: give each interaction an index when parsing the contract
1 parent f1a1959 commit 74e9568

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/pact/consumer_contract/http_consumer_contract_parser.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def call(hash)
1313
Pact.configuration.error_stream.puts "WARN: This code only knows how to parse v3 pacts, attempting to parse v#{options[:pact_specification_version]} pact using v3 code."
1414
end
1515

16-
interactions = hash[:interactions].collect { |hash| Interaction.from_hash(hash, options) }
16+
interactions = hash[:interactions].each_with_index.collect { |hash, index| Interaction.from_hash({ index: index }.merge(hash), options) }
1717
ConsumerContract.new(
1818
:consumer => ServiceConsumer.from_hash(hash[:consumer]),
1919
:provider => ServiceProvider.from_hash(hash[:provider]),

lib/pact/consumer_contract/interaction.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Pact
55
class Interaction
66
include ActiveSupportSupport
77

8-
attr_accessor :description, :request, :response, :provider_state, :provider_states, :metadata, :_id
8+
attr_accessor :description, :request, :response, :provider_state, :provider_states, :metadata, :_id, :index
99

1010
def initialize attributes = {}
1111
@description = attributes[:description]
@@ -15,6 +15,7 @@ def initialize attributes = {}
1515
@provider_states = attributes[:provider_states]
1616
@metadata = attributes[:metadata]
1717
@_id = attributes[:_id]
18+
@index = attributes[:index]
1819
end
1920

2021
def self.from_hash hash, options = {}

spec/lib/pact/consumer_contract/http_consumer_contract_parser_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ module Pact
1111
it "correctly parses the pact" do
1212
expect(subject.interactions.first.response.headers['Content-Type']).to be_a(Pact::Term)
1313
end
14+
15+
it "sets the index of each interaction" do
16+
expect(subject.interactions.first.index).to eq 0
17+
end
1418
end
1519

1620
context "with a v3 pact" do
@@ -19,6 +23,10 @@ module Pact
1923
it "correctly parses the pact" do
2024
expect(subject.interactions.first.response.body['foo']).to be_a(Pact::SomethingLike)
2125
end
26+
27+
it "sets the index of each interaction" do
28+
expect(subject.interactions.first.index).to eq 0
29+
end
2230
end
2331
end
2432
end

0 commit comments

Comments
 (0)