Skip to content

Commit

Permalink
fix: fix integration with pact-message-ruby (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxforasteiro authored Jun 15, 2020
1 parent f8a0c11 commit d2da13e
Show file tree
Hide file tree
Showing 2 changed files with 225 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/pact/provider/configuration/message_provider_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@ def initialize name
end

dsl do
def app &block
self.app_block = block
end

def app_version application_version
self.application_version = application_version
end

def app_version_tags tags
self.tags = tags
end

def publish_verification_results publish_verification_results
self.publish_verification_results = publish_verification_results
Pact::RSpec.with_rspec_2 do
Pact.configuration.error_stream.puts "WARN: Publishing of verification results is currently not supported with rspec 2. If you would like this functionality, please feel free to submit a PR!"
end
end

def honours_pact_with consumer_name, options = {}, &block
create_pact_verification consumer_name, options, &block
end

def honours_pacts_from_pact_broker &block
create_pact_verification_from_broker &block
end

def builder &block
self.app_block = lambda { RackToMessageAdapter.new(block) }
end
Expand Down
198 changes: 198 additions & 0 deletions spec/lib/pact/provider/configuration/message_provider_dsl_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
require "spec_helper"
require "pact/provider/configuration/service_provider_dsl"
require "pact/provider/pact_uri"
require "pact/pact_broker/fetch_pacts"

module Pact
module Provider
module Configuration
describe MessageProviderDSL do
describe "initialize" do
context "with an object instead of a block" do
subject do
described_class.build "name" do
app "blah"
end
end

it "raises an error" do
expect { subject }.to raise_error /wrong number of arguments/
end
end

end

describe "validate" do
context "when no name is provided" do
subject do
described_class.new " " do
app { Object.new }
end
end

it "raises an error" do
expect { subject.send(:validate) }.to raise_error("Please provide a name for the Provider")
end
end

context "when nil name is provided" do
subject do
described_class.new nil do
app { Object.new }
end
end

it "raises an error" do
expect { subject.send(:validate) }.to raise_error(Pact::Provider::Configuration::Error, "Please provide a name for the Provider")
end
end

context "when publish_verification_results is true" do
context "when no application version is provided" do
subject do
described_class.build "name" do
publish_verification_results true
end
end

it "raises an error" do
expect { subject.send(:validate) }.to raise_error(Pact::Provider::Configuration::Error, "Please set the app_version when publish_verification_results is true")
end
end

context "when an application version is provided" do
subject do
described_class.build "name" do
app_version "1.2.3"
publish_verification_results true
end
end

it "does not raise an error" do
expect { subject.send(:validate) }.to_not raise_error
end
end
end
end

describe "honours_pact_with" do
before do
Pact.clear_provider_world
end
let(:pact_url) { "blah" }

context "with no optional params" do
subject do
described_class.build "some-provider" do
app {}
honours_pact_with "some-consumer" do
pact_uri pact_url
end
end
end

it "adds a verification to the Pact.provider_world" do
subject
pact_uri = Pact::Provider::PactURI.new(pact_url)
expect(Pact.provider_world.pact_verifications.first)
.to eq(Pact::Provider::PactVerification.new("some-consumer", pact_uri, :head))
end
end

context "with all params specified" do
let(:pact_uri_options) do
{
username: "pact_user",
password: "pact_pw"
}
end
subject do
described_class.build "some-provider" do
app {}
honours_pact_with "some-consumer", ref: :prod do
pact_uri pact_url, pact_uri_options
end
end
end

it "adds a verification to the Pact.provider_world" do
subject
pact_uri = Pact::Provider::PactURI.new(pact_url, pact_uri_options)
expect(Pact.provider_world.pact_verifications.first)
.to eq(Pact::Provider::PactVerification.new("some-consumer", pact_uri , :prod))
end
end
end

describe "honours_pacts_from_pact_broker" do
before do
Pact.clear_provider_world
end
let(:pact_url) { "blah" }

context "with all params specified" do
let(:tag_1) { "master" }

let(:tag_2) do
{
name: "tag-name",
all: false,
fallback: "master"
}
end

let(:options) do
{
pact_broker_base_url: "some-url",
consumer_version_tags: [tag_1, tag_2]
}
end

subject do
described_class.build "some-provider" do
app {}
app_version_tags ["dev"]
honours_pacts_from_pact_broker do
end
end
end

it "builds a PactVerificationFromBroker" do
expect(PactVerificationFromBroker).to receive(:build).with("some-provider", ["dev"])
subject
end
end
end

describe "builder" do
context "when builder is initialize with a object instead of a block" do
subject do
described_class.build "some-provider" do
builder "foo"
end
end

it "raises an error" do
expect { subject }.to raise_error /wrong number of arguments/
end
end
end

describe "CONFIG_RU_APP" do
context "when a config.ru file does not exist" do
let(:path_that_does_not_exist) { "./tmp/this/path/does/not/exist/probably" }

before do
allow(Pact.configuration).to receive(:config_ru_path).and_return(path_that_does_not_exist)
end

it "raises an error with some helpful text" do
expect { described_class::CONFIG_RU_APP.call }
.to raise_error /Could not find config\.ru file.*#{Regexp.escape(path_that_does_not_exist)}/
end
end
end
end
end
end
end

0 comments on commit d2da13e

Please sign in to comment.