Skip to content

Commit

Permalink
feat(cli): allow --format json to be used to output spec results in j…
Browse files Browse the repository at this point in the history
…son format to stdout
  • Loading branch information
bethesque committed Oct 27, 2017
1 parent 44f5b8c commit aa7359a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/pact/provider_verifier/add_header_middlware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def warn_about_header_replacement header_name, existing_value, new_value
if existing_value.nil?
$stderr.puts "WARN: Adding header '#{header_name}: #{new_value}' to replayed request. This header did not exist in the pact, and hence this test cannot confirm that the request will work in real life."
else
$stdout.puts "INFO: Replacing header '#{header_name}: #{existing_value}' with '#{header_name}: #{new_value}'"
# Don't mess up the json formatter by using stdout here
$stderr.puts "INFO: Replacing header '#{header_name}: #{existing_value}' with '#{header_name}: #{new_value}'"
end
end
end
Expand Down
11 changes: 6 additions & 5 deletions lib/pact/provider_verifier/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ def configure_custom_header_middlware rack_reverse_proxy
def verify_pact pact_url
begin
verify_options = {
:pact_helper => PROXY_PACT_HELPER,
:pact_uri => pact_url,
:backtrace => ENV['BACKTRACE'] == 'true',
:pact_broker_username => options.broker_username,
:pact_broker_password => options.broker_password
pact_helper: PROXY_PACT_HELPER,
pact_uri: pact_url,
backtrace: ENV['BACKTRACE'] == 'true',
pact_broker_username: options.broker_username,
pact_broker_password: options.broker_password,
format: options.format
}
verify_options[:description] = ENV['PACT_DESCRIPTION'] if ENV['PACT_DESCRIPTION']
verify_options[:provider_state] = ENV['PACT_PROVIDER_STATE'] if ENV['PACT_PROVIDER_STATE']
Expand Down
3 changes: 2 additions & 1 deletion lib/pact/provider_verifier/cli/verify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Verify < CustomThor
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password", :required => false
method_option :custom_provider_header, type: :array, banner: 'CUSTOM_PROVIDER_HEADER', desc: "Header to add to provider state set up and pact verification requests. eg 'Authorization: Basic cGFjdDpwYWN0'. May be specified multiple times.", :required => false
method_option :verbose, aliases: "-v", desc: "Verbose output", :required => false
method_option :provider_states_url, aliases: "-s", desc: "DEPRECATED", :required => false
method_option :provider_states_url, aliases: "-s", :required => false, hide: true
method_option :format, banner: "FORMATTER", aliases: "-f", desc: "RSpec formatter. Defaults to custom Pact formatter. [j]son may also be used."
method_option :pact_urls, aliases: "-u", desc: "DEPRECATED. Please provide as space separated arguments.", :required => false

def verify(*pact_urls)
Expand Down
2 changes: 1 addition & 1 deletion pact-provider-verifier.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
gem.license = 'MIT'

gem.add_runtime_dependency 'rspec', '~> 3.5'
gem.add_runtime_dependency 'pact', '~>1.13'
gem.add_runtime_dependency 'pact', '~>1.17'
gem.add_runtime_dependency 'faraday', '~> 0.9', '>= 0.9.0'
gem.add_runtime_dependency 'faraday_middleware', '~> 0.10'
gem.add_runtime_dependency 'json', '>1.8'
Expand Down
16 changes: 16 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'json'

describe "pact-provider-verifier" do
before(:all) do
@pipe = IO.popen("bundle exec rackup -p 4567 spec/support/config.ru")
Expand Down Expand Up @@ -72,6 +74,20 @@
end
end

context "running verification with filtered interactions" 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/provider-state --format j` }

it "exits with a 0 exit code" do
subject
expect($?).to eq 0
end

it "the output can be parsed to json" do
expect(JSON.parse(subject)['examples'].size).to be > 1
end
end


after(:all) do
Process.kill 'KILL', @pipe.pid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module ProviderVerifier

context "when the specified header already exists" do
it "notifies the user" do
expect($stdout).to receive(:puts).with(/INFO: Replacing header 'Foo-Bar: wiffle' with 'Foo-Bar: foo'/)
expect($stderr).to receive(:puts).with(/INFO: Replacing header 'Foo-Bar: wiffle' with 'Foo-Bar: foo'/)
middlware.call({'HTTP_FOO_BAR' => 'wiffle' })
end
end
Expand Down

0 comments on commit aa7359a

Please sign in to comment.