Sha256: 4a8f1f5709bfb5ac0928ebb271867442c0fd1e31740aafc4399796e8df0d6dee

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module Pacto
  class Contract
    attr_reader :name, :values, :request, :response, :file, :request_pattern

    def initialize(request, response, file, name = nil, request_pattern_provider = RequestPattern)
      @request = request
      @response = response
      @file = Addressable::URI.convert_path(file.to_s).to_s
      @name = name || @file
      @request_pattern = request_pattern_provider.for(request)
      @values = {}
    end

    def stub_contract!(values = {})
      @values = values
      Pacto.configuration.provider.stub_request!(request, response)
    end

    def validate_provider(opts = {})
      request = @request
      response = provider_response
      validate_consumer request, response, opts
    end

    def validate_consumer(request, response, opts = {})
      Pacto::ContractValidator.validate self, request, response, opts
    end

    def matches?(request_signature)
      request_pattern.matches? request_signature
    end

    private

    def provider_response
      @request.execute
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pacto-0.3.1 lib/pacto/contract.rb