Merge branch 'master' of github.com:angular/angular.js

This commit is contained in:
Misko Hevery 2010-08-10 11:46:37 -07:00
commit 8d635cfb87
9 changed files with 343 additions and 164 deletions

View file

@ -45,8 +45,10 @@ task :compile_scenario do
src/apis.js \ src/apis.js \
src/services.js \ src/services.js \
src/AngularPublic.js \ src/AngularPublic.js \
src/scenario/Runner.js \
src/scenario/DSL.js \ src/scenario/DSL.js \
src/scenario/Future.js \
src/scenario/Matcher.js \
src/scenario/Runner.js \
src/scenario/angular.suffix \ src/scenario/angular.suffix \
) )
css = %x(cat css/angular-scenario.css) css = %x(cat css/angular-scenario.css)

View file

@ -1,13 +1,14 @@
angular.scenario.dsl.browser = { angular.scenario.dsl.browser = {
navigateTo: function(url){ navigateTo: function(url){
$scenario.addStep('Navigate to: ' + url, function(done){ return $scenario.addFuture('Navigate to: ' + url, function(done){
var self = this; var self = this;
this.testFrame.load(function(){ this.testFrame.load(function(){
self.testFrame.unbind(); self.testFrame.unbind();
self.testWindow = self.testFrame[0].contentWindow; self.testWindow = self.testFrame[0].contentWindow;
self.testDocument = jQuery(self.testWindow.document); self.testDocument = self.jQuery(self.testWindow.document);
self.$browser = self.testWindow.angular.service.$browser(); self.$browser = self.testWindow.angular.service.$browser();
self.notifyWhenNoOutstandingRequests = bind(self.$browser, self.$browser.notifyWhenNoOutstandingRequests); self.notifyWhenNoOutstandingRequests =
bind(self.$browser, self.$browser.notifyWhenNoOutstandingRequests);
self.notifyWhenNoOutstandingRequests(done); self.notifyWhenNoOutstandingRequests(done);
}); });
if (this.testFrame.attr('src') == url) { if (this.testFrame.attr('src') == url) {
@ -20,19 +21,18 @@ angular.scenario.dsl.browser = {
}; };
angular.scenario.dsl.input = function(selector) { angular.scenario.dsl.input = function(selector) {
var namePrefix = "input '" + selector + "'";
return { return {
enter: function(value){ enter: function(value) {
$scenario.addStep("Set input text of '" + selector + "' to '" + return $scenario.addFuture(namePrefix + " enter '" + value + "'", function(done) {
value + "'", function(done){ var input = this.testDocument.find('input[name=' + selector + ']');
var input = this.testDocument.find('input[name=' + selector + ']'); input.val(value);
input.val(value); this.testWindow.angular.element(input[0]).trigger('change');
this.testWindow.angular.element(input[0]).trigger('change'); done();
done();
}); });
}, },
select: function(value){ select: function(value) {
$scenario.addStep("Select radio '" + selector + "' to '" + return $scenario.addFuture(namePrefix + " select '" + value + "'", function(done) {
value + "'", function(done){
var input = this.testDocument. var input = this.testDocument.
find(':radio[name$=@' + selector + '][value=' + value + ']'); find(':radio[name$=@' + selector + '][value=' + value + ']');
jqLiteWrap(input[0]).trigger('click'); jqLiteWrap(input[0]).trigger('click');
@ -41,22 +41,56 @@ angular.scenario.dsl.input = function(selector) {
}); });
} }
}; };
},
angular.scenario.dsl.repeater = function(selector) {
var namePrefix = "repeater '" + selector + "'";
return {
count: function() {
return $scenario.addFuture(namePrefix + ' count', function(done) {
done(this.testDocument.find(selector).size());
});
},
collect: function() {
return $scenario.addFuture(namePrefix + ' collect', function(done) {
var self = this;
var doCollect = bind(this, function() {
var repeaterArray = [];
this.testDocument.find(selector).each(function(index) {
var element = angular.extend(self.jQuery(this),
{bindings: [],
boundTo: function(name) { return this.bindings[name]; }}
);
element.find('*').each(function(index) {
var bindName = self.jQuery(this).attr('ng:bind');
if (bindName) {
element.bindings[bindName] = self.jQuery(this).text();
}
});
repeaterArray[index] = element;
});
return repeaterArray;
});
done(doCollect());
});
}
};
}; };
angular.scenario.dsl.expect = { angular.scenario.dsl.element = function(selector) {
repeater: function(selector) { var nameSuffix = "element '" + selector + "'";
return { return $scenario.addFuture('Find ' + nameSuffix, function(done) {
count: { var self = this;
toEqual: function(number) { var element = angular.extend(this.testDocument.find(selector), {
$scenario.addStep("Expect that there are " + number + " items in Repeater with selector '" + selector + "'", function(done) { bindings: [],
var items = this.testDocument.find(selector); boundTo: function(name) { return this.bindings[name]; }
if (items.length != number) { });
this.result.fail("Expected " + number + " but was " + items.length); element.find('*').each(function(index) {
} var bindName = self.jQuery(this).attr('ng:bind');
done(); if (bindName) {
}); element.bindings[bindName] = self.jQuery(this).text();
}
} }
}; });
} done(element);
});
}; };

13
src/scenario/Future.js Normal file
View file

@ -0,0 +1,13 @@
function Future(name, behavior) {
this.name = name;
this.behavior = behavior;
this.fulfilled = false;
this.value = undefined;
}
Future.prototype = {
fulfill: function(value) {
this.fulfilled = true;
this.value = value;
}
};

21
src/scenario/Matcher.js Normal file
View file

@ -0,0 +1,21 @@
function Matcher(scope, future, logger) {
var self = scope.$scenario = 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; });

View file

@ -8,6 +8,7 @@ angular.scenario.Runner = function(scope, jQuery){
this.scope.$testrun = {done: false, results: []}; this.scope.$testrun = {done: false, results: []};
var specs = this.specs = {}; var specs = this.specs = {};
this.currentSpec = {name: '', futures: []};
var path = []; var path = [];
this.scope.describe = function(name, body){ this.scope.describe = function(name, body){
path.push(name); path.push(name);
@ -22,17 +23,20 @@ angular.scenario.Runner = function(scope, jQuery){
this.scope.afterEach = function(body) { this.scope.afterEach = function(body) {
afterEach = body; afterEach = body;
}; };
this.scope.expect = function(future) {
return new Matcher(self, future, self.logger);
};
this.scope.it = function(name, body) { this.scope.it = function(name, body) {
var specName = path.join(' ') + ': it ' + name; var specName = path.join(' ') + ': it ' + name;
self.currentSpec = specs[specName] = { self.currentSpec = specs[specName] = {
name: specName, name: specName,
steps:[] futures: []
}; };
try { try {
beforeEach(); beforeEach();
body(); body();
} catch(err) { } catch(err) {
self.addStep(err.message || 'ERROR', function(){ self.addFuture(err.message || 'ERROR', function(){
throw err; throw err;
}); });
} finally { } finally {
@ -107,14 +111,16 @@ angular.scenario.Runner.prototype = {
callback(); callback();
}, },
addStep: function(name, step) { addFuture: function(name, behavior) {
this.currentSpec.steps.push({name:name, fn:step}); var future = new Future(name, behavior);
this.currentSpec.futures.push(future);
return future;
}, },
execute: function(name, callback) { execute: function(name, callback) {
var spec = this.specs[name], var spec = this.specs[name],
self = this, self = this,
stepsDone = [], futuresFulfilled = [],
result = { result = {
passed: false, passed: false,
failed: false, failed: false,
@ -128,33 +134,37 @@ angular.scenario.Runner.prototype = {
}, },
specThis = createScope({ specThis = createScope({
result: result, result: result,
jQuery: this.jQuery,
testFrame: this.testFrame, testFrame: this.testFrame,
testWindow: this.testWindow testWindow: this.testWindow
}, angularService, {}); }, angularService, {});
this.self = specThis; this.self = specThis;
var stepLogger = this.logger('spec', name); var futureLogger = this.logger('spec', name);
spec.nextStepIndex = 0; spec.nextFutureIndex = 0;
function done() { function done() {
result.finished = true; result.finished = true;
stepLogger.close(); futureLogger.close();
self.self = null; self.self = null;
(callback||noop).call(specThis); (callback||noop).call(specThis);
} }
function next(){ function next(value){
var step = spec.steps[spec.nextStepIndex]; if (spec.nextFutureIndex > 0) {
spec.futures[spec.nextFutureIndex - 1].fulfill(value);
}
var future = spec.futures[spec.nextFutureIndex];
(result.log || {close:noop}).close(); (result.log || {close:noop}).close();
result.log = null; result.log = null;
if (step) { if (future) {
spec.nextStepIndex ++; spec.nextFutureIndex ++;
result.log = stepLogger('step', step.name); result.log = futureLogger('future', future.name);
stepsDone.push(step.name); futuresFulfilled.push(future.name);
try { try {
step.fn.call(specThis, next); future.behavior.call(specThis, next);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
result.fail(e); result.fail(e);
self.scope.$testrun.results.push( self.scope.$testrun.results.push(
{name: name, passed: false, error: e, steps: stepsDone}); {name: name, passed: false, error: e, steps: futuresFulfilled});
done(); done();
} }
} else { } else {
@ -163,7 +173,7 @@ angular.scenario.Runner.prototype = {
name: name, name: name,
passed: !result.failed, passed: !result.failed,
error: result.error, error: result.error,
steps: stepsDone}); steps: futuresFulfilled});
done(); done();
} }
}; };

View file

@ -1,39 +1,37 @@
describe("DSL", function() { describe("DSL", function() {
var lastStep, executeStep, lastDocument; var lastDocument, executeFuture, Expect;
beforeEach(function() { beforeEach(function() {
lastStep = null; setUpContext();
$scenario = { executeFuture = function(future, html, callback) {
addStep: function(name, stepFunction) { lastDocument = _jQuery('<div>' + html + '</div>');
lastStep = { name:name, fn: stepFunction};
}
};
executeStep = function(step, html, callback) {
lastDocument =_jQuery('<div>' + html + '</div>');
_jQuery(document.body).append(lastDocument); _jQuery(document.body).append(lastDocument);
var specThis = { var specThis = {
testWindow: window, testWindow: window,
testDocument: lastDocument testDocument: lastDocument,
jQuery: _jQuery
}; };
step.fn.call(specThis, callback || noop); future.behavior.call(specThis, callback || noop);
}; };
Expect = _window.expect;
}); });
describe("input", function() { describe("input", function() {
var input = angular.scenario.dsl.input; var input = angular.scenario.dsl.input;
it('should enter', function() { it('should enter', function() {
input('name').enter('John'); var future = input('name').enter('John');
expect(lastStep.name).toEqual("Set input text of 'name' to 'John'"); expect(future.name).toEqual("input 'name' enter 'John'");
executeStep(lastStep, '<input type="text" name="name" />'); executeFuture(future, '<input type="text" name="name" />');
expect(lastDocument.find('input').val()).toEqual('John'); expect(lastDocument.find('input').val()).toEqual('John');
}); });
it('should select', function() { it('should select', function() {
input('gender').select('female'); var future = input('gender').select('female');
expect(lastStep.name).toEqual("Select radio 'gender' to 'female'"); expect(future.name).toEqual("input 'gender' select 'female'");
executeStep(lastStep, executeFuture(future,
'<input type="radio" name="0@gender" value="male" checked/>' + '<input type="radio" name="0@gender" value="male" checked/>' +
'<input type="radio" name="0@gender" value="female"/>'); '<input type="radio" name="0@gender" value="female"/>');
expect(lastDocument.find(':radio:checked').length).toEqual(1); expect(lastDocument.find(':radio:checked').length).toEqual(1);
@ -41,15 +39,80 @@ describe("DSL", function() {
}); });
}); });
describe('expect', function() { describe('repeater', function() {
var dslExpect = angular.scenario.dsl.expect;
describe('repeater', function() { var repeater = angular.scenario.dsl.repeater;
it('should check the count of repeated elements', function() { it('should count', function() {
dslExpect.repeater('.repeater-row').count.toEqual(2); var future = repeater('.repeater-row').count();
expect(lastStep.name).toEqual("Expect that there are 2 items in Repeater with selector '.repeater-row'"); expect(future.name).toEqual("repeater '.repeater-row' count");
var html = "<div class='repeater-row'>a</div><div class='repeater-row'>b</div>"; executeFuture(future,
executeStep(lastStep, html); "<div class='repeater-row'>a</div>" +
"<div class='repeater-row'>b</div>",
function(value) {
future.fulfill(value);
}); });
expect(future.fulfilled).toBeTruthy();
expect(future.value).toEqual(2);
});
it('should collect', function() {
var future = repeater('.epic').collect();
expect(future.name).toEqual("repeater '.epic' collect");
executeFuture(future,
"<table>" +
"<tr class='epic'>" +
"<td ng:bind='hero'>John Marston</td>" +
"<td ng:bind='game'>Red Dead Redemption</td>" +
"</tr>" +
"<tr class='epic'>" +
"<td ng:bind='hero'>Nathan Drake</td>" +
"<td ng:bind='game'>Uncharted 2</td>" +
"</tr>" +
"</table>",
function(value) {
future.fulfill(value);
});
expect(future.fulfilled).toBeTruthy();
expect(future.value[0].boundTo('hero')).toEqual('John Marston');
expect(future.value[0].boundTo('game')).toEqual('Red Dead Redemption');
expect(future.value[1].boundTo('hero')).toEqual('Nathan Drake');
expect(future.value[1].boundTo('game')).toEqual('Uncharted 2');
});
});
describe('element', function() {
var element = angular.scenario.dsl.element;
var html;
beforeEach(function() {
html = '<div class="container">' +
'<table class="reports-detail">' +
'<span class="desc">Description : ' +
'<span ng:bind="report.description">Details...</span>' +
'</span>' +
'<span>Date created: ' +
'<span ng:bind="report.creationDate">01/01/01</span>' +
'</span>' +
'</table>' +
'</div>';
});
it('should find elements on the page and provide jquery api', function() {
var future = element('.reports-detail');
expect(future.name).toEqual("Find element '.reports-detail'");
executeFuture(future, html, function(value) { future.fulfill(value); });
expect(future.fulfilled).toBeTruthy();
expect(future.value.text()).
toEqual('Description : Details...Date created: 01/01/01');
expect(future.value.find('.desc').text()).
toEqual('Description : Details...');
});
it('should know how to find ng:bind elements on page', function() {
var future = element('.reports-detail');
expect(future.name).toEqual("Find element '.reports-detail'");
executeFuture(future, html, function(value) { future.fulfill(value); });
expect(future.fulfilled).toBeTruthy();
expect(future.value.boundTo('report.description')).toEqual('Details...');
expect(future.value.boundTo('report.creationDate')).toEqual('01/01/01');
expect(future.value.boundTo('doesnotexist')).not.toBeDefined();
}); });
}); });
}); });

View file

@ -0,0 +1,30 @@
describe('Matcher', function () {
function executeFutures() {
for(var i in $scenario.currentSpec.futures) {
var future = $scenario.currentSpec.futures[i];
future.behavior.call({}, function(value) { future.fulfill(value); });
}
}
var matcher;
beforeEach(function() {
setUpContext();
var future = $scenario.addFuture('Calculate first future', function(done) {
done(123);
});
matcher = new Matcher(this, future);
});
it('should correctly match toEqual', function() {
matcher.toEqual(123);
executeFutures();
});
it('should throw an error when incorrect match toEqual', function() {
matcher.toEqual(456);
try {
executeFutures();
fail();
} catch (e) {
expect(e).toEqual('Expected 456 but was 123');
}
});
});

View file

@ -1,40 +1,30 @@
describe('Runner', function(){ describe('Runner', function() {
var scenario, runner, log, Describe, It, $scenario, body;
function logger(text) { var Describe, It, BeforeEach, AfterEach, body;
return function(done){
log += text;
(done||noop)();
};
}
beforeEach(function(){ beforeEach(function() {
log = ''; setUpContext();
scenario = {}; Describe = _window.describe;
It = _window.it;
BeforeEach = _window.beforeEach;
AfterEach = _window.afterEach;
body = _jQuery('<div></div>'); body = _jQuery('<div></div>');
runner = new angular.scenario.Runner(scenario, _jQuery);
Describe = scenario.describe;
BeforeEach = scenario.beforeEach;
AfterEach = scenario.afterEach;
It = scenario.it;
$scenario = scenario.$scenario;
}); });
describe('describe', function(){ describe('describe', function() {
it('should consume the describe functions', function(){ it('should consume the describe functions', function() {
Describe('describe name', logger('body')); Describe('describe name', logger('body'));
expect(log).toEqual('body'); expect(log).toEqual('body');
}); });
describe('it', function(){ describe('it', function() {
it('should consume it', function(){ it('should consume it', function() {
Describe('describe name', function(){ Describe('describe name', function() {
It('should text', logger('body')); It('should text', logger('body'));
}); });
expect(log).toEqual('body'); expect(log).toEqual('body');
var spec = $scenario.specs['describe name: it should text']; var spec = $scenario.specs['describe name: it should text'];
expect(spec.steps).toEqual([]); expect(spec.futures).toEqual([]);
expect(spec.name).toEqual('describe name: it should text'); expect(spec.name).toEqual('describe name: it should text');
}); });
@ -42,18 +32,18 @@ describe('Runner', function(){
// WRITE ME!!!! // WRITE ME!!!!
}); });
it('should create a failing step if there is a javascript error', function(){ it('should create a failing future if there is a javascript error', function() {
var spec; var spec;
Describe('D1', function(){ Describe('D1', function() {
It('I1', function(){ It('I1', function() {
spec = $scenario.currentSpec; spec = $scenario.currentSpec;
throw {message: 'blah'}; throw {message: 'blah'};
}); });
}); });
var step = spec.steps[0]; var future = spec.futures[0];
expect(step.name).toEqual('blah'); expect(future.name).toEqual('blah');
try { try {
step.fn(); future.behavior();
fail(); fail();
} catch (e) { } catch (e) {
expect(e.message).toEqual('blah'); expect(e.message).toEqual('blah');
@ -63,7 +53,7 @@ describe('Runner', function(){
describe('beforeEach', function() { describe('beforeEach', function() {
it('should execute beforeEach before every it', function() { it('should execute beforeEach before every it', function() {
Describe('describe name', function(){ Describe('describe name', function() {
BeforeEach(logger('before;')); BeforeEach(logger('before;'));
It('should text', logger('body;')); It('should text', logger('body;'));
It('should text2', logger('body2;')); It('should text2', logger('body2;'));
@ -73,7 +63,7 @@ describe('Runner', function(){
}); });
describe('afterEach', function() { describe('afterEach', function() {
it('should execute afterEach after every it', function() { it('should execute afterEach after every it', function() {
Describe('describe name', function(){ Describe('describe name', function() {
AfterEach(logger('after;')); AfterEach(logger('after;'));
It('should text1', logger('body1;')); It('should text1', logger('body1;'));
It('should text2', logger('body2;')); It('should text2', logger('body2;'));
@ -82,7 +72,7 @@ describe('Runner', function(){
}); });
it('should always execute afterEach after every it', function() { it('should always execute afterEach after every it', function() {
Describe('describe name', function(){ Describe('describe name', function() {
AfterEach(logger('after;')); AfterEach(logger('after;'));
It('should text', function() { It('should text', function() {
logger('body1;')(); logger('body1;')();
@ -95,62 +85,63 @@ describe('Runner', function(){
it('should report an error if afterEach fails', function() { it('should report an error if afterEach fails', function() {
var next; var next;
Describe('describe name', function(){ Describe('describe name', function() {
AfterEach(function() { AfterEach(function() {
$scenario.addStep('afterEachLog', logger('after;')); $scenario.addFuture('afterEachLog', logger('after;'));
$scenario.addStep('afterEachThrow', function() { $scenario.addFuture('afterEachThrow', function() {
throw "AfterError"; throw "AfterError";
}); });
}); });
It('should text1', function() { It('should text1', function() {
$scenario.addStep('step1', logger('step1;')); $scenario.addFuture('future1', logger('future1;'));
}); });
It('should text2', function() { It('should text2', function() {
$scenario.addStep('step2', logger('step2;')); $scenario.addFuture('future2', logger('future2;'));
}); });
}); });
$scenario.run(body); $scenario.run(body);
expect(log).toEqual('step1;after;step2;after;'); expect(log).toEqual('future1;after;future2;after;');
expect(scenario.$testrun.results).toEqual([ expect(_window.$testrun.results).toEqual([
{ name : 'describe name: it should text1', { name : 'describe name: it should text1',
passed : false, passed : false,
error : 'AfterError', error : 'AfterError',
steps : [ 'step1', 'afterEachLog', 'afterEachThrow' ] }, steps : [ 'future1', 'afterEachLog', 'afterEachThrow' ] },
{ name : 'describe name: it should text2', { name : 'describe name: it should text2',
passed : false, passed : false,
error : 'AfterError', error : 'AfterError',
steps : [ 'step2', 'afterEachLog', 'afterEachThrow' ] }]); steps : [ 'future2', 'afterEachLog', 'afterEachThrow' ] }]);
}); });
}); });
}); });
describe('steps building', function(){ describe('future building', function() {
it('should queue steps', function(){ it('should queue futures', function() {
function step(){}; function behavior(){};
Describe('name', function(){ Describe('name', function() {
It('should', function(){ It('should', function() {
$scenario.addStep('stepname', step); $scenario.addFuture('futureName', behavior);
}); });
}); });
expect($scenario.specs['name: it should'].steps).toEqual([{name:'stepname', fn:step}]); expect($scenario.specs['name: it should'].futures[0].name).
toEqual('futureName');
}); });
}); });
describe('execution', function(){ describe('execution', function() {
it('should execute the queued steps', function(){ it('should execute the queued futures', function() {
var next, firstThis, secondThis, doneThis, spec; var next, firstThis, secondThis, doneThis, spec;
$scenario.specs['spec'] = { $scenario.specs['spec'] = {
steps: [ futures: [
{name:'step1', fn: function(done) { new Future('future1', function(done) {
next = done; next = done;
log += 'first;'; log += 'first;';
firstThis = this; firstThis = this;
}}, }),
{name:'step2', fn:function(done){ new Future('future2', function(done) {
next = done; next = done;
log += 'second;'; log += 'second;';
secondThis = this; secondThis = this;
}} })
] ]
}; };
@ -174,18 +165,18 @@ describe('Runner', function(){
expect(spec.result.passed).toEqual(true); expect(spec.result.passed).toEqual(true);
}); });
it('should handle exceptions in a step', function(){ it('should handle exceptions in a future', function() {
$scenario.specs['spec'] = { $scenario.specs['spec'] = {
steps: [ futures: [
{name: 'first step', fn: function(done) { new Future('first future', function(done) {
done(); done();
}}, }),
{name:'error', fn:function(done) { new Future('error', function(done) {
throw "MyError"; throw "MyError";
}}, }),
{name: 'should not execute', fn: function(done) { new Future('should not execute', function(done) {
done(); done();
}} })
] ]
}; };
@ -195,30 +186,30 @@ describe('Runner', function(){
expect(spec.result.failed).toEqual(true); expect(spec.result.failed).toEqual(true);
expect(spec.result.finished).toEqual(true); expect(spec.result.finished).toEqual(true);
expect(spec.result.error).toEqual("MyError"); expect(spec.result.error).toEqual("MyError");
expect(scenario.$testrun.results).toEqual([{ expect(_window.$testrun.results).toEqual([{
name: 'spec', name: 'spec',
passed: false, passed: false,
error: 'MyError', error: 'MyError',
steps: ['first step', 'error']}]); steps: ['first future', 'error']}]);
}); });
}); });
describe('run', function(){ describe('run', function() {
var next; var next;
beforeEach(function() { beforeEach(function() {
Describe('d1', function(){ Describe('d1', function() {
It('it1', function(){ $scenario.addStep('s1', logger('s1,')); }); It('it1', function() { $scenario.addFuture('s1', logger('s1,')); });
It('it2', function(){ It('it2', function() {
$scenario.addStep('s2', logger('s2,')); $scenario.addFuture('s2', logger('s2,'));
$scenario.addStep('s2.2', function(done){ next = done; }); $scenario.addFuture('s2.2', function(done){ next = done; });
}); });
}); });
Describe('d2', function(){ Describe('d2', function() {
It('it3', function(){ $scenario.addStep('s3', logger('s3,')); }); It('it3', function() { $scenario.addFuture('s3', logger('s3,')); });
It('it4', function(){ $scenario.addStep('s4', logger('s4,')); }); It('it4', function() { $scenario.addFuture('s4', logger('s4,')); });
}); });
}); });
it('should execute all specs', function(){ it('should execute all specs', function() {
$scenario.run(body); $scenario.run(body);
expect(log).toEqual('s1,s2,'); expect(log).toEqual('s1,s2,');
@ -226,20 +217,20 @@ describe('Runner', function(){
expect(log).toEqual('s1,s2,s3,s4,'); expect(log).toEqual('s1,s2,s3,s4,');
}); });
it('should publish done state and results as tests are run', function() { it('should publish done state and results as tests are run', function() {
expect(scenario.$testrun.done).toBeFalsy(); expect(_window.$testrun.done).toBeFalsy();
expect(scenario.$testrun.results).toEqual([]); expect(_window.$testrun.results).toEqual([]);
$scenario.run(body); $scenario.run(body);
expect(scenario.$testrun.done).toBeFalsy(); expect(_window.$testrun.done).toBeFalsy();
expect(scenario.$testrun.results).toEqual([ expect(_window.$testrun.results).toEqual([
{name: 'd1: it it1', passed: true, steps: ['s1']} {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']}
]); ]);
next(); next();
expect(scenario.$testrun.done).toBeTruthy(); expect(_window.$testrun.done).toBeTruthy();
expect(scenario.$testrun.results).toEqual([ expect(_window.$testrun.results).toEqual([
{name: 'd1: it it1', passed: true, steps: ['s1']}, {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']},
{name: 'd1: it it2', passed: true, steps: ['s2', 's2.2']}, {name: 'd1: it it2', passed: true, error: undefined, steps: ['s2', 's2.2']},
{name: 'd2: it it3', passed: true, steps: ['s3']}, {name: 'd2: it it3', passed: true, error: undefined, steps: ['s3']},
{name: 'd2: it it4', passed: true, steps: ['s4']} {name: 'd2: it it4', passed: true, error: undefined, steps: ['s4']}
]); ]);
}); });
}); });

View file

@ -0,0 +1,15 @@
var _window, runner, log, $scenario;
function logger(text) {
return function(done){
log += text;
(done||noop)();
};
}
function setUpContext() {
_window = {};
runner = new angular.scenario.Runner(_window, _jQuery);
$scenario = _window.$scenario;
log = '';
}