diff --git a/lib/pact_broker/pacts/selector.rb b/lib/pact_broker/pacts/selector.rb index bee494ef7..3a22f89b9 100644 --- a/lib/pact_broker/pacts/selector.rb +++ b/lib/pact_broker/pacts/selector.rb @@ -33,10 +33,15 @@ def self.latest_for_tag(tag) Selector.new(latest: true, tag: tag) end + def self.latest_for_tag_with_fallback(tag, fallback_tag) + Selector.new(latest: true, tag: tag, fallback_tag: fallback_tag) + end + def self.all_for_tag(tag) Selector.new(tag: tag) end + def self.from_hash hash Selector.new(hash) end diff --git a/lib/pact_broker/pacts/verifiable_pact_messages.rb b/lib/pact_broker/pacts/verifiable_pact_messages.rb index b281f6971..c1dbf94c7 100644 --- a/lib/pact_broker/pacts/verifiable_pact_messages.rb +++ b/lib/pact_broker/pacts/verifiable_pact_messages.rb @@ -129,7 +129,11 @@ def selector_description selector if selector.overall_latest? "latest pact between a consumer and #{provider_name}" elsif selector.latest_for_tag? - "latest pact for a consumer version tagged '#{selector.tag}'" + if selector.fallback_tag? + "latest pact for a consumer version tagged '#{selector.fallback_tag}' (fallback tag used as no pact was found with tag '#{selector.tag}')" + else + "latest pact for a consumer version tagged '#{selector.tag}'" + end elsif selector.tag "pacts for all consumer versions tagged '#{selector.tag}'" else diff --git a/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb b/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb index 160d7e782..6fdd08dce 100644 --- a/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +++ b/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb @@ -48,6 +48,10 @@ module Pacts its(:inclusion_reason) { is_expected.to include " (all have the same content)" } end + context "when the pact was selected by the fallback tag" do + let(:selectors) { Selectors.new(Selector.latest_for_tag_with_fallback("feat-x", "master")) } + its(:inclusion_reason) { is_expected.to include "latest pact for a consumer version tagged 'master' (fallback tag used as no pact was found with tag 'feat-x')" } + end context "when the pact is a WIP pact" do let(:selectors) { Selectors.create_for_latest_of_each_tag(%w[feat-x]) }