Class: PactBroker::Pacts::VerifiablePactMessages

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Messages
Defined in:
lib/pact_broker/pacts/verifiable_pact_messages.rb

Constant Summary collapse

READ_MORE_PENDING =
"Read more at https://docs.pact.io/go/pending"
READ_MORE_WIP =
"Read more at https://docs.pact.io/go/wip"

Instance Method Summary collapse

Methods included from Messages

#message, #pluralize, #validation_message, #validation_message_at_index

Constructor Details

#initialize(verifiable_pact, pact_version_url) ⇒ VerifiablePactMessages

Returns a new instance of VerifiablePactMessages.



15
16
17
18
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 15

def initialize(verifiable_pact, pact_version_url)
  @verifiable_pact = verifiable_pact
  @pact_version_url = pact_version_url
end

Instance Method Details

#inclusion_reasonObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 30

def inclusion_reason
  version_text = head_consumer_tags.size == 1 || branches.size == 1 ? "version" : "versions"
  if wip?
    # WIP pacts will always have tags, because it is part of the definition of being a WIP pact
    "The pact at #{pact_version_url} is being verified because it is a 'work in progress' pact (ie. it is the pact for the latest #{version_text} of #{consumer_name} #{joined_head_consumer_tags_and_branches} and it has not yet been successfully verified by #{pending_provider_branch_or_tags_description("a")} when the pact's application version was explicitly specified in the consumer version selectors). #{READ_MORE_WIP}"
  else
    criteria_or_criterion = selectors.size > 1 ? "criteria" : "criterion"
    version_or_versions = pluralize("the consumer version", selectors.size)
    "The pact at #{pact_version_url} is being verified because the pact content belongs to #{version_or_versions} matching the following #{criteria_or_criterion}:\n#{selector_descriptions}"
  end
end

#pact_descriptionObject



20
21
22
23
24
25
26
27
28
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 20

def pact_description
  position_descs = if head_consumer_tags.empty? && branches.empty?
                     ["latest"]
                   else
                     head_consumer_tags.collect { |tag| "latest with tag #{tag}" } + branches.collect{ |branch| "latest from branch #{branch}" }
                   end

  "Pact between #{consumer_name} and #{provider_name}, consumer version #{consumer_version_number}, #{position_descs.join(", ")}"
end

#pact_version_short_descriptionObject



74
75
76
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 74

def pact_version_short_description
  short_selector_descriptions
end

#pending_reasonObject



42
43
44
45
46
47
48
49
50
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 42

def pending_reason
  if pending? && wip?
    "This pact is in pending state for this version of #{provider_name} because it was included as a 'work in progress' pact. If this verification fails, it will not cause the overall build to fail. #{READ_MORE_PENDING}"
  elsif pending?
    "This pact is in pending state for this version of #{provider_name} because a successful verification result for #{pending_provider_branch_or_tags_description("a")} has not yet been published. If this verification fails, it will not cause the overall build to fail. #{READ_MORE_PENDING}"
  else
    "This pact has previously been successfully verified by #{non_pending_provider_branch_or_tags_description}. If this verification fails, it will fail the build. #{READ_MORE_PENDING}"
  end
end

#verification_success_false_published_falseObject



64
65
66
67
68
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 64

def verification_success_false_published_false
  if pending?
    "This pact is still in pending state for #{pending_provider_branch_or_tags_description} as a successful verification result #{with_these_tags}has not yet been published"
  end
end

#verification_success_false_published_trueObject



70
71
72
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 70

def verification_success_false_published_true
  verification_success_false_published_false
end

#verification_success_true_published_falseObject



52
53
54
55
56
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 52

def verification_success_true_published_false
  if pending?
    "This pact is still in pending state for #{pending_provider_branch_or_tags_description} as the successful verification results #{with_these_tags}have not yet been published."
  end
end

#verification_success_true_published_trueObject



58
59
60
61
62
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 58

def verification_success_true_published_true
  if pending?
    "This pact is no longer in pending state for #{pending_provider_branch_or_tags_description}, as a successful verification result #{with_these_tags}has been published. If a verification for a version of #{provider_name} #{with_these_tags}fails in the future, it will fail the build. #{READ_MORE_PENDING}"
  end
end