Skip to content

Commit

Permalink
fix(pact-stub-service): ensure all interactions loaded when loading m…
Browse files Browse the repository at this point in the history
…ultiple pacts

Closes: pact-foundation#83
  • Loading branch information
bethesque committed Dec 18, 2017
1 parent 12cf471 commit 4c0d698
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/pact/mock_service/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def shutdown
end

def setup_stub stub_pactfile_paths
stub_pactfile_paths.each do | pactfile_path |
interactions = stub_pactfile_paths.collect do | pactfile_path |
$stdout.puts "INFO: Loading interactions from #{pactfile_path}"
hash_interactions = JSON.parse(File.read(pactfile_path))['interactions']
interactions = hash_interactions.collect { | hash | Interaction.from_hash(hash) }
@session.set_expected_interactions interactions
end
hash_interactions.collect { | hash | Interaction.from_hash(hash) }
end.flatten
@session.set_expected_interactions interactions
end

def write_pact_if_configured
Expand Down
29 changes: 29 additions & 0 deletions spec/integration/stub_cli_with_multiple_pacts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'support/integration_spec_support'

describe "The pact-stub-service command line interface with multiple pacts", mri_only: true do

include Pact::IntegrationTestSupport

PORT = 5556

before :all do
clear_dirs
@pid = start_stub_server PORT, "spec/support/pact-for-stub-1.json spec/support/pact-for-stub-2.json"
end

it "includes the interactions from the first pact file" do
response = Faraday.get "http://localhost:#{PORT}/path1"
puts response.body if response.status != 200
expect(response.status).to eq 200
end

it "includes the interactions from the second pact file" do
response = Faraday.get "http://localhost:#{PORT}/path2"
puts response.body if response.status != 200
expect(response.status).to eq 200
end

after :all do
kill_server @pid
end
end
26 changes: 26 additions & 0 deletions spec/support/pact-for-stub-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"provider": {
"name": "a provider"
},
"consumer": {
"name": "a consumer"
},
"interactions": [
{
"description": "request one",
"request": {
"method": "get",
"path": "/path1"
},
"response": {
"status": 200
},
"providerState": "state one"
}
],
"metadata": {
"pactSpecification": {
"version": "2.0"
}
}
}
26 changes: 26 additions & 0 deletions spec/support/pact-for-stub-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"provider": {
"name": "a provider"
},
"consumer": {
"name": "a consumer"
},
"interactions": [
{
"description": "request two",
"request": {
"method": "get",
"path": "/path2"
},
"response": {
"status": 200
},
"providerState": "state two"
}
],
"metadata": {
"pactSpecification": {
"version": "2.0"
}
}
}

0 comments on commit 4c0d698

Please sign in to comment.