Sha256: ffbe4660b9060f8c6224f84ffb2541cac08f8975c236133959e0a12bb24fdf98

Contents?: true

Size: 1.83 KB

Versions: 16

Compression:

Stored size: 1.83 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

      def set_metadata example, key, value
        Pact::RSpec.with_rspec_3 do
          example.metadata[key] = value
        end

        Pact::RSpec.with_rspec_2 do
          example.example.metadata[key] = value
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
pact-1.33.2 lib/pact/provider/test_methods.rb
pact-1.33.1 lib/pact/provider/test_methods.rb
pact-1.33.0 lib/pact/provider/test_methods.rb
pact-1.32.0 lib/pact/provider/test_methods.rb
pact-1.31.0 lib/pact/provider/test_methods.rb
pact-1.30.0 lib/pact/provider/test_methods.rb
pact-1.29.0 lib/pact/provider/test_methods.rb
pact-1.28.0 lib/pact/provider/test_methods.rb
pact-1.28.0.rc1 lib/pact/provider/test_methods.rb
pact-1.27.0 lib/pact/provider/test_methods.rb
pact-1.26.0 lib/pact/provider/test_methods.rb
pact-1.25.0 lib/pact/provider/test_methods.rb
pact-1.24.0 lib/pact/provider/test_methods.rb
pact-1.23.0 lib/pact/provider/test_methods.rb
pact-1.22.2 lib/pact/provider/test_methods.rb
pact-1.22.0 lib/pact/provider/test_methods.rb