diff --git a/lib/pact/provider/configuration/pact_verification_with_tags.rb b/lib/pact/provider/configuration/pact_verification_with_tags.rb index 9f851ffd..120f6c52 100644 --- a/lib/pact/provider/configuration/pact_verification_with_tags.rb +++ b/lib/pact/provider/configuration/pact_verification_with_tags.rb @@ -12,10 +12,14 @@ class PactVerificationWithTags extend Pact::DSL - attr_accessor :tags, :pact_uri - - def initialize tags, options = {} - @tags = tags + attr_accessor :name, :pact_broker_base_url, :tags, :pact_uri + + def initialize(name, options = {}) + puts options + @tags = options.fetch(:consumer_version_tags) || [] + @pact_broker_base_url = options.fetch(:pact_broker_base_url) + @provider_name = name + @options = options @pact_uri = nil end @@ -33,8 +37,11 @@ def finalize private def create_pact_verification - verification = Pact::Provider::PactVerificationWithTags.new(tags, pact_uri) - Pact.provider_world.add_pact_verification verification + pacts = Pact::PactBroker::FetchPacts.call(@provider_name, tags, pact_broker_base_url, @options) + pacts.each do |pact_uri| + verification = Pact::Provider::PactVerificationWithTags.new(pact_uri) + Pact.provider_world.add_pact_verification verification + end end def validate diff --git a/lib/pact/provider/configuration/service_provider_dsl.rb b/lib/pact/provider/configuration/service_provider_dsl.rb index 722a9955..0c5272cf 100644 --- a/lib/pact/provider/configuration/service_provider_dsl.rb +++ b/lib/pact/provider/configuration/service_provider_dsl.rb @@ -55,8 +55,8 @@ def honours_pact_with consumer_name, options = {}, &block create_pact_verification consumer_name, options, &block end - def honours_pacts_from_pact_broker(tags, options = {}, &block) - create_pact_verification_with_tags tags, options, &block + def honours_pacts_from_pact_broker options = {}, &block + create_pact_verification_with_tags options, &block end end @@ -64,8 +64,8 @@ def create_pact_verification consumer_name, options, &block PactVerification.build(consumer_name, options, &block) end - def create_pact_verification_with_tags(tags, options, &block) - PactVerificationWithTags.build(tags, options, &block) + def create_pact_verification_with_tags(options, &block) + PactVerificationWithTags.build(name, options, &block) end def finalize diff --git a/lib/pact/provider/pact_verification_with_tags.rb b/lib/pact/provider/pact_verification_with_tags.rb index e515c4a9..1ba7c53c 100644 --- a/lib/pact/provider/pact_verification_with_tags.rb +++ b/lib/pact/provider/pact_verification_with_tags.rb @@ -1,14 +1,12 @@ module Pact::Provider class PactVerificationWithTags - attr_reader :tags, :uri - def initialize(tags, uri) - @tags = tags + attr_reader :uri + def initialize(uri) @uri = uri end def ==(other) other.is_a?(PactVerificationWithTags) && - tags == other.tags && uri == other.uri end end diff --git a/spec/lib/pact/provider/configuration/pact_verification_with_tags_spec.rb b/spec/lib/pact/provider/configuration/pact_verification_with_tags_spec.rb index 00be60c4..9458e947 100644 --- a/spec/lib/pact/provider/configuration/pact_verification_with_tags_spec.rb +++ b/spec/lib/pact/provider/configuration/pact_verification_with_tags_spec.rb @@ -1,5 +1,6 @@ require 'spec_helper' require 'pact/provider/configuration/pact_verification_with_tags' +require 'pact/pact_broker/fetch_pacts' module Pact module Provider @@ -8,6 +9,7 @@ module Configuration describe 'create_verification' do let(:url) { 'http://some/uri' } + let(:provider_name) {'provider-name'} let(:pact_repository_uri_options) do { username: 'pact_broker_username', @@ -22,19 +24,24 @@ module Configuration } end + let(:options) do + { + pact_broker_base_url: url, + consumer_version_tags: [tag] + } + end context "with valid values" do subject do - uri = url - tags = [tag] - PactVerificationWithTags.build(tags, options) do - pact_uri uri, pact_repository_uri_options + PactVerificationWithTags.build(provider_name, options) do end end it "creates a Verification" do - pact_uri = Pact::Provider::PactURI.new(url, pact_repository_uri_options) + allow(Pact::PactBroker::FetchPacts).to receive(:call).and_return(['pact-urls']) + tags = [tag] - expect(Pact::Provider::PactVerificationWithTags).to receive(:new).with(tags, pact_uri) + expect(Pact::PactBroker::FetchPacts).to receive(:call).with(provider_name, tags, url, options) + expect(Pact::Provider::PactVerificationWithTags).to receive(:new).with('pact-urls') subject end end diff --git a/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb b/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb index e094554c..9cd3bd1a 100644 --- a/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb +++ b/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' require 'pact/provider/configuration/service_provider_dsl' require 'pact/provider/pact_uri' +require 'pact/pact_broker/fetch_pacts' module Pact @@ -134,31 +135,7 @@ module Configuration end let(:pact_url) { 'blah' } - context 'with no optional params' do - subject do - ServiceProviderDSL.build 'some-provider' do - app {} - honours_pacts_from_pact_broker nil 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::PactVerificationWithTags.new(nil, pact_uri)) - end - end - context 'with all params specified' do - let(:pact_uri_options) do - { - username: 'pact_user', - password: 'pact_pw' - } - end let(:tag_1) { 'master' } let(:tag_2) do @@ -169,44 +146,47 @@ module Configuration } end + let(:options) do + { + pact_broker_base_url: 'some-url', + consumer_version_tags: [tag_1, tag_2] + } + end + subject do ServiceProviderDSL.build 'some-provider' do app {} - honours_pacts_from_pact_broker [tag_1, tag_2] do - pact_uri pact_url, pact_uri_options + honours_pacts_from_pact_broker options do end end end it 'adds a verification to the Pact.provider_world' do + allow(Pact::PactBroker::FetchPacts).to receive(:call).and_return(['pact-urls']) + subject - pact_uri = Pact::Provider::PactURI.new(pact_url, pact_uri_options) - tags = [tag_1, tag_2] + expect(Pact.provider_world.pact_verifications.first) - .to eq(Pact::Provider::PactVerificationWithTags.new(tags, pact_uri)) + .to eq(Pact::Provider::PactVerificationWithTags.new('pact-urls')) end end - end - describe "CONFIG_RU_APP" do - context "when a config.ru file does not exist" do - + 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 + it 'raises an error with some helpful text' do expect { ServiceProviderDSL::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