diff options
| author | Andres Ornelas | 2010-06-29 15:43:02 -0700 |
|---|---|---|
| committer | Andres Ornelas | 2010-06-29 15:43:02 -0700 |
| commit | e664186f93838ca1fb1b2e4277f7c18264f81d92 (patch) | |
| tree | 761eaa3afcc4c7d33783c471774135aa38388f13 /src/scenario/Future.js | |
| parent | fdc0bb232a259faf791b901f583e09bba3213ba5 (diff) | |
| download | angular.js-e664186f93838ca1fb1b2e4277f7c18264f81d92.tar.bz2 | |
initial concept
Diffstat (limited to 'src/scenario/Future.js')
| -rw-r--r-- | src/scenario/Future.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/scenario/Future.js b/src/scenario/Future.js new file mode 100644 index 00000000..057b89db --- /dev/null +++ b/src/scenario/Future.js @@ -0,0 +1,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); +} |
