@@ -7,7 +7,6 @@ module Pact::MockService
7
7
let ( :logger ) { double ( 'Logger' ) . as_null_object }
8
8
9
9
describe "set_expected_interactions" do
10
-
11
10
let ( :interaction_1 ) { InteractionFactory . create }
12
11
let ( :interaction_2 ) { InteractionFactory . create }
13
12
let ( :interactions ) { [ interaction_1 , interaction_2 ] }
@@ -84,6 +83,7 @@ module Pact::MockService
84
83
let ( :expected_interactions ) { instance_double ( 'Interactions::ExpectedInteractions' , :<< => nil ) }
85
84
let ( :actual_interactions ) { instance_double ( 'Interactions::ActualInteractions' ) }
86
85
let ( :verified_interactions ) { instance_double ( 'Interactions::VerifiedInteractions' ) }
86
+ let ( :matching_interaction ) { nil }
87
87
88
88
before do
89
89
allow ( Interactions ::ExpectedInteractions ) . to receive ( :new ) . and_return ( expected_interactions )
@@ -95,8 +95,6 @@ module Pact::MockService
95
95
subject { Session . new ( logger : logger ) }
96
96
97
97
context "when there is no already verified interaction with the same description and provider state" do
98
- let ( :matching_interaction ) { nil }
99
-
100
98
it "adds the new interaction to the interaction list" do
101
99
expect ( expected_interactions ) . to receive ( :<< ) . with ( interaction_1 )
102
100
subject . add_expected_interaction interaction_1
@@ -138,6 +136,31 @@ module Pact::MockService
138
136
expect { subject . add_expected_interaction interaction_1 } . to raise_error SameSameButDifferentError , diff_message
139
137
end
140
138
end
139
+
140
+ context "when there are more than 3 interactions mocked at the same time" do
141
+ subject { Session . new ( logger : logger , warn_on_too_many_interactions : true ) }
142
+
143
+ it "logs a warning" do
144
+ allow ( expected_interactions ) . to receive ( :size ) . and_return ( 3 , 4 )
145
+ expect ( logger ) . to receive ( :warn ) . with ( /You currently have 4 interactions/ ) . once
146
+ subject . add_expected_interaction ( InteractionFactory . create ( 'description' => 'third interaction' ) ) # no warning
147
+ subject . add_expected_interaction ( InteractionFactory . create ( 'description' => 'forth interaction' ) ) # warning
148
+ end
149
+
150
+ context "when PACT_MAX_CONCURRENT_INTERACTIONS_BEFORE_WARNING is set" do
151
+ before do
152
+ allow ( ENV ) . to receive ( :[] ) . and_call_original
153
+ allow ( ENV ) . to receive ( :[] ) . with ( "PACT_MAX_CONCURRENT_INTERACTIONS_BEFORE_WARNING" ) . and_return ( "5" )
154
+ end
155
+
156
+ it "logs a warning when over the configured limit" do
157
+ allow ( expected_interactions ) . to receive ( :size ) . and_return ( 5 , 6 )
158
+ expect ( logger ) . to receive ( :warn ) . with ( /You currently have 6 interactions/ ) . once
159
+ subject . add_expected_interaction ( InteractionFactory . create ( 'description' => 'fifth interaction' ) ) # no warning
160
+ subject . add_expected_interaction ( InteractionFactory . create ( 'description' => 'sixth interaction' ) ) # warning
161
+ end
162
+ end
163
+ end
141
164
end
142
165
end
143
166
end
0 commit comments