From 1d2330ccd02aad112bc004843f08918e22977fdb Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Tue, 6 Aug 2024 21:01:17 +0100 Subject: [PATCH] fix: handle case in no_pacts_found - undefined method empty? for nil --- lib/pact/pact_broker/fetch_pact_uris_for_verification.rb | 2 +- .../pact/pact_broker/fetch_pact_uris_for_verification_spec.rb | 4 ++-- .../configuration/pact_verification_from_broker_spec.rb | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb b/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb index 8c2bc3ee..42ac64b3 100644 --- a/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb +++ b/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb @@ -101,7 +101,7 @@ def log_message def handling_no_pacts_found pacts_found = yield - if pacts_found.empty? && options[:fail_if_no_pacts_found] != false + if pacts_found.blank? && options[:fail_if_no_pacts_found] != false raise "No pacts found to verify" else pacts_found diff --git a/spec/lib/pact/pact_broker/fetch_pact_uris_for_verification_spec.rb b/spec/lib/pact/pact_broker/fetch_pact_uris_for_verification_spec.rb index e0690663..c17800b2 100644 --- a/spec/lib/pact/pact_broker/fetch_pact_uris_for_verification_spec.rb +++ b/spec/lib/pact/pact_broker/fetch_pact_uris_for_verification_spec.rb @@ -14,7 +14,7 @@ module PactBroker let(:consumer_version_selectors) { [{ tag: "cmaster", latest: true, fallbackTag: 'blah' }] } let(:provider_version_branch) { "pbranch" } let(:provider_version_tags) { ["pmaster"] } - + subject { FetchPactURIsForVerification.call(provider, consumer_version_selectors, provider_version_branch, provider_version_tags, broker_base_url, http_client_options)} context "when there is an error retrieving the index resource" do @@ -62,7 +62,7 @@ module PactBroker it "calls the old fetch pacts code" do expect(FetchPacts).to receive(:call).with(provider, [{ name: "cmaster", all: false, fallback: "blah" }], broker_base_url, http_client_options) - subject + expect { subject }.to raise_error( "No pacts found to verify" ) end end end diff --git a/spec/lib/pact/provider/configuration/pact_verification_from_broker_spec.rb b/spec/lib/pact/provider/configuration/pact_verification_from_broker_spec.rb index 79c5c1ae..2bb838f8 100644 --- a/spec/lib/pact/provider/configuration/pact_verification_from_broker_spec.rb +++ b/spec/lib/pact/provider/configuration/pact_verification_from_broker_spec.rb @@ -37,7 +37,7 @@ module Configuration let(:fetch_pacts) { double('FetchPacts') } let(:basic_auth_opts) { basic_auth_options.merge(verbose: true) } - let(:options) { { include_pending_status: true, include_wip_pacts_since: "2020-01-01" }} + let(:options) { { fail_if_no_pacts_found: true, include_pending_status: true, include_wip_pacts_since: "2020-01-01" }} let(:consumer_version_selectors) { [ { tag: 'master', latest: true }] } it "creates a instance of Pact::PactBroker::FetchPactURIsForVerification" do @@ -70,6 +70,7 @@ module Configuration anything, anything, { + fail_if_no_pacts_found: true, include_pending_status: true, include_wip_pacts_since: since.xmlschema }