@@ -34,35 +34,83 @@ module Pacts
34
34
let ( :json_content ) { { 'some' => 'json' } . to_json }
35
35
let ( :pact ) { instance_double ( PactBroker ::Domain ::Pact , json_content : json_content ) }
36
36
37
- before do
38
- allow_any_instance_of ( Pacts ::Repository ) . to receive ( :find_previous_pact ) . and_return ( previous_pact )
39
- end
40
-
41
37
subject { Service . pact_is_new_or_pact_has_changed_since_previous_version? pact }
42
38
43
- context "when a previous pact is found" do
44
- let ( :previous_pact ) { instance_double ( PactBroker ::Domain ::Pact , json_content : previous_json_content ) }
45
- let ( :previous_json_content ) { { 'some' => 'json' } . to_json }
39
+ context "when consumer version is untagged" do
40
+ before do
41
+ allow ( pact ) . to receive ( :consumer_version_tag_names ) . and_return ( [ ] ) ;
42
+ allow_any_instance_of ( Pacts ::Repository ) . to receive ( :find_previous_pact ) . with ( pact , :untagged ) . and_return ( previous_pact )
43
+ end
44
+
45
+ context "when a previous pact is found" do
46
+ let ( :previous_pact ) { instance_double ( PactBroker ::Domain ::Pact , json_content : previous_json_content ) }
47
+ let ( :previous_json_content ) { { 'some' => 'json' } . to_json }
46
48
47
- context "when the json_content is the same" do
48
- it "returns false" do
49
- expect ( subject ) . to be_falsey
49
+ context "when the json_content is the same" do
50
+ it "returns false" do
51
+ expect ( subject ) . to be_falsey
52
+ end
53
+ end
54
+
55
+ context "when the json_content is not the same" do
56
+ let ( :previous_json_content ) { { 'some-other' => 'json' } . to_json }
57
+ it "returns truthy" do
58
+ expect ( subject ) . to be_truthy
59
+ end
50
60
end
51
61
end
52
62
53
- context "when the json_content is not the same" do
54
- let ( :previous_json_content ) { { 'some-other' => 'json' } . to_json }
55
- it "returns truthy" do
63
+ context "when a previous pact is not found" do
64
+ let ( :previous_pact ) { nil }
65
+
66
+ it "returns true" do
56
67
expect ( subject ) . to be_truthy
57
68
end
58
69
end
59
70
end
60
71
61
- context "when a previous pact is not found" do
62
- let ( :previous_pact ) { nil }
72
+ context "when consumer version has two tags" do
73
+ before do
74
+ allow ( pact ) . to receive ( :consumer_version_tag_names ) . and_return ( [ 'tag_1' , 'tag_2' ] ) ;
75
+ allow_any_instance_of ( Pacts ::Repository ) . to receive ( :find_previous_pact ) . with ( pact , 'tag_1' ) . and_return ( previous_pact_tag_1 )
76
+ allow_any_instance_of ( Pacts ::Repository ) . to receive ( :find_previous_pact ) . with ( pact , 'tag_2' ) . and_return ( previous_pact_tag_2 )
77
+ end
78
+
79
+ context "when a previous pact is found for both tags" do
80
+ let ( :previous_pact_tag_1 ) { instance_double ( PactBroker ::Domain ::Pact , json_content : previous_json_content_tag_1 ) }
81
+ let ( :previous_json_content_tag_1 ) { { 'some' => 'json' } . to_json }
82
+
83
+ let ( :previous_pact_tag_2 ) { instance_double ( PactBroker ::Domain ::Pact , json_content : previous_json_content_tag_2 ) }
84
+ let ( :previous_json_content_tag_2 ) { { 'some' => 'json' } . to_json }
63
85
64
- it "returns true" do
65
- expect ( subject ) . to be_truthy
86
+ context "when the json_content of both previous pacts and new pact is the same" do
87
+ it "returns false" do
88
+ expect ( subject ) . to be_falsey
89
+ end
90
+ end
91
+
92
+ context "when the json_content of first previous pact is not the same" do
93
+ let ( :previous_json_content_tag_1 ) { { 'some-other' => 'json' } . to_json }
94
+ it "returns truthy" do
95
+ expect ( subject ) . to be_truthy
96
+ end
97
+ end
98
+
99
+ context "when the json_content of second previous pact not the same" do
100
+ let ( :previous_json_content_tag_2 ) { { 'some-other' => 'json' } . to_json }
101
+ it "returns truthy" do
102
+ expect ( subject ) . to be_truthy
103
+ end
104
+ end
105
+ end
106
+
107
+ context "when no previous pacts are found" do
108
+ let ( :previous_pact_tag_1 ) { nil }
109
+ let ( :previous_pact_tag_2 ) { nil }
110
+
111
+ it "returns true" do
112
+ expect ( subject ) . to be_truthy
113
+ end
66
114
end
67
115
end
68
116
end
0 commit comments