Sha256: 591c1f1ed4d50a5e35393845562b31ba50670521e5e83d8ba5d92657e6d8d66f

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require_relative "pact_message_helpers"

module SbmtPactConsumerDsl
  include Sbmt::Pact::Matchers

  module ClassMethods
    def has_http_pact_between(consumer, provider, opts: {})
      _has_pact_between(:http, consumer, provider, opts: opts)
    end

    def has_grpc_pact_between(consumer, provider, opts: {})
      _has_pact_between(:grpc, consumer, provider, opts: opts)
    end

    def has_message_pact_between(consumer, provider, opts: {})
      _has_pact_between(:message, consumer, provider, opts: opts)
    end

    def _has_pact_between(transport_type, consumer, provider, opts: {})
      raise "has_#{transport_type}_pact_between is designed to be used with RSpec 3+" unless defined?(::RSpec)
      raise "has_#{transport_type}_pact_between has to be declared at the top level of a suite" unless top_level?
      raise "has_*_pact_between cannot be declared more than once per suite" if defined?(@_pact_config)

      # rubocop:disable RSpec/BeforeAfterAll
      before(:context) do
        @_pact_config = Sbmt::Pact::Consumer::PactConfig.new(transport_type, consumer_name: consumer, provider_name: provider, opts: opts)
      end
      # rubocop:enable RSpec/BeforeAfterAll
    end
  end

  def new_interaction(description = nil)
    pact_config.new_interaction(description)
  end

  def pact_config
    instance_variable_get(:@_pact_config)
  end
end

RSpec.configure do |config|
  config.include SbmtPactConsumerDsl, pact_entity: :consumer
  config.extend SbmtPactConsumerDsl::ClassMethods, pact_entity: :consumer
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sbmt-pact-0.12.2 lib/sbmt/pact/rspec/support/pact_consumer_helpers.rb
sbmt-pact-0.12.1 lib/sbmt/pact/rspec/support/pact_consumer_helpers.rb
sbmt-pact-0.12.0 lib/sbmt/pact/rspec/support/pact_consumer_helpers.rb