@@ -11,8 +11,6 @@ import 'package:test/test.dart';
11
11
12
12
import 'helper.dart' ;
13
13
14
- //class MockGitHub extends MockWithNamedArgs implements GitHub {}
15
-
16
14
class MockGitHub extends Mock implements GitHub {}
17
15
18
16
void main () {
@@ -151,18 +149,21 @@ void main() {
151
149
152
150
test ('creates valid JSON body' , () {
153
151
// given
154
- http.Response res = new http.Response ('{}' , 200 );
155
- github
156
- . when ( callsTo ( 'request' , anything, anything ))
157
- .alwaysReturn (new Future .value (res ));
152
+ http.Response expectedResponse = new http.Response ('{}' , 200 );
153
+ when ( github. request (any, any,
154
+ body : any, headers : typed (any, named : 'headers' ) ))
155
+ .thenReturn (new Future .value (expectedResponse ));
158
156
159
157
// when
160
158
git.editReference (repo, 'heads/b' , someSha, force: true );
161
159
162
160
// then
163
- LogEntryNamedArgs entry = github.getLogs ().first;
164
- Map body = JSON .decode (entry.namedArgs[#body]);
165
- Map headers = entry.namedArgs[#headers];
161
+ var captured = verify (github.request (any, any,
162
+ body: captureAny, headers: typed (captureAny, named: 'headers' )))
163
+ .captured;
164
+
165
+ var body = JSON .decode (captured[0 ]);
166
+ var headers = captured[1 ];
166
167
167
168
expect (body['sha' ], equals (someSha));
168
169
expect (body['force' ], equals (true ));
@@ -173,52 +174,44 @@ void main() {
173
174
group ('deleteReference()' , () {
174
175
test ('constructs correct path' , () {
175
176
// given
176
- http.Response res = new http.Response ('{}' , 200 );
177
- github
178
- .when (callsTo ('request' , anything, anything))
179
- .alwaysReturn (new Future .value (res));
177
+ http.Response expectedResponse = new http.Response ('{}' , 200 );
178
+ when (github.request (any, any))
179
+ .thenReturn (new Future .value (expectedResponse));
180
180
181
181
// when
182
182
git.deleteReference (repo, 'heads/b' );
183
183
184
184
// then
185
- github
186
- .getLogs (callsTo ('request' , 'DELETE' , '/repos/o/n/git/refs/heads/b' ))
187
- .verify (happenedOnce);
185
+ verify (github.request ('DELETE' , '/repos/o/n/git/refs/heads/b' ));
188
186
});
189
187
});
190
188
191
189
group ('getTag()' , () {
192
190
test ('constructs correct path' , () {
193
191
git.getTag (repo, someSha);
194
192
195
- github
196
- .getLogs (callsTo ('getJSON' , '/repos/o/n/git/tags/someSHA' ))
197
- .verify (happenedOnce);
193
+ verify (github.getJSON ('/repos/o/n/git/tags/someSHA' ,
194
+ convert: GitTag .fromJSON, statusCode: StatusCodes .OK ));
198
195
});
199
196
});
200
197
201
198
group ('createTag()' , () {
199
+ var createGitTag = new CreateGitTag ('v0.0.1' , 'a message' , someSha,
200
+ 'commit' , new GitCommitUser ('aName' , 'aEmail' , new DateTime .now ()));
201
+
202
202
test ('constructs correct path' , () {
203
- git.createTag (
204
- repo,
205
- new CreateGitTag ('v0.0.1' , 'a message' , someSha, 'commit' ,
206
- new GitCommitUser ('aName' , 'aEmail' , new DateTime .now ())));
203
+ git.createTag (repo, createGitTag);
207
204
208
- github
209
- .getLogs (callsTo ('postJSON' , '/repos/o/n/git/tags' ))
210
- .verify (happenedOnce);
205
+ verify (github.postJSON ('/repos/o/n/git/tags' ,
206
+ convert: GitTag .fromJSON,
207
+ statusCode: StatusCodes .CREATED ,
208
+ body: createGitTag.toJSON ()));
211
209
});
212
210
213
211
test ('creates valid JSON body' , () {
214
- git.createTag (
215
- repo,
216
- new CreateGitTag ('v0.0.1' , 'a message' , someSha, 'commit' ,
217
- new GitCommitUser ('aName' , 'aEmail' , new DateTime .now ())));
218
-
219
- LogEntryNamedArgs entry = github.getLogs ().first;
220
- Map body = JSON .decode (entry.namedArgs[#body]);
212
+ git.createTag (repo, createGitTag);
221
213
214
+ var body = captureSentBody (github);
222
215
expect (body['tag' ], equals ('v0.0.1' ));
223
216
expect (body['message' ], equals ('a message' ));
224
217
expect (body['object' ], equals (someSha));
@@ -312,3 +305,13 @@ captureSentBody(MockGitHub github) {
312
305
var body = JSON .decode (bodyString);
313
306
return body;
314
307
}
308
+
309
+ captureSentHeaders (MockGitHub github) {
310
+ var headersString = verify (github.postJSON (any,
311
+ convert: any, statusCode: any, body: any, headers: typed (captureAny)))
312
+ .captured
313
+ .single;
314
+
315
+ var headers = JSON .decode (headersString);
316
+ return headers;
317
+ }
0 commit comments