diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/scenario/Runner.js (renamed from src/test/Runner.js) | 51 | ||||
| -rw-r--r-- | src/scenario/Steps.js (renamed from src/test/Steps.js) | 6 | ||||
| -rw-r--r-- | src/scenario/_namespace.js | 6 | ||||
| -rw-r--r-- | src/scenario/bootstrap.js | 47 | ||||
| -rw-r--r-- | src/test/_namespace.js | 5 |
5 files changed, 86 insertions, 29 deletions
diff --git a/src/test/Runner.js b/src/scenario/Runner.js index c6684951..7caddc98 100644 --- a/src/test/Runner.js +++ b/src/scenario/Runner.js @@ -1,15 +1,16 @@ -if (typeof test == 'undefined') test = {}; - -test.ScenarioRunner = function(scenarios, body) { +var scenario = angular.scenario; +scenario.SuiteRunner = function(scenarios, body) { this.scenarios = scenarios; this.body = body; }; -test.ScenarioRunner.prototype = { +scenario.SuiteRunner.prototype = { run:function(){ this.setUpUI(); this.runScenarios(); }, + + setUpUI:function(){ this.body.html( '<div id="runner">' + @@ -24,23 +25,25 @@ test.ScenarioRunner.prototype = { jQuery(this).parent().find('.log').toggle(); }); }, + + runScenarios:function(){ - var runner = new test.Runner(this.console, this.testFrame); - _.stepper(this.scenarios, function(next, scenario, name){ - new test.Scenario(name, scenario).run(runner, next); + var runner = new scenario.Runner(this.console, this.testFrame); + _.stepper(this.scenarios, function(next, scenarioObj, name){ + new scenario.Scenario(name, scenarioObj).run(runner, next); }, function(){ } ); } }; -test.Runner = function(console, frame){ +scenario.Runner = function(console, frame){ this.console = console; this.current = null; this.tests = []; this.frame = frame; }; -test.Runner.prototype = { +scenario.Runner.prototype = { start:function(name){ var current = this.current = { name:name, @@ -86,11 +89,11 @@ test.Runner.prototype = { } }; -test.Scenario = function(name, scenario){ +scenario.Scenario = function(name, scenario){ this.name = name; this.scenario = scenario; }; -test.Scenario.prototype = { +scenario.Scenario.prototype = { run:function(runner, callback) { var self = this; _.stepper(this.scenario, function(next, steps, name){ @@ -108,16 +111,20 @@ test.Scenario.prototype = { } }, callback); }, + + verb:function(step){ var fn = null; - if (!step) fn = function (){ throw "Step is null!"; }; - else if (step.Given) fn = angular.test.GIVEN[step.Given]; - else if (step.When) fn = angular.test.WHEN[step.When]; - else if (step.Then) fn = angular.test.THEN[step.Then]; - return fn || function (){ - throw "ERROR: Need Given/When/Then got: " + toJson(step); - }; + if (!step) fn = function (){ throw "Step is null!"; }; + else if (step.Given) fn = scenario.GIVEN[step.Given]; + else if (step.When) fn = scenario.WHEN[step.When]; + else if (step.Then) fn = scenario.THEN[step.Then]; + return fn || function (){ + throw "ERROR: Need Given/When/Then got: " + toJson(step); + }; }, + + context: function(runner) { var frame = runner.frame; var window = frame[0].contentWindow; @@ -144,11 +151,13 @@ test.Scenario.prototype = { }; return context; }, + + executeStep:function(runner, step, callback) { if (!step) { - callback(); - return; - } + callback(); + return; + } runner.log("info", toJson(step)); var fn = this.verb(step); var context = this.context(runner); diff --git a/src/test/Steps.js b/src/scenario/Steps.js index cc9ff549..f8ac173f 100644 --- a/src/test/Steps.js +++ b/src/scenario/Steps.js @@ -1,4 +1,4 @@ -angular.test.GIVEN = { +angular.scenario.GIVEN = { browser:function(){ var self = this; if (jQuery.browser.safari && this.frame.attr('src') == this.at) { @@ -17,7 +17,7 @@ angular.test.GIVEN = { this.frame.name="$DATASET:" + toJson({dataset:this.dataset}); } }; -angular.test.WHEN = { +angular.scenario.WHEN = { enter:function(){ var element = this.element(this.at); element.attr('value', this.text); @@ -40,7 +40,7 @@ angular.test.WHEN = { element.change(); } }; -angular.test.THEN = { +angular.scenario.THEN = { text:function(){ var element = this.element(this.at); if (typeof this.should_be != undefined ) { diff --git a/src/scenario/_namespace.js b/src/scenario/_namespace.js new file mode 100644 index 00000000..7da3a5d8 --- /dev/null +++ b/src/scenario/_namespace.js @@ -0,0 +1,6 @@ +if (!angular) var angular = window['angular'] = {}; +if (!angular['scenario']) var angularScenario = angular['scenario'] = {}; +if (!angular['scenarioDef']) var scenarioDef = angular['scenarioDef'] = {}; +if (!angular['scenario']['GIVEN']) angularScenario['GIVEN'] = {}; +if (!angular['scenario']['WHEN']) angularScenario['WHEN'] = {}; +if (!angular['scenario']['THEN']) angularScenario['THEN'] = {}; diff --git a/src/scenario/bootstrap.js b/src/scenario/bootstrap.js new file mode 100644 index 00000000..1d40b9d0 --- /dev/null +++ b/src/scenario/bootstrap.js @@ -0,0 +1,47 @@ +(function(onLoadDelegate){ + var prefix = (function(){ + var filename = /(.*\/)bootstrap.js(#(.*))?/; + var scripts = document.getElementsByTagName("script"); + for(var j = 0; j < scripts.length; j++) { + var src = scripts[j].src; + if (src && src.match(filename)) { + var parts = src.match(filename); + return parts[1]; + } + } + })(); + function addScript(path) { + document.write('<script type="text/javascript" src="' + prefix + path + '"></script>'); + }; + function addCSS(path) { + document.write('<link rel="stylesheet" type="text/css" href="' + prefix + path + '"/>'); + }; + window.onload = function(){ + if (!_.stepper) { + _.stepper = function(collection, iterator, done){ + var keys = _.keys(collection); + function next() { + if (keys.length) { + var key = keys.shift(); + iterator(next, collection[key], key); + } else { + (done||_.identity)(); + } + } + next(); + }; + } + _.defer(function(){ + new angular.scenario.SuiteRunner(angular.scenarioDef, jQuery(document.body)).run(); + }); + (onLoadDelegate||function(){})(); + }; + addCSS("../../css/angular-scenario.css"); + addScript("../../lib/underscore/underscore.js"); + addScript("../../lib/jquery/jquery-1.3.2.js"); + addScript("../angular-bootstrap.js"); + addScript("_namespace.js"); + addScript("Steps.js"); + addScript("Runner.js"); +})(window.onload); + diff --git a/src/test/_namespace.js b/src/test/_namespace.js deleted file mode 100644 index e29ae72a..00000000 --- a/src/test/_namespace.js +++ /dev/null @@ -1,5 +0,0 @@ -if (!angular) var angular = window['angular'] = {}; -if (!angular['test']) var angularTest = angular['test'] = {}; -if (!angular['test']['GIVEN']) angularTest['GIVEN'] = {}; -if (!angular['test']['WHEN']) angularTest['WHEN'] = {}; -if (!angular['test']['THEN']) angularTest['THEN'] = {}; |
