feat(injector): initial implementaion of dynamic injector

This commit is contained in:
vsavkin
2014-09-30 14:56:33 -04:00
parent 6c8da62c1b
commit b2199632c7
24 changed files with 792 additions and 44 deletions
+44 -4
View File
@@ -1,5 +1,45 @@
library test_lib.test_lib;
export 'package:guinness/guinness.dart' show
describe, ddescribe, xdescribe,
it, xit, iit,
beforeEach, afterEach, expect;
import 'package:guinness/guinness_html.dart' as gns;
export 'package:guinness/guinness_html.dart';
import 'package:unittest/unittest.dart' hide expect;
import 'dart:mirrors';
import 'dart:async';
Expect expect(actual, [matcher]) {
final expect = new Expect(actual);
if (matcher != null) expect.to(matcher);
return expect;
}
class Expect extends gns.Expect {
Expect(actual) : super(actual);
void toThrowError(message) => this.toThrowWith(message: message);
void toBeFuture() => _expect(actual is Future, equals(true));
Function get _expect => gns.guinness.matchers.expect;
}
it(name, fn) {
gns.it(name, _handleAsync(fn));
}
iit(name, fn) {
gns.iit(name, _handleAsync(fn));
}
_handleAsync(fn) {
ClosureMirror cm = reflect(fn);
MethodMirror mm = cm.function;
var completer = new Completer();
if (mm.parameters.length == 1) {
return () {
cm.apply([completer.complete]);
return completer.future;
};
}
return fn;
}
+32
View File
@@ -16,3 +16,35 @@ window.print = function(msg) {
window.console.log(msg);
}
};
window.beforeEach(function() {
jasmine.addMatchers({
toBeFuture: function() {
return {
compare: function (actual, expectedClass) {
var pass = typeof actual === 'object' && typeof actual.then === 'function';
return {
pass: pass,
get message() {
return 'Expected ' + actual + ' to be a future';
}
};
}
};
},
toBeAnInstanceOf: function() {
return {
compare: function(actual, expectedClass) {
var pass = typeof actual === 'object' && actual instanceof expectedClass;
return {
pass: pass,
get message() {
return 'Expected ' + actual + ' to be an instance of ' + expectedClass;
}
};
}
};
}
});
});