Sha256: 7b223ae6a2351a809ec91a8cf363e254d0dc511534a7bb75308087e7b37000ff

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

require 'rake/tasklib'
require 'pact/tasks/task_helper'

module Pact
  class ProxyVerificationTask < ::Rake::TaskLib

    include Pact::TaskHelper

    attr_reader :pact_spec_configs

    def initialize(name)
      @pact_spec_configs = []
      @provider_base_url = nil
      @name = name
      yield self
      rake_task
    end


    def pact_url(uri, options = {})
      @pact_spec_configs << {uri: uri, pact_helper: options.fetch(:pact_helper, pact_helper_url)}
    end

    # For compatiblity with the normal VerificationTask, allow task.uri
    alias_method :uri, :pact_url

    def provider_base_url url
      @provider_base_url = url
    end

    def pact_helper_url
      File.expand_path('../../../pact_helper', __FILE__)
    end

    private

    attr_reader :name

    def rake_task
      namespace :pact do
        desc "Verify provider against the consumer pacts for #{name}"
        task "verify:#{name}", :description, :provider_state do |t, args|

          require 'pact/provider/pact_spec_runner'
          require 'pact/provider/proxy/configure_service_provider'

          Pact::Proxy::ConfigureServiceProvider.call @provider_base_url
          options = {criteria: spec_criteria(args)}

          handle_verification_failure do
            Provider::PactSpecRunner.new(@pact_spec_configs, options).run
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact-provider-proxy-0.0.2 lib/pact/provider/proxy/tasks/proxy_verification_task.rb