1
- require 'spec_helper'
2
1
require 'pact/provider/configuration/pact_verification'
3
- require 'pact/pact_broker/fetch_pacts'
4
2
5
3
module Pact
6
4
module Provider
7
5
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
12
8
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
14
11
{
15
12
username : 'pact_broker_username' ,
16
13
password : 'pact_broker_password'
17
14
}
18
15
end
19
- let ( :tag ) do
20
- {
21
- name : 'tag-name' ,
22
- all : false ,
23
- fallback : 'master'
24
- }
25
- end
16
+ let ( :tags ) { [ 'master' ] }
26
17
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 )
32
21
end
22
+
33
23
context "with valid values" do
34
24
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
36
78
end
37
79
end
38
80
39
- it "creates a Verification" do
40
- allow ( Pact ::PactBroker ::FetchPacts ) . to receive ( :call ) . and_return ( [ 'pact-urls' ] )
81
+ let ( :fetch_pacts ) { double ( 'FetchPacts' ) }
41
82
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 )
45
85
subject
46
86
end
47
87
end
48
88
end
49
89
end
50
90
end
51
91
end
52
- end
92
+ end
0 commit comments