Sha256: 411b44f6f6dfc0fd129fe2c6a26928ceb1379f7a1fa79a5bc3646d2b8d8f7a96

Contents?: true

Size: 956 Bytes

Versions: 45

Compression:

Stored size: 956 Bytes

Contents

require 'pact/mock_service/spawn'
require 'pact/mock_service/control_server/delegator'
require 'find_a_port'
require 'pact/mock_service/server/wait_for_server_up'

# Create a new MockService on a random port and delegate the incoming request to it

module Pact
  module MockService
    module ControlServer

      class MockServiceCreator

        attr_reader :options

        def initialize mock_services, options
          @mock_services = mock_services
          @options = options
        end

        def call env
          consumer_name = env['HTTP_X_PACT_CONSUMER']
          provider_name = env['HTTP_X_PACT_PROVIDER']
          port = FindAPort.available_port
          mock_service = Pact::MockService::Spawn.(consumer_name, provider_name, port, options)
          delegator = Delegator.new(mock_service, consumer_name, provider_name)
          @mock_services.add(delegator)
          delegator.call(env)
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
pact-mock_service-0.7.2 lib/pact/mock_service/control_server/mock_service_creator.rb
pact-mock_service-0.7.1 lib/pact/mock_service/control_server/mock_service_creator.rb
pact-mock_service-0.7.0 lib/pact/mock_service/control_server/mock_service_creator.rb
pact-mock_service-0.6.0 lib/pact/mock_service/control_server/mock_service_creator.rb
pact-mock_service-0.5.5 lib/pact/mock_service/control_server/mock_service_creator.rb