Skip to content

Commit

Permalink
feat: give each interaction an index when parsing the contract
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 23, 2020
1 parent f1a1959 commit 74e9568
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def call(hash)
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."
end

interactions = hash[:interactions].collect { |hash| Interaction.from_hash(hash, options) }
interactions = hash[:interactions].each_with_index.collect { |hash, index| Interaction.from_hash({ index: index }.merge(hash), options) }
ConsumerContract.new(
:consumer => ServiceConsumer.from_hash(hash[:consumer]),
:provider => ServiceProvider.from_hash(hash[:provider]),
Expand Down
3 changes: 2 additions & 1 deletion lib/pact/consumer_contract/interaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Pact
class Interaction
include ActiveSupportSupport

attr_accessor :description, :request, :response, :provider_state, :provider_states, :metadata, :_id
attr_accessor :description, :request, :response, :provider_state, :provider_states, :metadata, :_id, :index

def initialize attributes = {}
@description = attributes[:description]
Expand All @@ -15,6 +15,7 @@ def initialize attributes = {}
@provider_states = attributes[:provider_states]
@metadata = attributes[:metadata]
@_id = attributes[:_id]
@index = attributes[:index]
end

def self.from_hash hash, options = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module Pact
it "correctly parses the pact" do
expect(subject.interactions.first.response.headers['Content-Type']).to be_a(Pact::Term)
end

it "sets the index of each interaction" do
expect(subject.interactions.first.index).to eq 0
end
end

context "with a v3 pact" do
Expand All @@ -19,6 +23,10 @@ module Pact
it "correctly parses the pact" do
expect(subject.interactions.first.response.body['foo']).to be_a(Pact::SomethingLike)
end

it "sets the index of each interaction" do
expect(subject.interactions.first.index).to eq 0
end
end
end
end
Expand Down

0 comments on commit 74e9568

Please sign in to comment.