diff --git a/lib/pact/mock_service/app.rb b/lib/pact/mock_service/app.rb index 705763b..f590238 100644 --- a/lib/pact/mock_service/app.rb +++ b/lib/pact/mock_service/app.rb @@ -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 diff --git a/spec/integration/stub_cli_with_multiple_pacts_spec.rb b/spec/integration/stub_cli_with_multiple_pacts_spec.rb new file mode 100644 index 0000000..6588631 --- /dev/null +++ b/spec/integration/stub_cli_with_multiple_pacts_spec.rb @@ -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 diff --git a/spec/support/pact-for-stub-1.json b/spec/support/pact-for-stub-1.json new file mode 100644 index 0000000..578e2a0 --- /dev/null +++ b/spec/support/pact-for-stub-1.json @@ -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" + } + } +} diff --git a/spec/support/pact-for-stub-2.json b/spec/support/pact-for-stub-2.json new file mode 100644 index 0000000..c74a4af --- /dev/null +++ b/spec/support/pact-for-stub-2.json @@ -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" + } + } +}