redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

Errors when trying to dispatch MockRequest #67

Closed austincummings closed 9 years ago

austincummings commented 9 years ago

Hey, I am receiving the following errors when I try to make a MockRequest to a route I have configured. All parameters should be set up correctly.

INFO: 2015-01-20 15:19:52.819: Configured target for /ocams/hk/query [POST]: webquery.server.ocams.handleOcamsHkQuery
INFO: 2015-01-20 15:19:52.824: Configured target for /ocams/sci/query [POST]: webquery.server.ocams.handleOcamsScienceQuery
unittest-suite-wait-for-done
ERROR - 2015-01-20 15:19:52.864
Error thrown by handler.
The null object does not have a method 'call'.

NoSuchMethodError: method not found: 'call'
Receiver: null
Arguments: [Instance of 'Request']
package:shelf/shelf_io.dart 66:20             handleRequest
package:redstone/src/server_impl.dart 170:29  _process.<fn>
dart:async                                    runZoned
package:redstone/src/server_impl.dart 167:11  _process
package:redstone/src/server_impl.dart 160:11  _dispatchRequest
package:redstone/server.dart 491:21           dispatch
test/test_ocams_hk_query.dart 32:28           main.<fn>
package:unittest/src/test_case.dart 100:37    _run.<fn>
dart:isolate                                  _RawReceivePortImpl._handleMessage

SEVERE: 2015-01-20 15:19:52.883: Uncaught error. Please, report this at https://github.com/luizmineo/redstone.dart - The null object does not have a getter 'url'.

NoSuchMethodError: method not found: 'url'
Receiver: null
Arguments: []
dart:core                                     Object.noSuchMethod
package:redstone/mocks.dart 137:31            MockRequest.url
package:redstone/src/server_impl.dart 171:54  _process.<fn>.<fn>
dart:isolate                                  _RawReceivePortImpl._handleMessage
luizmineo commented 9 years ago

can you share your test code?

austincummings commented 9 years ago

Here you go,

import "package:unittest/unittest.dart";
import "package:redstone/server.dart" as app;
import "package:redstone/mocks.dart";
@app.Install(urlPrefix: "/ocams")
import "package:webquery/server/ocams.dart";

void main() {
    app.setupConsoleLog();
    app.setUp();
    test("no parameters", () {
        var req = new MockRequest("/ocams/hk/query", method: app.POST, body: {
            "start_date": "1900-01-01",
            "end_date": "2040-12-31"
        });
        return app.dispatch(req).then((resp) {
            expect(resp.statusCode, equals(200));
        });
    });
    app.tearDown();
}
luizmineo commented 9 years ago

Thanks! Try to move the setup() and tearDown() calls to the setup and teardown stages of your test:

import "package:unittest/unittest.dart";
import "package:redstone/server.dart" as app;
import "package:redstone/mocks.dart";
@app.Install(urlPrefix: "/ocams")
import "package:webquery/server/ocams.dart";

void main() {
    setUp((){
       app.setupConsoleLog();
       app.setUp();
    });

    tearDown((){
      app.tearDown();
    });

    test("no parameters", () {
        var req = new MockRequest("/ocams/hk/query", method: app.POST, body: {
            "start_date": "1900-01-01",
            "end_date": "2040-12-31"
        });
        return app.dispatch(req).then((resp) {
            expect(resp.statusCode, equals(200));
        });
    });

}
austincummings commented 9 years ago

Works. Thanks!