').find(".log");
+ current.run.find(".name").text(name);
+ this.tests.push(current);
+ this.console.append(current.scenario);
+ },
+ end:function(name){
+ var current = this.current;
+ var run = current.run;
+ this.current = null;
+ current.end = new Date().getTime();
+ current.time = current.end - current.start;
+ run.find(".time").text(current.time);
+ run.find(".state").text(current.error ? "FAIL" : "PASS");
+ run.addClass(current.error ? "fail" : "pass");
+ if (current.error)
+ run.find(".run").append('
').text(current.error);
+ current.scenario.find(".log").hide();
+ },
+ log:function(level) {
+ var buf = [];
+ for ( var i = 1; i < arguments.length; i++) {
+ var arg = arguments[i];
+ buf.push(typeof arg == "string" ?arg:toJson(arg));
+ }
+ var log = jQuery('
');
+ log.text(buf.join(" "));
+ this.current.log.append(log);
+ this.console.scrollTop(this.console[0].scrollHeight);
+ if (level == "error")
+ this.current.error = buf.join(" ");
+ }
+};
+
+scenario.Scenario = function(name, scenario){
+ this.name = name;
+ this.scenario = scenario;
+};
+scenario.Scenario.prototype = {
+ run:function(runner, callback) {
+ var self = this;
+ _.stepper(this.scenario, function(next, steps, name){
+ if (name.charAt(0) == '$') {
+ next();
+ } else {
+ runner.start(self.name + "::" + name);
+ var allSteps = (self.scenario.$before||[]).concat(steps);
+ _.stepper(allSteps, function(next, step){
+ self.executeStep(runner, step, next);
+ }, function(){
+ runner.end();
+ next();
+ });
+ }
+ }, callback);
+ },
+
+
+ verb:function(step){
+ var fn = null;
+ 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;
+ var document;
+ if (window.jQuery)
+ document = window.jQuery(window.document);
+ var context = {
+ frame:frame,
+ window:window,
+ log:_.bind(runner.log, runner, "info"),
+ document:document,
+ assert:function(element, path){
+ if (element.size() != 1) {
+ throw "Expected to find '1' found '"+
+ element.size()+"' for '"+path+"'.";
+ }
+ return element;
+ },
+ element:function(path){
+ var exp = path.replace("{{","[ng-bind=").replace("}}", "]");
+ var element = document.find(exp);
+ return context.assert(element, path);
+ }
+ };
+ return context;
+ },
+
+
+ executeStep:function(runner, step, callback) {
+ if (!step) {
+ callback();
+ return;
+ }
+ runner.log("info", toJson(step));
+ var fn = this.verb(step);
+ var context = this.context(runner);
+ _.extend(context, step);
+ try {
+ (fn.call(context)||function(c){c();})(callback);
+ } catch (e) {
+ runner.log("error", "ERROR: " + toJson(e));
+ }
+ }
+};
--
cgit v1.2.3
From 5215e2095cfd42a0363eb02eded34e03fa2b0cd3 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Thu, 20 May 2010 15:55:41 -0700
Subject: basic end to end runner
---
src/scenario/Runner.js | 250 +++++++++++++++++++------------------------------
1 file changed, 94 insertions(+), 156 deletions(-)
(limited to 'src/scenario/Runner.js')
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 7caddc98..eeb4330d 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -1,171 +1,109 @@
-var scenario = angular.scenario;
-scenario.SuiteRunner = function(scenarios, body) {
- this.scenarios = scenarios;
- this.body = body;
-};
+angular['scenario'] = (angular['scenario'] = {});
-scenario.SuiteRunner.prototype = {
- run:function(){
- this.setUpUI();
- this.runScenarios();
- },
+angular.scenario.Runner = function(scope){
+ var self = scope.$scenario = this;
+ this.scope = scope;
+ var specs = this.specs = {};
+ var path = [];
+ this.scope.describe = function describe(name, body){
+ path.push(name);
+ body();
+ path.pop();
+ };
+ this.scope.it = function it(name, body) {
+ var specName = path.join(' ') + ': it ' + name;
+ self.currentSpec = specs[specName] = {
+ name: specName,
+ steps:[]
+ };
+ body();
+ self.currentSpec = null;
+ };
+ this.beginSpec = function returnNoop(){
+ return returnNoop;
+ };
+};
- setUpUI:function(){
- this.body.html(
+angular.scenario.Runner.prototype = {
+ run: function(body){
+ body.append(
'
');
- this.console = this.body.find(".console");
- this.testFrame = this.body.find("iframe");
- this.console.find(".run").live("click", function(){
- jQuery(this).parent().find('.log').toggle();
- });
- },
-
-
- runScenarios:function(){
- 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(){
- }
- );
- }
-};
-
-scenario.Runner = function(console, frame){
- this.console = console;
- this.current = null;
- this.tests = [];
- this.frame = frame;
-};
-scenario.Runner.prototype = {
- start:function(name){
- var current = this.current = {
- name:name,
- start:new Date().getTime(),
- scenario:jQuery('
')
+ var console = body.find('#runner .console');
+ this.testFrame = body.find('#testView iframe');
+ this.testWindow = this.testFrame[0].contentWindow;
+ this.beginSpec = function(name){
+ var specElement = jQuery('
');
+ console.append(specElement);
+ specElement.text(name);
+ specElement.append(stepContainer);
+ return function(name){
+ var stepElement = jQuery('
');
+ stepContainer.append(stepElement);
+ stepElement.text(name);
+ stepElement.append(logContainer);
+ return function(message) {
+ var logElement = jQuery('
');
+ logContainer.append(logElement);
+ logElement.text(message);
+ };
+ };
};
- current.run = current.scenario.append(
- '
' +
- '
.' +
- '
.' +
- '
.' +
- '').find(".run");
- current.log = current.scenario.append('
').find(".log");
- current.run.find(".name").text(name);
- this.tests.push(current);
- this.console.append(current.scenario);
- },
- end:function(name){
- var current = this.current;
- var run = current.run;
- this.current = null;
- current.end = new Date().getTime();
- current.time = current.end - current.start;
- run.find(".time").text(current.time);
- run.find(".state").text(current.error ? "FAIL" : "PASS");
- run.addClass(current.error ? "fail" : "pass");
- if (current.error)
- run.find(".run").append('
').text(current.error);
- current.scenario.find(".log").hide();
+ this.execute("widgets: it should verify that basic widgets work");
},
- log:function(level) {
- var buf = [];
- for ( var i = 1; i < arguments.length; i++) {
- var arg = arguments[i];
- buf.push(typeof arg == "string" ?arg:toJson(arg));
- }
- var log = jQuery('
');
- log.text(buf.join(" "));
- this.current.log.append(log);
- this.console.scrollTop(this.console[0].scrollHeight);
- if (level == "error")
- this.current.error = buf.join(" ");
- }
-};
-scenario.Scenario = function(name, scenario){
- this.name = name;
- this.scenario = scenario;
-};
-scenario.Scenario.prototype = {
- run:function(runner, callback) {
- var self = this;
- _.stepper(this.scenario, function(next, steps, name){
- if (name.charAt(0) == '$') {
- next();
- } else {
- runner.start(self.name + "::" + name);
- var allSteps = (self.scenario.$before||[]).concat(steps);
- _.stepper(allSteps, function(next, step){
- self.executeStep(runner, step, next);
- }, function(){
- runner.end();
- next();
- });
- }
- }, callback);
+ addStep: function(name, step) {
+ this.currentSpec.steps.push({name:name, fn:step});
},
-
- verb:function(step){
- var fn = null;
- 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);
+ execute: function(name, callback) {
+ var spec = this.specs[name],
+ result = {
+ passed: false,
+ failed: false,
+ finished: false,
+ fail: function(error) {
+ result.passed = false;
+ result.failed = true;
+ result.error = error;
+ result.log(angular.isString(error) ? error : angular.toJson(error));
+ }
+ };
+ specThis = {
+ result: result,
+ testWindow: this.testWindow,
+ testFrame: this.testFrame
};
- },
-
-
- context: function(runner) {
- var frame = runner.frame;
- var window = frame[0].contentWindow;
- var document;
- if (window.jQuery)
- document = window.jQuery(window.document);
- var context = {
- frame:frame,
- window:window,
- log:_.bind(runner.log, runner, "info"),
- document:document,
- assert:function(element, path){
- if (element.size() != 1) {
- throw "Expected to find '1' found '"+
- element.size()+"' for '"+path+"'.";
- }
- return element;
- },
- element:function(path){
- var exp = path.replace("{{","[ng-bind=").replace("}}", "]");
- var element = document.find(exp);
- return context.assert(element, path);
- }
- };
- return context;
- },
-
-
- executeStep:function(runner, step, callback) {
- if (!step) {
- callback();
- return;
- }
- runner.log("info", toJson(step));
- var fn = this.verb(step);
- var context = this.context(runner);
- _.extend(context, step);
- try {
- (fn.call(context)||function(c){c();})(callback);
- } catch (e) {
- runner.log("error", "ERROR: " + toJson(e));
- }
+ var beginStep = this.beginSpec(name);
+ spec.nextStepIndex = 0;
+ function done() {
+ result.finished = true;
+ (callback||angular.noop).call(specThis);
+ }
+ function next(){
+ var step = spec.steps[spec.nextStepIndex];
+ if (step) {
+ spec.nextStepIndex ++;
+ result.log = beginStep(step.name);
+ try {
+ step.fn.call(specThis, next);
+ } catch (e) {
+ result.fail(e);
+ done();
+ }
+ } else {
+ result.passed = !result.failed;
+ done();
+ }
+ };
+ next();
+ return specThis;
}
-};
+};
\ No newline at end of file
--
cgit v1.2.3
From e3368e12a6207706d8a08b18f9958db3b86ca4e5 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Thu, 20 May 2010 16:55:47 -0700
Subject: semi working state
---
src/scenario/Runner.js | 63 +++++++++++++++++++++++++++++++-------------------
1 file changed, 39 insertions(+), 24 deletions(-)
(limited to 'src/scenario/Runner.js')
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index eeb4330d..970d0c66 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -20,8 +20,8 @@ angular.scenario.Runner = function(scope){
body();
self.currentSpec = null;
};
- this.beginSpec = function returnNoop(){
- return returnNoop;
+ this.logger = function returnNoop(){
+ return angular.extend(returnNoop, {close:angular.noop, fail:angular.noop});;
};
};
@@ -29,33 +29,45 @@ angular.scenario.Runner.prototype = {
run: function(body){
body.append(
'
' +
'
' +
'' +
'
');
var console = body.find('#runner .console');
+ console.find('li').live('click', function(){
+ jQuery(this).toggleClass('collapsed');
+ });
this.testFrame = body.find('#testView iframe');
this.testWindow = this.testFrame[0].contentWindow;
- this.beginSpec = function(name){
- var specElement = jQuery('
');
- var stepContainer = jQuery('
');
- console.append(specElement);
- specElement.text(name);
- specElement.append(stepContainer);
- return function(name){
- var stepElement = jQuery('
');
- var logContainer = jQuery('
');
- stepContainer.append(stepElement);
- stepElement.text(name);
- stepElement.append(logContainer);
- return function(message) {
- var logElement = jQuery('
');
- logContainer.append(logElement);
- logElement.text(message);
- };
+ function logger(parent) {
+ var container;
+ return function(type, text) {
+ if (!container) {
+ container = jQuery('
');
+ parent.append(container);
+ }
+ var element = jQuery('
');
+ element.find('span').text(text);
+ container.append(element);
+ return angular.extend(logger(element), {
+ close: function(){
+ element.removeClass('running');
+ },
+ fail: function(){
+ element.removeClass('running');
+ var current = element;
+ while (current[0] != console[0]) {
+ if (current.is('li'))
+ current.addClass('fail');
+ current.removeClass('collapsed');
+ current = current.parent();
+ }
+ }
+ });;
};
- };
+ }
+ this.logger = logger(console);
this.execute("widgets: it should verify that basic widgets work");
},
@@ -73,7 +85,7 @@ angular.scenario.Runner.prototype = {
result.passed = false;
result.failed = true;
result.error = error;
- result.log(angular.isString(error) ? error : angular.toJson(error));
+ result.log('fail', angular.isString(error) ? error : angular.toJson(error)).fail();
}
};
specThis = {
@@ -81,17 +93,20 @@ angular.scenario.Runner.prototype = {
testWindow: this.testWindow,
testFrame: this.testFrame
};
- var beginStep = this.beginSpec(name);
+ var stepLogger = this.logger('spec', name);
spec.nextStepIndex = 0;
function done() {
result.finished = true;
+ stepLogger.close();
(callback||angular.noop).call(specThis);
}
function next(){
var step = spec.steps[spec.nextStepIndex];
+ (result.log || {close:angular.noop}).close();
+ result.log = null;
if (step) {
spec.nextStepIndex ++;
- result.log = beginStep(step.name);
+ result.log = stepLogger('step', step.name);
try {
step.fn.call(specThis, next);
} catch (e) {
--
cgit v1.2.3
From f6c67e28c94033edf6a16eb6508de54679cb49db Mon Sep 17 00:00:00 2001
From: Andres Ornelas Mesta
Date: Mon, 24 May 2010 13:54:32 -0700
Subject: happy
---
src/scenario/Runner.js | 44 +++++++++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 15 deletions(-)
(limited to 'src/scenario/Runner.js')
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 970d0c66..9e20d394 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -1,8 +1,9 @@
angular['scenario'] = (angular['scenario'] = {});
-angular.scenario.Runner = function(scope){
+angular.scenario.Runner = function(scope, jQuery){
var self = scope.$scenario = this;
this.scope = scope;
+ this.jQuery = jQuery;
var specs = this.specs = {};
var path = [];
@@ -27,6 +28,7 @@ angular.scenario.Runner = function(scope){
angular.scenario.Runner.prototype = {
run: function(body){
+ var jQuery = this.jQuery;
body.append(
'
' +
'
' +
@@ -68,7 +70,19 @@ angular.scenario.Runner.prototype = {
};
}
this.logger = logger(console);
- this.execute("widgets: it should verify that basic widgets work");
+ var specNames = [];
+ angular.foreach(this.specs, function(spec, name){
+ specNames.push(name);
+ }, this);
+ specNames.sort();
+ var self = this;
+ function callback(){
+ var next = specNames.shift();
+ if(next) {
+ self.execute(next, callback);
+ }
+ };
+ callback();
},
addStep: function(name, step) {
@@ -102,21 +116,21 @@ angular.scenario.Runner.prototype = {
}
function next(){
var step = spec.steps[spec.nextStepIndex];
- (result.log || {close:angular.noop}).close();
- result.log = null;
- if (step) {
- spec.nextStepIndex ++;
- result.log = stepLogger('step', step.name);
- try {
- step.fn.call(specThis, next);
- } catch (e) {
- result.fail(e);
- done();
- }
- } else {
- result.passed = !result.failed;
+ (result.log || {close:angular.noop}).close();
+ result.log = null;
+ if (step) {
+ spec.nextStepIndex ++;
+ result.log = stepLogger('step', step.name);
+ try {
+ step.fn.call(specThis, next);
+ } catch (e) {
+ result.fail(e);
done();
}
+ } else {
+ result.passed = !result.failed;
+ done();
+ }
};
next();
return specThis;
--
cgit v1.2.3
From 3fab5d9879272b9f991a67c8135754f00c055834 Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Mon, 24 May 2010 15:25:30 -0700
Subject: added error handling on scenario definition
---
src/scenario/Runner.js | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
(limited to 'src/scenario/Runner.js')
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 9e20d394..003ce487 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -1,9 +1,11 @@
-angular['scenario'] = (angular['scenario'] = {});
+angular['scenario'] = (angular['scenario'] = {});
+angular.scenario['dsl'] = (angular.scenario['dsl'] = {});
angular.scenario.Runner = function(scope, jQuery){
var self = scope.$scenario = this;
this.scope = scope;
this.jQuery = jQuery;
+ angular.extend(scope, angular.scenario.dsl);
var specs = this.specs = {};
var path = [];
@@ -18,7 +20,13 @@ angular.scenario.Runner = function(scope, jQuery){
name: specName,
steps:[]
};
- body();
+ try {
+ body();
+ } catch(err) {
+ self.addStep(err.message || 'ERROR', function(){
+ throw err;
+ });
+ }
self.currentSpec = null;
};
this.logger = function returnNoop(){
@@ -55,6 +63,7 @@ angular.scenario.Runner.prototype = {
return angular.extend(logger(element), {
close: function(){
element.removeClass('running');
+ console.scrollTop(console[0].scrollHeight);
},
fail: function(){
element.removeClass('running');
@@ -66,7 +75,7 @@ angular.scenario.Runner.prototype = {
current = current.parent();
}
}
- });;
+ });
};
}
this.logger = logger(console);
--
cgit v1.2.3
From 2cce1ffc15ae6483da9cf354f7a5d2d26317427e Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Tue, 25 May 2010 13:05:23 -0700
Subject: fixed collapsed issue
---
src/scenario/Runner.js | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'src/scenario/Runner.js')
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 003ce487..8669f56b 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -57,12 +57,14 @@ angular.scenario.Runner.prototype = {
container = jQuery('
');
parent.append(container);
}
- var element = jQuery('
');
+ var element = jQuery('
');
element.find('span').text(text);
container.append(element);
return angular.extend(logger(element), {
close: function(){
element.removeClass('running');
+ if(!element.hasClass('fail'))
+ element.addClass('collapsed');
console.scrollTop(console[0].scrollHeight);
},
fail: function(){
@@ -71,7 +73,6 @@ angular.scenario.Runner.prototype = {
while (current[0] != console[0]) {
if (current.is('li'))
current.addClass('fail');
- current.removeClass('collapsed');
current = current.parent();
}
}
--
cgit v1.2.3
From 5992e81b2e302c3b3375567e347227f6a9496585 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Tue, 25 May 2010 14:23:52 -0700
Subject: added rake task to create a single file for scenario runner
---
src/scenario/Runner.js | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'src/scenario/Runner.js')
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 8669f56b..01e16e79 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -1,11 +1,10 @@
-angular['scenario'] = (angular['scenario'] = {});
-angular.scenario['dsl'] = (angular.scenario['dsl'] = {});
+angular['scenario'] = angular['scenario'] || (angular['scenario'] = {});
+angular.scenario['dsl'] = angular.scenario['dsl'] || (angular.scenario['dsl'] = {});
angular.scenario.Runner = function(scope, jQuery){
var self = scope.$scenario = this;
this.scope = scope;
this.jQuery = jQuery;
- angular.extend(scope, angular.scenario.dsl);
var specs = this.specs = {};
var path = [];
@@ -30,7 +29,7 @@ angular.scenario.Runner = function(scope, jQuery){
self.currentSpec = null;
};
this.logger = function returnNoop(){
- return angular.extend(returnNoop, {close:angular.noop, fail:angular.noop});;
+ return _(returnNoop).extend({close:_.identity, fail:_.identity});;
};
};
@@ -60,7 +59,7 @@ angular.scenario.Runner.prototype = {
var element = jQuery('
');
element.find('span').text(text);
container.append(element);
- return angular.extend(logger(element), {
+ return _(logger(element)).extend({
close: function(){
element.removeClass('running');
if(!element.hasClass('fail'))
@@ -81,7 +80,7 @@ angular.scenario.Runner.prototype = {
}
this.logger = logger(console);
var specNames = [];
- angular.foreach(this.specs, function(spec, name){
+ _(this.specs).each(function(spec, name){
specNames.push(name);
}, this);
specNames.sort();
@@ -109,7 +108,7 @@ angular.scenario.Runner.prototype = {
result.passed = false;
result.failed = true;
result.error = error;
- result.log('fail', angular.isString(error) ? error : angular.toJson(error)).fail();
+ result.log('fail', _(error).isString() ? error : toJson(error)).fail();
}
};
specThis = {
@@ -122,11 +121,11 @@ angular.scenario.Runner.prototype = {
function done() {
result.finished = true;
stepLogger.close();
- (callback||angular.noop).call(specThis);
+ (callback||_.identity).call(specThis);
}
function next(){
var step = spec.steps[spec.nextStepIndex];
- (result.log || {close:angular.noop}).close();
+ (result.log || {close:_.identity}).close();
result.log = null;
if (step) {
spec.nextStepIndex ++;
@@ -134,6 +133,7 @@ angular.scenario.Runner.prototype = {
try {
step.fn.call(specThis, next);
} catch (e) {
+ console.error(e);
result.fail(e);
done();
}
--
cgit v1.2.3
From 0d41c86522ef912fe5bb7a02fd434080f9827c00 Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Wed, 26 May 2010 15:17:28 -0700
Subject: fixed broken jstd conf file
---
src/scenario/Runner.js | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
(limited to 'src/scenario/Runner.js')
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 01e16e79..68c3ff65 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -29,7 +29,7 @@ angular.scenario.Runner = function(scope, jQuery){
self.currentSpec = null;
};
this.logger = function returnNoop(){
- return _(returnNoop).extend({close:_.identity, fail:_.identity});;
+ return extend(returnNoop, {close:noop, fail:noop});;
};
};
@@ -59,7 +59,7 @@ angular.scenario.Runner.prototype = {
var element = jQuery('
');
element.find('span').text(text);
container.append(element);
- return _(logger(element)).extend({
+ return extend(logger(element), {
close: function(){
element.removeClass('running');
if(!element.hasClass('fail'))
@@ -80,7 +80,7 @@ angular.scenario.Runner.prototype = {
}
this.logger = logger(console);
var specNames = [];
- _(this.specs).each(function(spec, name){
+ foreach(this.specs, function(spec, name){
specNames.push(name);
}, this);
specNames.sort();
@@ -108,7 +108,7 @@ angular.scenario.Runner.prototype = {
result.passed = false;
result.failed = true;
result.error = error;
- result.log('fail', _(error).isString() ? error : toJson(error)).fail();
+ result.log('fail', isString(error) ? error : toJson(error)).fail();
}
};
specThis = {
@@ -121,11 +121,11 @@ angular.scenario.Runner.prototype = {
function done() {
result.finished = true;
stepLogger.close();
- (callback||_.identity).call(specThis);
+ (callback||noop).call(specThis);
}
function next(){
var step = spec.steps[spec.nextStepIndex];
- (result.log || {close:_.identity}).close();
+ (result.log || {close:noop}).close();
result.log = null;
if (step) {
spec.nextStepIndex ++;
--
cgit v1.2.3
From cb5d21192787985bbff20b369e885639de253345 Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Thu, 27 May 2010 11:26:23 -0700
Subject: extracted switchRouteMatcher and added necessary libraries to
angular-scenario
---
src/scenario/Runner.js | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
(limited to 'src/scenario/Runner.js')
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 68c3ff65..da6e2c39 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -48,7 +48,6 @@ angular.scenario.Runner.prototype = {
jQuery(this).toggleClass('collapsed');
});
this.testFrame = body.find('#testView iframe');
- this.testWindow = this.testFrame[0].contentWindow;
function logger(parent) {
var container;
return function(type, text) {
@@ -100,27 +99,30 @@ angular.scenario.Runner.prototype = {
execute: function(name, callback) {
var spec = this.specs[name],
+ self = this,
result = {
- passed: false,
- failed: false,
- finished: false,
- fail: function(error) {
- result.passed = false;
- result.failed = true;
- result.error = error;
- result.log('fail', isString(error) ? error : toJson(error)).fail();
- }
- };
- specThis = {
+ passed: false,
+ failed: false,
+ finished: false,
+ fail: function(error) {
+ result.passed = false;
+ result.failed = true;
+ result.error = error;
+ result.log('fail', isString(error) ? error : toJson(error)).fail();
+ }
+ },
+ specThis = createScope({
result: result,
- testWindow: this.testWindow,
- testFrame: this.testFrame
- };
+ testFrame: this.testFrame,
+ testWindow: this.testWindow
+ }, angularService, {});
+ this.self = specThis;
var stepLogger = this.logger('spec', name);
spec.nextStepIndex = 0;
function done() {
result.finished = true;
stepLogger.close();
+ self.self = null;
(callback||noop).call(specThis);
}
function next(){
--
cgit v1.2.3
From 85fac4d78c131771d7fdd46d6ccd44bae92419cd Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Wed, 9 Jun 2010 14:12:54 -0700
Subject: add beforeEach and afterEach to scenario DSL
---
src/scenario/Runner.js | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
(limited to 'src/scenario/Runner.js')
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index da6e2c39..8e0cc909 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -8,23 +8,34 @@ angular.scenario.Runner = function(scope, jQuery){
var specs = this.specs = {};
var path = [];
- this.scope.describe = function describe(name, body){
+ this.scope.describe = function(name, body){
path.push(name);
body();
path.pop();
};
- this.scope.it = function it(name, body) {
+ var beforeEach = noop;
+ var afterEach = noop;
+ this.scope.beforeEach = function(body) {
+ beforeEach = body;
+ };
+ this.scope.afterEach = function(body) {
+ afterEach = body;
+ };
+ this.scope.it = function(name, body) {
var specName = path.join(' ') + ': it ' + name;
self.currentSpec = specs[specName] = {
name: specName,
steps:[]
};
try {
+ beforeEach();
body();
} catch(err) {
self.addStep(err.message || 'ERROR', function(){
throw err;
});
+ } finally {
+ afterEach();
}
self.currentSpec = null;
};
--
cgit v1.2.3