diff options
| author | Elliott Sprehn | 2010-10-08 16:43:40 -0700 |
|---|---|---|
| committer | Elliott Sprehn | 2010-10-14 09:47:39 -0700 |
| commit | 03df6cbddbb80186caf571e29957370b2ef9881c (patch) | |
| tree | d5a321c8b207b464a5c8a300c422186e20e8ae31 /src/scenario/SpecRunner.js | |
| parent | 0f104317dff5628765e26cc68df7dd1175b2aa5e (diff) | |
| download | angular.js-03df6cbddbb80186caf571e29957370b2ef9881c.tar.bz2 | |
New Angular Scenario runner and DSL system with redesigned HTML UI.
Uses the Jasmine syntax for tests, ex:
describe('widgets', function() {
it('should verify that basic widgets work', function(){
navigateTo('widgets.html');
input('text.basic').enter('Carlos');
expect(binding('text.basic')).toEqual('Carlos');
input('text.basic').enter('Carlos Santana');
expect(binding('text.basic')).not().toEqual('Carlos Boozer');
input('text.password').enter('secret');
expect(binding('text.password')).toEqual('secret');
expect(binding('text.hidden')).toEqual('hiddenValue');
expect(binding('gender')).toEqual('male');
input('gender').select('female');
expect(binding('gender')).toEqual('female');
});
});
Note: To create new UI's implement the interface shown in angular.scenario.ui.Html.
Diffstat (limited to 'src/scenario/SpecRunner.js')
| -rw-r--r-- | src/scenario/SpecRunner.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/scenario/SpecRunner.js b/src/scenario/SpecRunner.js new file mode 100644 index 00000000..8b6d4ef1 --- /dev/null +++ b/src/scenario/SpecRunner.js @@ -0,0 +1,78 @@ +/** + * This class is the "this" of the it/beforeEach/afterEach method. + * Responsibilities: + * - "this" for it/beforeEach/afterEach + * - keep state for single it/beforeEach/afterEach execution + * - keep track of all of the futures to execute + * - run single spec (execute each future) + */ +angular.scenario.SpecRunner = function() { + this.futures = []; +}; + +/** + * Executes a spec which is an it block with associated before/after functions + * based on the describe nesting. + * + * @param {Object} An angular.scenario.UI implementation + * @param {Object} A spec object + * @param {Object} An angular.scenario.Application instance + * @param {Function} Callback function that is called when the spec finshes. + */ +angular.scenario.SpecRunner.prototype.run = function(ui, spec, specDone) { + var specUI = ui.addSpec(spec); + + try { + spec.fn.call(this); + } catch (e) { + specUI.error(e); + specDone(); + return; + } + + asyncForEach( + this.futures, + function(future, futureDone) { + var stepUI = specUI.addStep(future.name); + try { + future.execute(function(error) { + stepUI.finish(error); + futureDone(error); + }); + } catch (e) { + stepUI.error(e); + rethrow(e); + } + }, + function(e) { + specUI.finish(e); + specDone(); + } + ); +}; + +/** + * Adds a new future action. + * + * @param {String} Name of the future + * @param {Function} Behavior of the future + */ +angular.scenario.SpecRunner.prototype.addFuture = function(name, behavior) { + var future = new angular.scenario.Future(name, angular.bind(this, behavior)); + this.futures.push(future); + return future; +}; + +/** + * Adds a new future action to be executed on the application window. + * + * @param {String} Name of the future + * @param {Function} Behavior of the future + */ +angular.scenario.SpecRunner.prototype.addFutureAction = function(name, behavior) { + return this.addFuture(name, function(done) { + this.application.executeAction(function() { + behavior.call(this, done); + }); + }); +}; |
