From 0b4bc7e44b5b0e759eebd1e712fd221fd680a7f2 Mon Sep 17 00:00:00 2001 From: bangn Date: Tue, 26 Jul 2022 23:04:25 +1000 Subject: [PATCH] fix: Return non-error if enable-pending is set --- .../set_up_provider_state.rb | 8 ++++++-- .../set_up_provider_state_spec.rb | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/pact/provider_verifier/set_up_provider_state.rb b/lib/pact/provider_verifier/set_up_provider_state.rb index 04e614b..7d8f6c8 100644 --- a/lib/pact/provider_verifier/set_up_provider_state.rb +++ b/lib/pact/provider_verifier/set_up_provider_state.rb @@ -91,11 +91,15 @@ def add_custom_provider_header request end def check_for_error response - if response.status >= 300 - raise SetUpProviderStateError.new("Error setting up provider state '#{provider_state}' for consumer '#{consumer}' at #{provider_states_setup_url}. response status=#{response.status} response body=#{response.body}") + if response.status >= 300 && !(@options[:enable_pending] == true) + raise SetUpProviderStateError.new(set_up_provider_state_error_message(response)) end end + def set_up_provider_state_error_message(response) + "Error setting up provider state '#{provider_state}' for consumer '#{consumer}' at #{provider_states_setup_url}. response status=#{response.status} response body=#{response.body}" + end + def log_request if verbose? $stdout.puts "DEBUG: Setting up provider state '#{provider_state}' for consumer '#{consumer}' using provider state set up URL #{provider_states_setup_url}" diff --git a/spec/lib/pact/provider_verifier/set_up_provider_state_spec.rb b/spec/lib/pact/provider_verifier/set_up_provider_state_spec.rb index 4efea0c..33652fb 100644 --- a/spec/lib/pact/provider_verifier/set_up_provider_state_spec.rb +++ b/spec/lib/pact/provider_verifier/set_up_provider_state_spec.rb @@ -31,8 +31,23 @@ module ProviderVerifier stub_request(:post, provider_states_setup_url).to_return(status: 500, body: "Some error") end - it "raises an error" do - expect { subject }.to raise_error(SetUpProviderStateError, /500.*Some error/) + context "when enable_pending is not set" do + it "raises an error" do + expect { subject }.to raise_error(SetUpProviderStateError, /500.*Some error/) + end + end + + context "when enable_pending is set" do + let(:options) do + { + params: params, + enable_pending: true, + } + end + + it "does not raise an error" do + expect { subject }.not_to raise_error + end end end