1- require 'spec_helper'
21require 'pact/provider/configuration/pact_verification'
3- require 'pact/pact_broker/fetch_pacts'
42
53module Pact
64 module Provider
75 module Configuration
8- describe PactVerification do
9-
10- describe 'create_verification' do
11- let ( :url ) { 'http://some/uri' }
6+ describe PactVerificationFromBroker do
7+ describe 'build' do
128 let ( :provider_name ) { 'provider-name' }
13- let ( :pact_repository_uri_options ) do
9+ let ( :base_url ) { "http://broker.org" }
10+ let ( :basic_auth_options ) do
1411 {
1512 username : 'pact_broker_username' ,
1613 password : 'pact_broker_password'
1714 }
1815 end
19- let ( :tag ) do
20- {
21- name : 'tag-name' ,
22- all : false ,
23- fallback : 'master'
24- }
25- end
16+ let ( :tags ) { [ 'master' ] }
2617
27- let ( :options ) do
28- {
29- pact_broker_base_url : url ,
30- consumer_version_tags : [ tag ]
31- }
18+ before do
19+ allow ( Pact ::PactBroker ::FetchPacts ) . to receive ( :new ) . and_return ( fetch_pacts )
20+ allow ( Pact . provider_world ) . to receive ( :add_pact_uri_source )
3221 end
22+
3323 context "with valid values" do
3424 subject do
35- PactVerificationFromBroker . build ( provider_name , options ) do
25+ PactVerificationFromBroker . build ( provider_name ) do
26+ pact_broker_base_url base_url , basic_auth_options
27+ consumer_version_tags tags
28+ end
29+ end
30+
31+ let ( :fetch_pacts ) { double ( 'FetchPacts' ) }
32+
33+ it "creates a instance of Pact::PactBroker::FetchPacts" do
34+ expect ( Pact ::PactBroker ::FetchPacts ) . to receive ( :new ) . with ( provider_name , tags , base_url , basic_auth_options )
35+ subject
36+ end
37+
38+ it "adds a pact_uri_source to the provider world" do
39+ expect ( Pact . provider_world ) . to receive ( :add_pact_uri_source ) . with ( fetch_pacts )
40+ subject
41+ end
42+ end
43+
44+ context "with a missing base url" do
45+ subject do
46+ PactVerificationFromBroker . build ( provider_name ) do
47+
48+ end
49+ end
50+
51+ let ( :fetch_pacts ) { double ( 'FetchPacts' ) }
52+
53+ it "raises an error" do
54+ expect { subject } . to raise_error Pact ::Error , /Please provide a pact_broker_base_url/
55+ end
56+ end
57+
58+ context "with a non array object for consumer_version_tags" do
59+ subject do
60+ PactVerificationFromBroker . build ( provider_name ) do
61+ pact_broker_base_url base_url
62+ consumer_version_tags "master"
63+ end
64+ end
65+
66+ let ( :fetch_pacts ) { double ( 'FetchPacts' ) }
67+
68+ it "coerces the value into an array" do
69+ expect ( Pact ::PactBroker ::FetchPacts ) . to receive ( :new ) . with ( anything , [ "master" ] , anything , anything )
70+ subject
71+ end
72+ end
73+
74+ context "when no consumer_version_tags are provided" do
75+ subject do
76+ PactVerificationFromBroker . build ( provider_name ) do
77+ pact_broker_base_url base_url
3678 end
3779 end
3880
39- it "creates a Verification" do
40- allow ( Pact ::PactBroker ::FetchPacts ) . to receive ( :call ) . and_return ( [ 'pact-urls' ] )
81+ let ( :fetch_pacts ) { double ( 'FetchPacts' ) }
4182
42- tags = [ tag ]
43- expect ( Pact ::PactBroker ::FetchPacts ) . to receive ( :call ) . with ( provider_name , tags , url , options )
44- expect ( Pact ::Provider ::PactVerification ) . to receive ( :new ) . with ( nil , 'pact-urls' , nil )
83+ it "creates an instance of FetchPacts with an emtpy array for the consumer_version_tags" do
84+ expect ( Pact ::PactBroker ::FetchPacts ) . to receive ( :new ) . with ( anything , [ ] , anything , anything )
4585 subject
4686 end
4787 end
4888 end
4989 end
5090 end
5191 end
52- end
92+ end
0 commit comments