Sha256: c9f1da7e302b783bf483d4cbbff9b1657d24db9a5e6d94db1731e33212b4ff56

Contents?: true

Size: 1.59 KB

Versions: 13

Compression:

Stored size: 1.59 KB

Contents

require 'pact/logging'
require 'rack/test'
require 'pact/consumer_contract/interaction'
require 'pact/provider/state/provider_state'
require 'pact/provider/state/provider_state_proxy'
require 'pact/provider/request'
require 'pact/provider/world'
require 'pact/provider/state/provider_state_manager'

module Pact
  module Provider
    module TestMethods

      include Pact::Logging
      include Rack::Test::Methods

      def replay_interaction interaction
        request = Request::Replayable.new(interaction.request)
        args = [request.path, request.body, request.headers]

        logger.info "Sending #{request.method.upcase} request to path: \"#{request.path}\" with headers: #{request.headers}, see debug logs for body"
        logger.debug "body :#{request.body}"
        response = self.send(request.method.downcase, *args)
        logger.info "Received response with status: #{response.status}, headers: #{response.headers}, see debug logs for body"
        logger.debug "body: #{response.body}"
      end

      def parse_body_from_response rack_response
        case rack_response.headers['Content-Type']
        when /json/
          JSON.load(rack_response.body)
        else
          rack_response.body
        end
      end

      def set_up_provider_state provider_state_name, consumer, options = {}
        Pact.configuration.provider_state_set_up.call(provider_state_name, consumer, options)
      end

      def tear_down_provider_state provider_state_name, consumer, options = {}
        Pact.configuration.provider_state_tear_down.call(provider_state_name, consumer, options)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
pact-1.21.0 lib/pact/provider/test_methods.rb
pact-1.20.1 lib/pact/provider/test_methods.rb
pact-1.20.0 lib/pact/provider/test_methods.rb
pact-1.19.2 lib/pact/provider/test_methods.rb
pact-1.19.1 lib/pact/provider/test_methods.rb
pact-1.19.0 lib/pact/provider/test_methods.rb
pact-1.18.0 lib/pact/provider/test_methods.rb
pact-1.17.0 lib/pact/provider/test_methods.rb
pact-1.16.1 lib/pact/provider/test_methods.rb
pact-1.16.0 lib/pact/provider/test_methods.rb
pact-1.15.0 lib/pact/provider/test_methods.rb
pact-1.14.0 lib/pact/provider/test_methods.rb
pact-1.13.0 lib/pact/provider/test_methods.rb