Skip to content

Commit

Permalink
fix: ensure all json results are sent to stdout when multiple pacts a…
Browse files Browse the repository at this point in the history
…re verified

Fixes: pact-foundation/pact-go#88
  • Loading branch information
bethesque committed Jul 10, 2018
1 parent 9ffc5d0 commit 7662df0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/pact/provider_verifier/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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` }
Expand Down

0 comments on commit 7662df0

Please sign in to comment.