Skip to content

Commit 4c0d698

Browse files
committed
fix(pact-stub-service): ensure all interactions loaded when loading multiple pacts
Closes: pact-foundation#83
1 parent 12cf471 commit 4c0d698

File tree

4 files changed

+85
-4
lines changed

4 files changed

+85
-4
lines changed

lib/pact/mock_service/app.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def shutdown
3838
end
3939

4040
def setup_stub stub_pactfile_paths
41-
stub_pactfile_paths.each do | pactfile_path |
41+
interactions = stub_pactfile_paths.collect do | pactfile_path |
4242
$stdout.puts "INFO: Loading interactions from #{pactfile_path}"
4343
hash_interactions = JSON.parse(File.read(pactfile_path))['interactions']
44-
interactions = hash_interactions.collect { | hash | Interaction.from_hash(hash) }
45-
@session.set_expected_interactions interactions
46-
end
44+
hash_interactions.collect { | hash | Interaction.from_hash(hash) }
45+
end.flatten
46+
@session.set_expected_interactions interactions
4747
end
4848

4949
def write_pact_if_configured
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'support/integration_spec_support'
2+
3+
describe "The pact-stub-service command line interface with multiple pacts", mri_only: true do
4+
5+
include Pact::IntegrationTestSupport
6+
7+
PORT = 5556
8+
9+
before :all do
10+
clear_dirs
11+
@pid = start_stub_server PORT, "spec/support/pact-for-stub-1.json spec/support/pact-for-stub-2.json"
12+
end
13+
14+
it "includes the interactions from the first pact file" do
15+
response = Faraday.get "http://localhost:#{PORT}/path1"
16+
puts response.body if response.status != 200
17+
expect(response.status).to eq 200
18+
end
19+
20+
it "includes the interactions from the second pact file" do
21+
response = Faraday.get "http://localhost:#{PORT}/path2"
22+
puts response.body if response.status != 200
23+
expect(response.status).to eq 200
24+
end
25+
26+
after :all do
27+
kill_server @pid
28+
end
29+
end

spec/support/pact-for-stub-1.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"provider": {
3+
"name": "a provider"
4+
},
5+
"consumer": {
6+
"name": "a consumer"
7+
},
8+
"interactions": [
9+
{
10+
"description": "request one",
11+
"request": {
12+
"method": "get",
13+
"path": "/path1"
14+
},
15+
"response": {
16+
"status": 200
17+
},
18+
"providerState": "state one"
19+
}
20+
],
21+
"metadata": {
22+
"pactSpecification": {
23+
"version": "2.0"
24+
}
25+
}
26+
}

spec/support/pact-for-stub-2.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"provider": {
3+
"name": "a provider"
4+
},
5+
"consumer": {
6+
"name": "a consumer"
7+
},
8+
"interactions": [
9+
{
10+
"description": "request two",
11+
"request": {
12+
"method": "get",
13+
"path": "/path2"
14+
},
15+
"response": {
16+
"status": 200
17+
},
18+
"providerState": "state two"
19+
}
20+
],
21+
"metadata": {
22+
"pactSpecification": {
23+
"version": "2.0"
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)