class Pacto::Validation

Attributes

contract[R]
request[R]
response[R]
results[R]

Public Class Methods

new(request, response, contract) click to toggle source
# File lib/pacto/validation.rb, line 6
def initialize(request, response, contract)
  @request = request
  @response = response
  @contract = contract
  validate unless contract.nil?
end

Public Instance Methods

against_contract?(contract_pattern) click to toggle source
# File lib/pacto/validation.rb, line 17
def against_contract?(contract_pattern)
  unless @contract.nil?
    case contract_pattern
    when String
      @contract if @contract.file.eql? contract_pattern
    when Regexp
      @contract if @contract.file =~ contract_pattern
    end
  end
end
successful?() click to toggle source
# File lib/pacto/validation.rb, line 13
def successful?
  @results.nil? || @results.empty?
end
summary() click to toggle source
# File lib/pacto/validation.rb, line 38
def summary
  if @contract.nil?
    "Missing contract for services provided by #{@request.uri.host}"
  else
    status = successful? ? 'successful' : 'unsuccessful'
    "#{status} validation of #{@contract.name}"
  end
end
to_s() click to toggle source
# File lib/pacto/validation.rb, line 28
def to_s
  contract_name = @contract.nil? ? 'nil' : contract.name
  """
  Validation:
  \tRequest: #{@request}
  \tContract: #{contract_name}
  \tResults: \n\t\t#{@results.join "\n\t\t"}
  """
end

Private Instance Methods

validate() click to toggle source
# File lib/pacto/validation.rb, line 49
def validate
  logger.debug("Validating #{@request}, #{@response} against #{@contract}")
  @results = contract.validate_consumer(@request, @response)
end