Browse Source

[4.0.0] TakeRequest to be FIFO like Square's implementation

pull/2/head
Miguel Castiblanco 4 years ago
parent
commit
86529c2e93
  1. 3
      .gitignore
  2. 6
      CHANGELOG.md
  3. 8
      README.md
  4. 6
      lib/mock_web_server.dart
  5. 2
      pubspec.yaml
  6. 4
      test/server_test.dart

3
.gitignore

@ -13,3 +13,6 @@ pubspec.lock
doc/api/
.dart_tool/
# vim
*.swp

6
CHANGELOG.md

@ -1,5 +1,11 @@
# Changelog
### 4.0.0 - Dec 06, 2018
- Changed `takeRequest()` to be FIFO like Square's implementation
## Breaking
- All your tests need to be updated to use `takeRequest()` according to above
## 3.0.0 - Nov 27, 2018
### Changed
- Updated code to support Dart 2

8
README.md

@ -100,12 +100,12 @@ request(path: "first");
request(path: "second");
request(path: "third");
// takeRequest is LIFO
// takeRequest is FIFO
// You should probably assign takeRequest() to a var so that you can
// validate multiple things.
expect(server.takeRequest().uri.path, "/third");
expect(server.takeRequest().method, "GET");
expect(server.takeRequest().headers['x-header'], "nosniff");
expect(server.takeRequest().method, "GET");
expect(server.takeRequest().uri.path, "/third");
```
### Using a dispatcher for fine-grained routing
@ -191,4 +191,4 @@ MockWebServer _server =
```
### Stopping
During the `tearDown` of your tests you should stop the server. `server.shutdown()` will do.
During the `tearDown` of your tests you should stop the server. `server.shutdown()` will do.

6
lib/mock_web_server.dart

@ -208,15 +208,15 @@ class MockWebServer {
}
/**
* Returns the most recent request that was received by the server. Will
* Returns the requests received by the server, first in first out FIFO. Will
* throw an exception if there aren't any requests available.
*/
StoredRequest takeRequest() {
if (_requests.isEmpty) {
throw new Exception("No requests on record");
}
var request = _requests.last;
_requests.removeLast();
var request = _requests.first;
_requests.removeFirst();
return request;
}

2
pubspec.yaml

@ -1,5 +1,5 @@
name: mock_web_server
version: 3.0.0
version: 4.0.0
description: Versatile scriptable Web Server for real integration tests in Flutter, server, and Dart CLI applications
author: Miguel Castiblanco <miguel@starcarr.co>
homepage: https://git.starcarr.co/Dart/MockWebServer

4
test/server_test.dart

@ -92,9 +92,9 @@ void main() {
await _get("second");
await _get("third");
expect(_server.takeRequest().uri.path, "/third");
expect(_server.takeRequest().uri.path, "/second");
expect(_server.takeRequest().uri.path, "/first");
expect(_server.takeRequest().uri.path, "/second");
expect(_server.takeRequest().uri.path, "/third");
expect(_server.requestCount, 3);
});

Loading…
Cancel
Save