Skip to content

Commit

Permalink
feat(pacts for verification): update inclusion reason to support fall…
Browse files Browse the repository at this point in the history
…back tag explanation
  • Loading branch information
bethesque committed Feb 6, 2020
1 parent 113180c commit 4308117
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/pact_broker/pacts/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/pact_broker/pacts/verifiable_pact_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]) }
Expand Down

0 comments on commit 4308117

Please sign in to comment.