blob: 057b89db1650c0dec235fcb89271e3a2e703bae2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
function Future(name, behavior) {
this.value = undefined;
this.name = name;
this.behavior = behavior;
this.fulfilled = false;
}
Future.prototype = {
fulfill: function(value){
this.fulfilled = true;
this.value = value;
}
};
function future(name, behavior) {
return new Future(name, behavior);
};
function repeater(selector) {
var repeaterFuture = future('repeater ' + selector, function(done) {
done($(selector));
});
repeaterFuture.count = function(){
return future(repeaterFuture.name + ' count', function(done) {
done(repeaterFuture.value.size());
});
};
return repeaterFuture;
}
function Matcher(future, logger) {
var self = this;
this.logger = logger;
this.future = future;
}
Matcher.addMatcher = function(name, matcher){
Matcher.prototype[name] = function(expected) {
var future = this.future;
$scenario.addFuture(
'expect ' + future.name + ' ' + name + ' ' + expected,
function(done){
if (matcher(future.value, expected))
throw "Expected " + expected + ' but was ' + future.value;
done();
}
);
};
};
Matcher.addMatcher('toEqual', function(a,b){ return a == b; });
function expect(future) {
return new Matcher(future, window.alert);
}
|