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, #potential_duplicate_pacticipant_message, #validation_message

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 is still in pending state). #{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



72
73
74
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 72

def pact_version_short_description
  short_selector_descriptions
end

#pending_reasonObject



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

def pending_reason
  if 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



62
63
64
65
66
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 62

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



68
69
70
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 68

def verification_success_false_published_true
  verification_success_false_published_false
end

#verification_success_true_published_falseObject



50
51
52
53
54
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 50

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



56
57
58
59
60
# File 'lib/pact_broker/pacts/verifiable_pact_messages.rb', line 56

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