@@ -13,12 +13,14 @@ module Resources
13
13
let ( :headers ) { { 'CONTENT_TYPE' => 'application/json' } }
14
14
let ( :webhook ) { double ( 'webhook' ) }
15
15
let ( :saved_webhook ) { double ( 'saved_webhook' ) }
16
- let ( :provider ) { instance_double ( PactBroker ::Domain ::Pacticipant ) }
17
- let ( :consumer ) { instance_double ( PactBroker ::Domain ::Pacticipant ) }
16
+ let ( :provider ) { instance_double ( PactBroker ::Domain ::Pacticipant ) }
17
+ let ( :consumer ) { instance_double ( PactBroker ::Domain ::Pacticipant ) }
18
+ let ( :webhook_decorator ) { instance_double ( Decorators ::WebhookDecorator , from_json : webhook ) }
18
19
19
20
before do
20
21
allow ( PactBroker ::Pacticipants ::Service ) . to receive ( :find_pacticipant_by_name ) . with ( "Some Provider" ) . and_return ( provider )
21
22
allow ( PactBroker ::Pacticipants ::Service ) . to receive ( :find_pacticipant_by_name ) . with ( "Some Consumer" ) . and_return ( consumer )
23
+ allow ( Decorators ::WebhookDecorator ) . to receive ( :new ) . and_return ( webhook_decorator )
22
24
end
23
25
24
26
describe "GET" do
@@ -83,6 +85,7 @@ module Resources
83
85
84
86
context "when the provider is not found" do
85
87
let ( :provider ) { nil }
88
+
86
89
it "returns a 404 status" do
87
90
subject
88
91
expect ( last_response . status ) . to eq 404
@@ -142,10 +145,10 @@ module Resources
142
145
context "with valid attributes" do
143
146
144
147
let ( :webhook_response_json ) { { some : 'webhook' } . to_json }
145
- let ( :decorator ) { instance_double ( Decorators ::WebhookDecorator ) }
146
148
147
149
before do
148
150
allow_any_instance_of ( Decorators ::WebhookDecorator ) . to receive ( :to_json ) . and_return ( webhook_response_json )
151
+ allow ( webhook_decorator ) . to receive ( :to_json ) . and_return ( webhook_response_json )
149
152
end
150
153
151
154
it "saves the webhook" do
@@ -169,9 +172,8 @@ module Resources
169
172
end
170
173
171
174
it "generates the JSON response body" do
172
- allow ( Decorators ::WebhookDecorator ) . to receive ( :new ) . and_call_original #Deserialise
173
- expect ( Decorators ::WebhookDecorator ) . to receive ( :new ) . with ( saved_webhook ) . and_return ( decorator ) #Serialize
174
- expect ( decorator ) . to receive ( :to_json ) . with ( user_options : { base_url : 'http://example.org' } )
175
+ expect ( Decorators ::WebhookDecorator ) . to receive ( :new ) . with ( saved_webhook ) . and_return ( webhook_decorator )
176
+ expect ( webhook_decorator ) . to receive ( :to_json ) . with ( user_options : { base_url : 'http://example.org' } )
175
177
subject
176
178
end
177
179
@@ -180,10 +182,7 @@ module Resources
180
182
expect ( last_response . body ) . to eq webhook_response_json
181
183
end
182
184
end
183
-
184
185
end
185
-
186
186
end
187
187
end
188
-
189
188
end
0 commit comments