diff --git a/lib/pact/provider_verifier/app.rb b/lib/pact/provider_verifier/app.rb index b048bb3..6c3514d 100644 --- a/lib/pact/provider_verifier/app.rb +++ b/lib/pact/provider_verifier/app.rb @@ -40,7 +40,6 @@ def call def setup print_deprecation_note set_environment_variables - configure_service_provider require_pact_project_pact_helper # Beth: not sure if this is needed, hangover from pact-provider-proxy? end @@ -106,12 +105,24 @@ def verify_pact pact_url verify_options[:description] = ENV['PACT_DESCRIPTION'] if ENV['PACT_DESCRIPTION'] verify_options[:provider_state] = ENV['PACT_PROVIDER_STATE'] if ENV['PACT_PROVIDER_STATE'] + reset_pact_configuration + # Really, this should call the PactSpecRunner directly, rather than using the CLI class. Cli::RunPactVerification.call(verify_options) rescue SystemExit => e e.status end end + def reset_pact_configuration + require 'pact/configuration' + require 'pact/consumer/world' + require 'pact/provider/world' + Pact.clear_configuration + Pact.clear_consumer_world + Pact.clear_provider_world + configure_service_provider + end + def require_pact_project_pact_helper require ENV['PACT_PROJECT_PACT_HELPER'] if ENV.fetch('PACT_PROJECT_PACT_HELPER','') != '' end diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index ed69f38..55edcd5 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -47,6 +47,21 @@ end end + context "when there are multiple pacts to verify with --format json" do + subject { `bundle exec bin/pact-provider-verifier ./test/me-they.json ./test/me-they.json --format json -a 1.0.100 --provider-base-url http://localhost:4567 --provider-states-setup-url http://localhost:4567/provider-state` } + + it "sends the results of both pacts to stdout" do + expect(subject).to include "}{" + expect(subject.scan(/\d examples, \d failure/).count).to eq 2 + end + + it "allows the results to be split and parsed to JSON" do + result_1, result_2 = subject.split("}{", 2) + JSON.parse(result_1 + "}") + JSON.parse("{" + result_2) + end + end + context "when there is an error setting up the state" do subject { `bundle exec bin/pact-provider-verifier ./test/me-they.json -a 1.0.100 --provider-base-url http://localhost:4567 --provider-states-setup-url http://localhost:4567/wrong -v` }