Sha256: 97d7c2d7b077cef6049dc33c41dab3aafa571cb0b73d4167590a6d261c8b0327

Contents?: true

Size: 1.58 KB

Versions: 14

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'
require 'pact/consumer/rspec'


Pact.configure do | config |
  config.logger.level = Logger::DEBUG
  config.doc_generator = :markdown
end

Pact.service_consumer 'Pact Broker Client' do

  has_pact_with "Pact Broker" do
    mock_service :pact_broker do
      port 1234
      pact_specification_version "2.0"
    end
  end

end

module PactBrokerPactHelperMethods

  def placeholder_path(relation, params = [])
    path = "/HAL-REL-PLACEHOLDER-#{relation.gsub(':', '-').upcase}"
    if params.any?
      joined_params = params.collect{ |param| "{#{param}}"}.join("-")
      path = "#{path}-#{joined_params}"
    end

    path
  end

  def placeholder_url(relation, params = [])
    "#{pact_broker.mock_service_base_url}#{placeholder_path(relation, params)}"
  end

  def placeholder_url_term(relation, params = [])
    regexp = "http:\/\/.*"
    if params.any?
      joined_params_for_regexp = params.collect{ |param| "{#{param}}"}.join(".*")
      regexp = "#{regexp}#{joined_params_for_regexp}"
    end

    Pact.term(placeholder_url(relation, params), /#{regexp}/)
  end

  def mock_pact_broker_index(context)
    pact_broker
      .upon_receiving("a request for the index resource")
      .with(
          method: :get,
          path: '/',
          headers: context.get_request_headers).
        will_respond_with(
          status: 200,
          headers: context.pact_broker_response_headers,
          body: {
            _links: {
              :'pb:webhooks' => {
                href: placeholder_url_term('pb:webhooks')
              }
            }
          }
        )
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
pact_broker-client-1.23.0 spec/service_providers/pact_helper.rb
pact_broker-client-1.22.3 spec/service_providers/pact_helper.rb
pact_broker-client-1.22.2 spec/service_providers/pact_helper.rb
pact_broker-client-1.22.1 spec/service_providers/pact_helper.rb
pact_broker-client-1.21.0 spec/service_providers/pact_helper.rb
pact_broker-client-1.20.0 spec/service_providers/pact_helper.rb
pact_broker-client-1.19.0 spec/service_providers/pact_helper.rb
pact_broker-client-1.18.0 spec/service_providers/pact_helper.rb
pact_broker-client-1.17.0 spec/service_providers/pact_helper.rb
pact_broker-client-1.16.2 spec/service_providers/pact_helper.rb
pact_broker-client-1.16.1 spec/service_providers/pact_helper.rb
pact_broker-client-1.16.0 spec/service_providers/pact_helper.rb
pact_broker-client-1.15.1 spec/service_providers/pact_helper.rb
pact_broker-client-1.15.0 spec/service_providers/pact_helper.rb