class PactBroker::Api::Decorators::ReasonDecorator

Attributes

ignored[R]
reason[R]

Public Class Methods

new(reason) click to toggle source
# File lib/pact_broker/api/decorators/reason_decorator.rb, line 7
def initialize(reason)
  if reason.is_a?(PactBroker::Matrix::IgnoredReason)
    @reason = reason.root_reason
    @ignored = true
  else
    @reason = reason
    @ignored = false
  end
end

Public Instance Methods

to_s() click to toggle source
# File lib/pact_broker/api/decorators/reason_decorator.rb, line 17
def to_s
  (ignored ? "Ignoring: " : "") + reason_text
end

Private Instance Methods

interaction_description(interaction) click to toggle source

TODO move this somewhere else

# File lib/pact_broker/api/decorators/reason_decorator.rb, line 57
def interaction_description(interaction)
  if interaction["providerState"] && interaction["providerState"] != ""
    "#{interaction['description']} given #{interaction['providerState']}"
  elsif interaction["providerStates"] && interaction["providerStates"].is_a?(Array) && interaction["providerStates"].any?
    provider_states = interaction["providerStates"].collect{ |ps| ps["name"] }.compact.join(", ")
    "#{interaction['description']} given #{provider_states}"
  else
    interaction["description"]
  end
end
reason_text() click to toggle source

rubocop: disable Metrics/CyclomaticComplexity

# File lib/pact_broker/api/decorators/reason_decorator.rb, line 26
def reason_text
  case reason
  when PactBroker::Matrix::PactNotEverVerifiedByProvider
    "There is no verified pact between #{reason.consumer_selector.description} and #{reason.provider_selector.description}"
  when PactBroker::Matrix::PactNotVerifiedByRequiredProviderVersion
    "There is no verified pact between #{reason.consumer_selector.description} and #{reason.provider_selector.description}"
  when PactBroker::Matrix::SpecifiedVersionDoesNotExist
    reason.selector.version_does_not_exist_description
  when PactBroker::Matrix::VerificationFailed
    "The verification for the pact between #{reason.consumer_selector.description} and #{reason.provider_selector.description} failed"
  when PactBroker::Matrix::NoDependenciesMissing
    "There are no missing dependencies"
  when PactBroker::Matrix::Successful
    "All required verification results are published and successful"
  when PactBroker::Matrix::InteractionsMissingVerifications
    descriptions = reason.interactions.collect do | interaction |
      interaction_description(interaction)
    end.join("; ")
    "WARN: Although the verification was reported as successful, the results for #{reason.consumer_selector.description} and #{reason.provider_selector.description} may be missing tests for the following interactions: #{descriptions}"
  when PactBroker::Matrix::IgnoreSelectorDoesNotExist
    "WARN: Cannot ignore #{reason.selector.description}"
  when PactBroker::Matrix::SelectorWithoutPacticipantVersionNumberSpecified
    "WARN: It is recommended to specify the version number (rather than the tag or branch) of the pacticipant you wish to deploy to avoid race conditions. Without a version number, this result will not be reliable."
  when PactBroker::Matrix::NoEnvironmentSpecified
    "WARN: It is recommended to specify the environment into which you are deploying. Without the environment, this result will not be reliable."
  else
    reason
  end
end