From e664186f93838ca1fb1b2e4277f7c18264f81d92 Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Tue, 29 Jun 2010 15:43:02 -0700
Subject: initial concept
---
src/scenario/Future.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 src/scenario/Future.js
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);
+}
--
cgit v1.2.3
From 9d8646b0d1bee2ca60bbb7b494b63ab83e243072 Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Wed, 30 Jun 2010 09:51:54 -0700
Subject: all tests passing with new futures concept
---
src/scenario/DSL.js | 8 ++--
src/scenario/Future.js | 45 +++++++++++----------
src/scenario/Runner.js | 39 ++++++++++--------
test/scenario/DSLSpec.js | 24 +++++------
test/scenario/RunnerSpec.js | 97 +++++++++++++++++++++++----------------------
5 files changed, 111 insertions(+), 102 deletions(-)
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js
index 194a28d6..bcf2b6c5 100644
--- a/src/scenario/DSL.js
+++ b/src/scenario/DSL.js
@@ -1,6 +1,6 @@
angular.scenario.dsl.browser = {
navigateTo: function(url){
- $scenario.addStep('Navigate to: ' + url, function(done){
+ $scenario.addFuture('Navigate to: ' + url, function(done){
var self = this;
this.testFrame.load(function(){
self.testFrame.unbind();
@@ -22,7 +22,7 @@ angular.scenario.dsl.browser = {
angular.scenario.dsl.input = function(selector) {
return {
enter: function(value){
- $scenario.addStep("Set input text of '" + selector + "' to '" +
+ $scenario.addFuture("Set input text of '" + selector + "' to '" +
value + "'", function(done){
var input = this.testDocument.find('input[name=' + selector + ']');
input.val(value);
@@ -31,7 +31,7 @@ angular.scenario.dsl.input = function(selector) {
});
},
select: function(value){
- $scenario.addStep("Select radio '" + selector + "' to '" +
+ $scenario.addFuture("Select radio '" + selector + "' to '" +
value + "'", function(done){
var input = this.testDocument.
find(':radio[name$=@' + selector + '][value=' + value + ']');
@@ -49,7 +49,7 @@ angular.scenario.dsl.expect = {
return {
count: {
toEqual: function(number) {
- $scenario.addStep("Expect that there are " + number + " items in Repeater with selector '" + selector + "'", function(done) {
+ $scenario.addFuture("Expect that there are " + number + " items in Repeater with selector '" + selector + "'", function(done) {
var items = this.testDocument.find(selector);
if (items.length != number) {
this.result.fail("Expected " + number + " but was " + items.length);
diff --git a/src/scenario/Future.js b/src/scenario/Future.js
index 057b89db..c718bba2 100644
--- a/src/scenario/Future.js
+++ b/src/scenario/Future.js
@@ -1,8 +1,8 @@
function Future(name, behavior) {
- this.value = undefined;
this.name = name;
this.behavior = behavior;
this.fulfilled = false;
+ this.value = undefined;
}
Future.prototype = {
@@ -11,25 +11,6 @@ Future.prototype = {
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;
@@ -52,6 +33,28 @@ Matcher.addMatcher = function(name, matcher){
Matcher.addMatcher('toEqual', function(a,b){ return a == b; });
-function expect(future) {
+/*
+
+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 expectX(future) {
return new Matcher(future, window.alert);
}
+
+ */
\ No newline at end of file
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 13ba5af0..c77239cc 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -26,13 +26,13 @@ angular.scenario.Runner = function(scope, jQuery){
var specName = path.join(' ') + ': it ' + name;
self.currentSpec = specs[specName] = {
name: specName,
- steps:[]
+ futures: []
};
try {
beforeEach();
body();
} catch(err) {
- self.addStep(err.message || 'ERROR', function(){
+ self.addFuture(err.message || 'ERROR', function(){
throw err;
});
} finally {
@@ -107,14 +107,16 @@ angular.scenario.Runner.prototype = {
callback();
},
- addStep: function(name, step) {
- this.currentSpec.steps.push({name:name, fn:step});
+ addFuture: function(name, behavior) {
+ var future = new Future(name, behavior);
+ this.currentSpec.futures.push(future);
+ return future;
},
execute: function(name, callback) {
var spec = this.specs[name],
self = this,
- stepsDone = [],
+ futuresFulfilled = [],
result = {
passed: false,
failed: false,
@@ -132,29 +134,32 @@ angular.scenario.Runner.prototype = {
testWindow: this.testWindow
}, angularService, {});
this.self = specThis;
- var stepLogger = this.logger('spec', name);
- spec.nextStepIndex = 0;
+ var futureLogger = this.logger('spec', name);
+ spec.nextFutureIndex = 0;
function done() {
result.finished = true;
- stepLogger.close();
+ futureLogger.close();
self.self = null;
(callback||noop).call(specThis);
}
- function next(){
- var step = spec.steps[spec.nextStepIndex];
+ function next(value){
+ if (spec.nextFutureIndex > 0) {
+ spec.futures[spec.nextFutureIndex - 1].fulfill(value);
+ }
+ var future = spec.futures[spec.nextFutureIndex];
(result.log || {close:noop}).close();
result.log = null;
- if (step) {
- spec.nextStepIndex ++;
- result.log = stepLogger('step', step.name);
- stepsDone.push(step.name);
+ if (future) {
+ spec.nextFutureIndex ++;
+ result.log = futureLogger('future', future.name);
+ futuresFulfilled.push(future.name);
try {
- step.fn.call(specThis, next);
+ future.behavior.call(specThis, next);
} catch (e) {
console.error(e);
result.fail(e);
self.scope.$testrun.results.push(
- {name: name, passed: false, error: e, steps: stepsDone});
+ {name: name, passed: false, error: e, steps: futuresFulfilled});
done();
}
} else {
@@ -163,7 +168,7 @@ angular.scenario.Runner.prototype = {
name: name,
passed: !result.failed,
error: result.error,
- steps: stepsDone});
+ steps: futuresFulfilled});
done();
}
};
diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js
index 5aac9752..442178d0 100644
--- a/test/scenario/DSLSpec.js
+++ b/test/scenario/DSLSpec.js
@@ -1,22 +1,22 @@
describe("DSL", function() {
- var lastStep, executeStep, lastDocument;
+ var lastFuture, executeFuture, lastDocument;
beforeEach(function() {
- lastStep = null;
+ lastFuture = null;
$scenario = {
- addStep: function(name, stepFunction) {
- lastStep = { name:name, fn: stepFunction};
+ addFuture: function(name, behavior) {
+ lastFuture = { name:name, behavior: behavior};
}
};
- executeStep = function(step, html, callback) {
+ executeFuture = function(future, html, callback) {
lastDocument =_jQuery('
' + html + '
');
_jQuery(document.body).append(lastDocument);
var specThis = {
testWindow: window,
testDocument: lastDocument
};
- step.fn.call(specThis, callback || noop);
+ future.behavior.call(specThis, callback || noop);
};
});
@@ -25,15 +25,15 @@ describe("DSL", function() {
var input = angular.scenario.dsl.input;
it('should enter', function() {
input('name').enter('John');
- expect(lastStep.name).toEqual("Set input text of 'name' to 'John'");
- executeStep(lastStep, '');
+ expect(lastFuture.name).toEqual("Set input text of 'name' to 'John'");
+ executeFuture(lastFuture, '');
expect(lastDocument.find('input').val()).toEqual('John');
});
it('should select', function() {
input('gender').select('female');
- expect(lastStep.name).toEqual("Select radio 'gender' to 'female'");
- executeStep(lastStep,
+ expect(lastFuture.name).toEqual("Select radio 'gender' to 'female'");
+ executeFuture(lastFuture,
'' +
'');
expect(lastDocument.find(':radio:checked').length).toEqual(1);
@@ -46,9 +46,9 @@ describe("DSL", function() {
describe('repeater', function() {
it('should check the count of repeated elements', function() {
dslExpect.repeater('.repeater-row').count.toEqual(2);
- expect(lastStep.name).toEqual("Expect that there are 2 items in Repeater with selector '.repeater-row'");
+ expect(lastFuture.name).toEqual("Expect that there are 2 items in Repeater with selector '.repeater-row'");
var html = "a
b
";
- executeStep(lastStep, html);
+ executeFuture(lastFuture, html);
});
});
});
diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js
index 884e897a..689354df 100644
--- a/test/scenario/RunnerSpec.js
+++ b/test/scenario/RunnerSpec.js
@@ -34,7 +34,7 @@ describe('Runner', function(){
});
expect(log).toEqual('body');
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');
});
@@ -42,7 +42,7 @@ describe('Runner', function(){
// 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;
Describe('D1', function(){
It('I1', function(){
@@ -50,10 +50,10 @@ describe('Runner', function(){
throw {message: 'blah'};
});
});
- var step = spec.steps[0];
- expect(step.name).toEqual('blah');
+ var future = spec.futures[0];
+ expect(future.name).toEqual('blah');
try {
- step.fn();
+ future.behavior();
fail();
} catch (e) {
expect(e.message).toEqual('blah');
@@ -97,60 +97,61 @@ describe('Runner', function(){
var next;
Describe('describe name', function(){
AfterEach(function() {
- $scenario.addStep('afterEachLog', logger('after;'));
- $scenario.addStep('afterEachThrow', function() {
+ $scenario.addFuture('afterEachLog', logger('after;'));
+ $scenario.addFuture('afterEachThrow', function() {
throw "AfterError";
});
});
It('should text1', function() {
- $scenario.addStep('step1', logger('step1;'));
+ $scenario.addFuture('future1', logger('future1;'));
});
It('should text2', function() {
- $scenario.addStep('step2', logger('step2;'));
+ $scenario.addFuture('future2', logger('future2;'));
});
});
$scenario.run(body);
- expect(log).toEqual('step1;after;step2;after;');
+ expect(log).toEqual('future1;after;future2;after;');
expect(scenario.$testrun.results).toEqual([
{ name : 'describe name: it should text1',
passed : false,
error : 'AfterError',
- steps : [ 'step1', 'afterEachLog', 'afterEachThrow' ] },
+ steps : [ 'future1', 'afterEachLog', 'afterEachThrow' ] },
{ name : 'describe name: it should text2',
passed : false,
error : 'AfterError',
- steps : [ 'step2', 'afterEachLog', 'afterEachThrow' ] }]);
+ steps : [ 'future2', 'afterEachLog', 'afterEachThrow' ] }]);
});
});
});
- describe('steps building', function(){
- it('should queue steps', function(){
- function step(){};
+ describe('future building', function(){
+ it('should queue futures', function(){
+ function behavior(){};
Describe('name', 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(){
- it('should execute the queued steps', function(){
+ it('should execute the queued futures', function(){
var next, firstThis, secondThis, doneThis, spec;
$scenario.specs['spec'] = {
- steps: [
- {name:'step1', fn: function(done) {
- next = done;
- log += 'first;';
- firstThis = this;
- }},
- {name:'step2', fn:function(done){
- next = done;
- log += 'second;';
- secondThis = this;
- }}
+ futures: [
+ new Future('future1', function(done) {
+ next = done;
+ log += 'first;';
+ firstThis = this;
+ }),
+ new Future('future2', function(done) {
+ next = done;
+ log += 'second;';
+ secondThis = this;
+ })
]
};
@@ -174,18 +175,18 @@ describe('Runner', function(){
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'] = {
- steps: [
- {name: 'first step', fn: function(done) {
+ futures: [
+ new Future('first future', function(done) {
done();
- }},
- {name:'error', fn:function(done) {
+ }),
+ new Future('error', function(done) {
throw "MyError";
- }},
- {name: 'should not execute', fn: function(done) {
+ }),
+ new Future('should not execute', function(done) {
done();
- }}
+ })
]
};
@@ -199,7 +200,7 @@ describe('Runner', function(){
name: 'spec',
passed: false,
error: 'MyError',
- steps: ['first step', 'error']}]);
+ steps: ['first future', 'error']}]);
});
});
@@ -207,15 +208,15 @@ describe('Runner', function(){
var next;
beforeEach(function() {
Describe('d1', function(){
- It('it1', function(){ $scenario.addStep('s1', logger('s1,')); });
+ It('it1', function(){ $scenario.addFuture('s1', logger('s1,')); });
It('it2', function(){
- $scenario.addStep('s2', logger('s2,'));
- $scenario.addStep('s2.2', function(done){ next = done; });
+ $scenario.addFuture('s2', logger('s2,'));
+ $scenario.addFuture('s2.2', function(done){ next = done; });
});
});
Describe('d2', function(){
- It('it3', function(){ $scenario.addStep('s3', logger('s3,')); });
- It('it4', function(){ $scenario.addStep('s4', logger('s4,')); });
+ It('it3', function(){ $scenario.addFuture('s3', logger('s3,')); });
+ It('it4', function(){ $scenario.addFuture('s4', logger('s4,')); });
});
});
it('should execute all specs', function(){
@@ -231,15 +232,15 @@ describe('Runner', function(){
$scenario.run(body);
expect(scenario.$testrun.done).toBeFalsy();
expect(scenario.$testrun.results).toEqual([
- {name: 'd1: it it1', passed: true, steps: ['s1']}
+ {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']}
]);
next();
expect(scenario.$testrun.done).toBeTruthy();
expect(scenario.$testrun.results).toEqual([
- {name: 'd1: it it1', passed: true, steps: ['s1']},
- {name: 'd1: it it2', passed: true, steps: ['s2', 's2.2']},
- {name: 'd2: it it3', passed: true, steps: ['s3']},
- {name: 'd2: it it4', passed: true, steps: ['s4']}
+ {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']},
+ {name: 'd1: it it2', passed: true, error: undefined, steps: ['s2', 's2.2']},
+ {name: 'd2: it it3', passed: true, error: undefined, steps: ['s3']},
+ {name: 'd2: it it4', passed: true, error: undefined, steps: ['s4']}
]);
});
});
--
cgit v1.2.3
From da95010350882d9e13b5e461fb4a1e05bc7d065c Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Tue, 27 Jul 2010 15:43:14 -0700
Subject: stable before refactoring
---
src/scenario/DSL.js | 53 +++++++++---------
src/scenario/Future.js | 29 +---------
src/scenario/Matcher.js | 21 ++++++++
src/scenario/Runner.js | 3 ++
test/scenario/DSLSpec.js | 43 ++++++++-------
test/scenario/RunnerSpec.js | 124 +++++++++++++++++++++----------------------
test/scenario/TestContext.js | 20 +++++++
7 files changed, 154 insertions(+), 139 deletions(-)
create mode 100644 src/scenario/Matcher.js
create mode 100644 test/scenario/TestContext.js
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js
index fcadd3ca..ef2f5553 100644
--- a/src/scenario/DSL.js
+++ b/src/scenario/DSL.js
@@ -7,7 +7,8 @@ angular.scenario.dsl.browser = {
self.testWindow = self.testFrame[0].contentWindow;
self.testDocument = jQuery(self.testWindow.document);
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);
});
if (this.testFrame.attr('src') == url) {
@@ -19,20 +20,23 @@ angular.scenario.dsl.browser = {
}
};
+function future(name, behavior) {
+ return new Future(name, behavior);
+};
+
angular.scenario.dsl.input = function(selector) {
+ var namePrefix = "input '" + selector + "'";
return {
- enter: function(value){
- $scenario.addFuture("Set input text of '" + selector + "' to '" +
- value + "'", function(done){
- var input = this.testDocument.find('input[name=' + selector + ']');
- input.val(value);
- this.testWindow.angular.element(input[0]).trigger('change');
- done();
+ enter: function(value) {
+ return future(namePrefix + " enter '" + value + "'", function(done) {
+ var input = this.testDocument.find('input[name=' + selector + ']');
+ input.val(value);
+ this.testWindow.angular.element(input[0]).trigger('change');
+ done();
});
},
- select: function(value){
- $scenario.addFuture("Select radio '" + selector + "' to '" +
- value + "'", function(done){
+ select: function(value) {
+ return future(namePrefix + " select '" + value + "'", function(done) {
var input = this.testDocument.
find(':radio[name$=@' + selector + '][value=' + value + ']');
jqLiteWrap(input[0]).trigger('click');
@@ -41,22 +45,15 @@ angular.scenario.dsl.input = function(selector) {
});
}
};
-};
+},
-angular.scenario.dsl.expect = {
- repeater: function(selector) {
- return {
- count: {
- toEqual: function(number) {
- $scenario.addFuture("Expect that there are " + number + " items in Repeater with selector '" + selector + "'", function(done) {
- var items = this.testDocument.find(selector);
- if (items.length != number) {
- this.result.fail("Expected " + number + " but was " + items.length);
- }
- done();
- });
- }
- }
- };
- }
+angular.scenario.dsl.repeater = function(selector) {
+ var namePrefix = "repeater '" + selector + "'";
+ return {
+ count: function() {
+ return future(namePrefix + ' count', function(done) {
+ done(this.testDocument.find(selector).size());
+ });
+ }
+ };
};
diff --git a/src/scenario/Future.js b/src/scenario/Future.js
index c718bba2..6c90df9d 100644
--- a/src/scenario/Future.js
+++ b/src/scenario/Future.js
@@ -6,11 +6,12 @@ function Future(name, behavior) {
}
Future.prototype = {
- fulfill: function(value){
+ fulfill: function(value) {
this.fulfilled = true;
this.value = value;
}
};
+
function Matcher(future, logger) {
var self = this;
this.logger = logger;
@@ -32,29 +33,3 @@ Matcher.addMatcher = function(name, matcher){
};
Matcher.addMatcher('toEqual', function(a,b){ return a == b; });
-
-/*
-
-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 expectX(future) {
- return new Matcher(future, window.alert);
-}
-
- */
\ No newline at end of file
diff --git a/src/scenario/Matcher.js b/src/scenario/Matcher.js
new file mode 100644
index 00000000..dd7b7ee6
--- /dev/null
+++ b/src/scenario/Matcher.js
@@ -0,0 +1,21 @@
+//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; });
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index c77239cc..3fc1c614 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -22,6 +22,9 @@ angular.scenario.Runner = function(scope, jQuery){
this.scope.afterEach = function(body) {
afterEach = body;
};
+// this.scope.expect = function(future) {
+// return new Matcher(future, self.logger);
+// };
this.scope.it = function(name, body) {
var specName = path.join(' ') + ': it ' + name;
self.currentSpec = specs[specName] = {
diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js
index 442178d0..4d8d1075 100644
--- a/test/scenario/DSLSpec.js
+++ b/test/scenario/DSLSpec.js
@@ -1,14 +1,11 @@
describe("DSL", function() {
- var lastFuture, executeFuture, lastDocument;
+ var scenario, runner, $scenario, lastDocument, executeFuture;
beforeEach(function() {
- lastFuture = null;
- $scenario = {
- addFuture: function(name, behavior) {
- lastFuture = { name:name, behavior: behavior};
- }
- };
+ scenario = {};
+ runner = new angular.scenario.Runner(scenario, _jQuery);
+ $scenario = scenario.$scenario;
executeFuture = function(future, html, callback) {
lastDocument =_jQuery('' + html + '
');
_jQuery(document.body).append(lastDocument);
@@ -23,17 +20,18 @@ describe("DSL", function() {
describe("input", function() {
var input = angular.scenario.dsl.input;
+
it('should enter', function() {
- input('name').enter('John');
- expect(lastFuture.name).toEqual("Set input text of 'name' to 'John'");
- executeFuture(lastFuture, '');
+ var future = input('name').enter('John');
+ expect(future.name).toEqual("input 'name' enter 'John'");
+ executeFuture(future, '');
expect(lastDocument.find('input').val()).toEqual('John');
});
it('should select', function() {
- input('gender').select('female');
- expect(lastFuture.name).toEqual("Select radio 'gender' to 'female'");
- executeFuture(lastFuture,
+ var future = input('gender').select('female');
+ expect(future.name).toEqual("input 'gender' select 'female'");
+ executeFuture(future,
'' +
'');
expect(lastDocument.find(':radio:checked').length).toEqual(1);
@@ -41,15 +39,16 @@ describe("DSL", function() {
});
});
- describe('expect', function() {
- var dslExpect = angular.scenario.dsl.expect;
- describe('repeater', function() {
- it('should check the count of repeated elements', function() {
- dslExpect.repeater('.repeater-row').count.toEqual(2);
- expect(lastFuture.name).toEqual("Expect that there are 2 items in Repeater with selector '.repeater-row'");
- var html = "a
b
";
- executeFuture(lastFuture, html);
- });
+ describe('repeater', function() {
+
+ var repeater = angular.scenario.dsl.repeater;
+
+ it('should fetch the count of repeated elements', function() {
+ var future = repeater('.repeater-row').count();
+ expect(future.name).toEqual("repeater '.repeater-row' count");
+ executeFuture(future, "a
" +
+ "b
");
+// Expect(future).toEqual(2);
});
});
});
diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js
index 98858747..b9280e0a 100644
--- a/test/scenario/RunnerSpec.js
+++ b/test/scenario/RunnerSpec.js
@@ -1,4 +1,5 @@
-describe('Runner', function(){
+describe('Runner', function() {
+
var scenario, runner, log, Describe, It, $scenario, body;
function logger(text) {
@@ -8,7 +9,7 @@ describe('Runner', function(){
};
}
- beforeEach(function(){
+ beforeEach(function() {
log = '';
scenario = {};
body = _jQuery('');
@@ -20,16 +21,15 @@ describe('Runner', function(){
$scenario = scenario.$scenario;
});
- describe('describe', function(){
- it('should consume the describe functions', function(){
+ describe('describe', function() {
+ it('should consume the describe functions', function() {
Describe('describe name', logger('body'));
-
expect(log).toEqual('body');
});
- describe('it', function(){
- it('should consume it', function(){
- Describe('describe name', function(){
+ describe('it', function() {
+ it('should consume it', function() {
+ Describe('describe name', function() {
It('should text', logger('body'));
});
expect(log).toEqual('body');
@@ -42,10 +42,10 @@ describe('Runner', function(){
// WRITE ME!!!!
});
- it('should create a failing future if there is a javascript error', function(){
+ it('should create a failing future if there is a javascript error', function() {
var spec;
- Describe('D1', function(){
- It('I1', function(){
+ Describe('D1', function() {
+ It('I1', function() {
spec = $scenario.currentSpec;
throw {message: 'blah'};
});
@@ -63,7 +63,7 @@ describe('Runner', function(){
describe('beforeEach', function() {
it('should execute beforeEach before every it', function() {
- Describe('describe name', function(){
+ Describe('describe name', function() {
BeforeEach(logger('before;'));
It('should text', logger('body;'));
It('should text2', logger('body2;'));
@@ -73,7 +73,7 @@ describe('Runner', function(){
});
describe('afterEach', function() {
it('should execute afterEach after every it', function() {
- Describe('describe name', function(){
+ Describe('describe name', function() {
AfterEach(logger('after;'));
It('should text1', logger('body1;'));
It('should text2', logger('body2;'));
@@ -82,7 +82,7 @@ describe('Runner', function(){
});
it('should always execute afterEach after every it', function() {
- Describe('describe name', function(){
+ Describe('describe name', function() {
AfterEach(logger('after;'));
It('should text', function() {
logger('body1;')();
@@ -95,7 +95,7 @@ describe('Runner', function(){
it('should report an error if afterEach fails', function() {
var next;
- Describe('describe name', function(){
+ Describe('describe name', function() {
AfterEach(function() {
$scenario.addFuture('afterEachLog', logger('after;'));
$scenario.addFuture('afterEachThrow', function() {
@@ -124,11 +124,11 @@ describe('Runner', function(){
});
});
- describe('future building', function(){
- it('should queue futures', function(){
+ describe('future building', function() {
+ it('should queue futures', function() {
function behavior(){};
- Describe('name', function(){
- It('should', function(){
+ Describe('name', function() {
+ It('should', function() {
$scenario.addFuture('futureName', behavior);
});
});
@@ -137,8 +137,8 @@ describe('Runner', function(){
});
});
- describe('execution', function(){
- it('should execute the queued futures', function(){
+ describe('execution', function() {
+ it('should execute the queued futures', function() {
var next, firstThis, secondThis, doneThis, spec;
$scenario.specs['spec'] = {
futures: [
@@ -175,7 +175,7 @@ describe('Runner', function(){
expect(spec.result.passed).toEqual(true);
});
- it('should handle exceptions in a future', function(){
+ it('should handle exceptions in a future', function() {
$scenario.specs['spec'] = {
futures: [
new Future('first future', function(done) {
@@ -204,45 +204,45 @@ describe('Runner', function(){
});
});
- describe('run', function(){
- var next;
- beforeEach(function() {
- Describe('d1', function(){
- It('it1', function(){ $scenario.addFuture('s1', logger('s1,')); });
- It('it2', function(){
- $scenario.addFuture('s2', logger('s2,'));
- $scenario.addFuture('s2.2', function(done){ next = done; });
- });
- });
- Describe('d2', function(){
- It('it3', function(){ $scenario.addFuture('s3', logger('s3,')); });
- It('it4', function(){ $scenario.addFuture('s4', logger('s4,')); });
- });
- });
- it('should execute all specs', function(){
- $scenario.run(body);
-
- expect(log).toEqual('s1,s2,');
- next();
- expect(log).toEqual('s1,s2,s3,s4,');
- });
- it('should publish done state and results as tests are run', function() {
- expect(scenario.$testrun.done).toBeFalsy();
- expect(scenario.$testrun.results).toEqual([]);
- $scenario.run(body);
- expect(scenario.$testrun.done).toBeFalsy();
- expect(scenario.$testrun.results).toEqual([
- {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']}
- ]);
- next();
- expect(scenario.$testrun.done).toBeTruthy();
- expect(scenario.$testrun.results).toEqual([
- {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']},
- {name: 'd1: it it2', passed: true, error: undefined, steps: ['s2', 's2.2']},
- {name: 'd2: it it3', passed: true, error: undefined, steps: ['s3']},
- {name: 'd2: it it4', passed: true, error: undefined, steps: ['s4']}
- ]);
- });
- });
+// describe('run', function() {
+// var next;
+// beforeEach(function() {
+// Describe('d1', function() {
+// It('it1', function() { $scenario.addFuture('s1', logger('s1,')); });
+// It('it2', function() {
+// $scenario.addFuture('s2', logger('s2,'));
+// $scenario.addFuture('s2.2', function(done){ next = done; });
+// });
+// });
+// Describe('d2', function() {
+// It('it3', function() { $scenario.addFuture('s3', logger('s3,')); });
+// It('it4', function() { $scenario.addFuture('s4', logger('s4,')); });
+// });
+// });
+// it('should execute all specs', function() {
+// $scenario.run(body);
+//
+// expect(log).toEqual('s1,s2,');
+// next();
+// expect(log).toEqual('s1,s2,s3,s4,');
+// });
+// it('should publish done state and results as tests are run', function() {
+// expect(scenario.$testrun.done).toBeFalsy();
+// expect(scenario.$testrun.results).toEqual([]);
+// $scenario.run(body);
+// expect(scenario.$testrun.done).toBeFalsy();
+// expect(scenario.$testrun.results).toEqual([
+// {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']}
+// ]);
+// next();
+// expect(scenario.$testrun.done).toBeTruthy();
+// expect(scenario.$testrun.results).toEqual([
+// {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']},
+// {name: 'd1: it it2', passed: true, error: undefined, steps: ['s2', 's2.2']},
+// {name: 'd2: it it3', passed: true, error: undefined, steps: ['s3']},
+// {name: 'd2: it it4', passed: true, error: undefined, steps: ['s4']}
+// ]);
+// });
+// });
});
\ No newline at end of file
diff --git a/test/scenario/TestContext.js b/test/scenario/TestContext.js
new file mode 100644
index 00000000..2081479e
--- /dev/null
+++ b/test/scenario/TestContext.js
@@ -0,0 +1,20 @@
+//var scenario, runner, log, Describe, It, $scenario, body;
+//
+//function logger(text) {
+// return function(done){
+// log += text;
+// (done||noop)();
+// };
+//}
+//
+//function beforeEach() {
+// log = '';
+// scenario = {};
+// body = _jQuery('');
+// runner = new angular.scenario.Runner(scenario, _jQuery);
+// Describe = scenario.describe;
+// BeforeEach = scenario.beforeEach;
+// AfterEach = scenario.afterEach;
+// It = scenario.it;
+// $scenario = scenario.$scenario;
+//}
--
cgit v1.2.3
From 32c4aee1cdb601550e948b52a3fa7b4824cfbf1f Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Tue, 27 Jul 2010 15:53:55 -0700
Subject: before pulling testcontext out
---
src/scenario/Future.js | 22 -------------
src/scenario/Matcher.js | 42 ++++++++++++------------
src/scenario/Runner.js | 6 ++--
test/scenario/RunnerSpec.js | 80 ++++++++++++++++++++++-----------------------
4 files changed, 64 insertions(+), 86 deletions(-)
diff --git a/src/scenario/Future.js b/src/scenario/Future.js
index 6c90df9d..d70e8e6e 100644
--- a/src/scenario/Future.js
+++ b/src/scenario/Future.js
@@ -11,25 +11,3 @@ Future.prototype = {
this.value = value;
}
};
-
-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; });
diff --git a/src/scenario/Matcher.js b/src/scenario/Matcher.js
index dd7b7ee6..a4a13285 100644
--- a/src/scenario/Matcher.js
+++ b/src/scenario/Matcher.js
@@ -1,21 +1,21 @@
-//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 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; });
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 3fc1c614..4e5d0f01 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -22,9 +22,9 @@ angular.scenario.Runner = function(scope, jQuery){
this.scope.afterEach = function(body) {
afterEach = body;
};
-// this.scope.expect = function(future) {
-// return new Matcher(future, self.logger);
-// };
+ this.scope.expect = function(future) {
+ return new Matcher(future, self.logger);
+ };
this.scope.it = function(name, body) {
var specName = path.join(' ') + ': it ' + name;
self.currentSpec = specs[specName] = {
diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js
index b9280e0a..de7c199d 100644
--- a/test/scenario/RunnerSpec.js
+++ b/test/scenario/RunnerSpec.js
@@ -204,45 +204,45 @@ describe('Runner', function() {
});
});
-// describe('run', function() {
-// var next;
-// beforeEach(function() {
-// Describe('d1', function() {
-// It('it1', function() { $scenario.addFuture('s1', logger('s1,')); });
-// It('it2', function() {
-// $scenario.addFuture('s2', logger('s2,'));
-// $scenario.addFuture('s2.2', function(done){ next = done; });
-// });
-// });
-// Describe('d2', function() {
-// It('it3', function() { $scenario.addFuture('s3', logger('s3,')); });
-// It('it4', function() { $scenario.addFuture('s4', logger('s4,')); });
-// });
-// });
-// it('should execute all specs', function() {
-// $scenario.run(body);
-//
-// expect(log).toEqual('s1,s2,');
-// next();
-// expect(log).toEqual('s1,s2,s3,s4,');
-// });
-// it('should publish done state and results as tests are run', function() {
-// expect(scenario.$testrun.done).toBeFalsy();
-// expect(scenario.$testrun.results).toEqual([]);
-// $scenario.run(body);
-// expect(scenario.$testrun.done).toBeFalsy();
-// expect(scenario.$testrun.results).toEqual([
-// {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']}
-// ]);
-// next();
-// expect(scenario.$testrun.done).toBeTruthy();
-// expect(scenario.$testrun.results).toEqual([
-// {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']},
-// {name: 'd1: it it2', passed: true, error: undefined, steps: ['s2', 's2.2']},
-// {name: 'd2: it it3', passed: true, error: undefined, steps: ['s3']},
-// {name: 'd2: it it4', passed: true, error: undefined, steps: ['s4']}
-// ]);
-// });
-// });
+ describe('run', function() {
+ var next;
+ beforeEach(function() {
+ Describe('d1', function() {
+ It('it1', function() { $scenario.addFuture('s1', logger('s1,')); });
+ It('it2', function() {
+ $scenario.addFuture('s2', logger('s2,'));
+ $scenario.addFuture('s2.2', function(done){ next = done; });
+ });
+ });
+ Describe('d2', function() {
+ It('it3', function() { $scenario.addFuture('s3', logger('s3,')); });
+ It('it4', function() { $scenario.addFuture('s4', logger('s4,')); });
+ });
+ });
+ it('should execute all specs', function() {
+ $scenario.run(body);
+
+ expect(log).toEqual('s1,s2,');
+ next();
+ expect(log).toEqual('s1,s2,s3,s4,');
+ });
+ it('should publish done state and results as tests are run', function() {
+ expect(scenario.$testrun.done).toBeFalsy();
+ expect(scenario.$testrun.results).toEqual([]);
+ $scenario.run(body);
+ expect(scenario.$testrun.done).toBeFalsy();
+ expect(scenario.$testrun.results).toEqual([
+ {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']}
+ ]);
+ next();
+ expect(scenario.$testrun.done).toBeTruthy();
+ expect(scenario.$testrun.results).toEqual([
+ {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']},
+ {name: 'd1: it it2', passed: true, error: undefined, steps: ['s2', 's2.2']},
+ {name: 'd2: it it3', passed: true, error: undefined, steps: ['s3']},
+ {name: 'd2: it it4', passed: true, error: undefined, steps: ['s4']}
+ ]);
+ });
+ });
});
\ No newline at end of file
--
cgit v1.2.3
From e8b477f5b1f6fcca99ea54731e7c4f09ef17b0f7 Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Tue, 27 Jul 2010 16:02:51 -0700
Subject: text context extracted
---
test/scenario/RunnerSpec.js | 19 +------------------
test/scenario/TestContext.js | 40 ++++++++++++++++++++--------------------
2 files changed, 21 insertions(+), 38 deletions(-)
diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js
index de7c199d..f5c152a5 100644
--- a/test/scenario/RunnerSpec.js
+++ b/test/scenario/RunnerSpec.js
@@ -1,24 +1,7 @@
describe('Runner', function() {
- var scenario, runner, log, Describe, It, $scenario, body;
-
- function logger(text) {
- return function(done){
- log += text;
- (done||noop)();
- };
- }
-
beforeEach(function() {
- log = '';
- scenario = {};
- body = _jQuery('');
- runner = new angular.scenario.Runner(scenario, _jQuery);
- Describe = scenario.describe;
- BeforeEach = scenario.beforeEach;
- AfterEach = scenario.afterEach;
- It = scenario.it;
- $scenario = scenario.$scenario;
+ setUpContext();
});
describe('describe', function() {
diff --git a/test/scenario/TestContext.js b/test/scenario/TestContext.js
index 2081479e..7a7b41e4 100644
--- a/test/scenario/TestContext.js
+++ b/test/scenario/TestContext.js
@@ -1,20 +1,20 @@
-//var scenario, runner, log, Describe, It, $scenario, body;
-//
-//function logger(text) {
-// return function(done){
-// log += text;
-// (done||noop)();
-// };
-//}
-//
-//function beforeEach() {
-// log = '';
-// scenario = {};
-// body = _jQuery('');
-// runner = new angular.scenario.Runner(scenario, _jQuery);
-// Describe = scenario.describe;
-// BeforeEach = scenario.beforeEach;
-// AfterEach = scenario.afterEach;
-// It = scenario.it;
-// $scenario = scenario.$scenario;
-//}
+var scenario, runner, log, $scenario, Describe, It, body;
+
+function logger(text) {
+ return function(done){
+ log += text;
+ (done||noop)();
+ };
+}
+
+function setUpContext() {
+ scenario = {};
+ runner = new angular.scenario.Runner(scenario, _jQuery);
+ $scenario = scenario.$scenario;
+ Describe = scenario.describe;
+ BeforeEach = scenario.beforeEach;
+ AfterEach = scenario.afterEach;
+ It = scenario.it;
+ log = '';
+ body = _jQuery('');
+}
--
cgit v1.2.3
From ef88eb9a71ee7666029c4fb5eb731ce2e986cecc Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Tue, 27 Jul 2010 17:04:37 -0700
Subject: refactoring done but Expect not working
---
src/scenario/Matcher.js | 8 ++++----
src/scenario/Runner.js | 3 ++-
test/scenario/DSLSpec.js | 9 ++++-----
test/scenario/RunnerSpec.js | 7 +++++++
test/scenario/TestContext.js | 7 +------
5 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/src/scenario/Matcher.js b/src/scenario/Matcher.js
index a4a13285..b9787050 100644
--- a/src/scenario/Matcher.js
+++ b/src/scenario/Matcher.js
@@ -1,10 +1,10 @@
-function Matcher(future, logger) {
- var self = this;
+function Matcher(scope, future, logger) {
+ var self = scope.$scenario = this;
this.logger = logger;
this.future = future;
}
-Matcher.addMatcher = function(name, matcher){
+Matcher.addMatcher = function(name, matcher) {
Matcher.prototype[name] = function(expected) {
var future = this.future;
$scenario.addFuture(
@@ -18,4 +18,4 @@ Matcher.addMatcher = function(name, matcher){
};
};
-Matcher.addMatcher('toEqual', function(a,b){ return a == b; });
+Matcher.addMatcher('toEqual', function(a,b) { return a == b; });
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 4e5d0f01..13dfbe7d 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -8,6 +8,7 @@ angular.scenario.Runner = function(scope, jQuery){
this.scope.$testrun = {done: false, results: []};
var specs = this.specs = {};
+ this.currentSpec = {name: '', futures: []};
var path = [];
this.scope.describe = function(name, body){
path.push(name);
@@ -23,7 +24,7 @@ angular.scenario.Runner = function(scope, jQuery){
afterEach = body;
};
this.scope.expect = function(future) {
- return new Matcher(future, self.logger);
+ return new Matcher(self, future, self.logger);
};
this.scope.it = function(name, body) {
var specName = path.join(' ') + ': it ' + name;
diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js
index 4d8d1075..533d34ac 100644
--- a/test/scenario/DSLSpec.js
+++ b/test/scenario/DSLSpec.js
@@ -1,11 +1,9 @@
describe("DSL", function() {
- var scenario, runner, $scenario, lastDocument, executeFuture;
+ var lastDocument, executeFuture, Expect;
beforeEach(function() {
- scenario = {};
- runner = new angular.scenario.Runner(scenario, _jQuery);
- $scenario = scenario.$scenario;
+ setUpContext();
executeFuture = function(future, html, callback) {
lastDocument =_jQuery('' + html + '
');
_jQuery(document.body).append(lastDocument);
@@ -15,6 +13,7 @@ describe("DSL", function() {
};
future.behavior.call(specThis, callback || noop);
};
+ Expect = scenario.expect;
});
describe("input", function() {
@@ -48,7 +47,7 @@ describe("DSL", function() {
expect(future.name).toEqual("repeater '.repeater-row' count");
executeFuture(future, "a
" +
"b
");
-// Expect(future).toEqual(2);
+ Expect(future).toEqual(2);
});
});
});
diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js
index f5c152a5..2eb13f7f 100644
--- a/test/scenario/RunnerSpec.js
+++ b/test/scenario/RunnerSpec.js
@@ -1,7 +1,14 @@
describe('Runner', function() {
+ var Describe, It, BeforeEach, AfterEach, body;
+
beforeEach(function() {
setUpContext();
+ Describe = scenario.describe;
+ It = scenario.it;
+ BeforeEach = scenario.beforeEach;
+ AfterEach = scenario.afterEach;
+ body = _jQuery('');
});
describe('describe', function() {
diff --git a/test/scenario/TestContext.js b/test/scenario/TestContext.js
index 7a7b41e4..ebb40b95 100644
--- a/test/scenario/TestContext.js
+++ b/test/scenario/TestContext.js
@@ -1,4 +1,4 @@
-var scenario, runner, log, $scenario, Describe, It, body;
+var scenario, runner, log, $scenario;
function logger(text) {
return function(done){
@@ -11,10 +11,5 @@ function setUpContext() {
scenario = {};
runner = new angular.scenario.Runner(scenario, _jQuery);
$scenario = scenario.$scenario;
- Describe = scenario.describe;
- BeforeEach = scenario.beforeEach;
- AfterEach = scenario.afterEach;
- It = scenario.it;
log = '';
- body = _jQuery('');
}
--
cgit v1.2.3
From 26ed747588d2e7bceddcb4ccd9bacd5f51b9fec8 Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Wed, 4 Aug 2010 11:47:10 -0700
Subject: test passing with repeater.count
---
src/scenario/Matcher.js | 3 ++-
test/scenario/DSLSpec.js | 8 ++++++--
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/scenario/Matcher.js b/src/scenario/Matcher.js
index b9787050..326bb948 100644
--- a/src/scenario/Matcher.js
+++ b/src/scenario/Matcher.js
@@ -10,11 +10,12 @@ Matcher.addMatcher = function(name, matcher) {
$scenario.addFuture(
'expect ' + future.name + ' ' + name + ' ' + expected,
function(done){
- if (matcher(future.value, expected))
+ if (!matcher(future.value, expected))
throw "Expected " + expected + ' but was ' + future.value;
done();
}
);
+ dump('future added');
};
};
diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js
index 533d34ac..47bedb80 100644
--- a/test/scenario/DSLSpec.js
+++ b/test/scenario/DSLSpec.js
@@ -46,8 +46,12 @@ describe("DSL", function() {
var future = repeater('.repeater-row').count();
expect(future.name).toEqual("repeater '.repeater-row' count");
executeFuture(future, "a
" +
- "b
");
- Expect(future).toEqual(2);
+ "b
",
+ function(value) {
+ future.fulfill(value);
+ });
+ expect(future.fulfilled).toBeTruthy();
+ expect(future.value).toEqual(2);
});
});
});
--
cgit v1.2.3
From 6d0eeda1e231d0fbe515ce4cea8bf6245e1b72d3 Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Wed, 4 Aug 2010 12:36:53 -0700
Subject: added MatcherSpec
---
src/scenario/Matcher.js | 1 -
test/scenario/MatcherSpec.js | 30 ++++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
create mode 100644 test/scenario/MatcherSpec.js
diff --git a/src/scenario/Matcher.js b/src/scenario/Matcher.js
index 326bb948..62f094c8 100644
--- a/src/scenario/Matcher.js
+++ b/src/scenario/Matcher.js
@@ -15,7 +15,6 @@ Matcher.addMatcher = function(name, matcher) {
done();
}
);
- dump('future added');
};
};
diff --git a/test/scenario/MatcherSpec.js b/test/scenario/MatcherSpec.js
new file mode 100644
index 00000000..c47f0c25
--- /dev/null
+++ b/test/scenario/MatcherSpec.js
@@ -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');
+ }
+ });
+});
\ No newline at end of file
--
cgit v1.2.3
From 643b43ffe5bd481b129484828fb35e2ab71a7d4c Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Thu, 5 Aug 2010 15:44:54 -0700
Subject: Added new files to Rakefile and consistently used .addFuture
---
Rakefile | 4 +++-
src/scenario/DSL.js | 10 +++-------
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/Rakefile b/Rakefile
index 4eb22ade..bf37edce 100644
--- a/Rakefile
+++ b/Rakefile
@@ -45,8 +45,10 @@ task :compile_scenario do
src/apis.js \
src/services.js \
src/AngularPublic.js \
- src/scenario/Runner.js \
src/scenario/DSL.js \
+ src/scenario/Future.js \
+ src/scenario/Matcher.js \
+ src/scenario/Runner.js \
src/scenario/angular.suffix \
)
css = %x(cat css/angular-scenario.css)
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js
index ef2f5553..944ca6f5 100644
--- a/src/scenario/DSL.js
+++ b/src/scenario/DSL.js
@@ -20,15 +20,11 @@ angular.scenario.dsl.browser = {
}
};
-function future(name, behavior) {
- return new Future(name, behavior);
-};
-
angular.scenario.dsl.input = function(selector) {
var namePrefix = "input '" + selector + "'";
return {
enter: function(value) {
- return future(namePrefix + " enter '" + value + "'", function(done) {
+ $scenario.addFuture(namePrefix + " enter '" + value + "'", function(done) {
var input = this.testDocument.find('input[name=' + selector + ']');
input.val(value);
this.testWindow.angular.element(input[0]).trigger('change');
@@ -36,7 +32,7 @@ angular.scenario.dsl.input = function(selector) {
});
},
select: function(value) {
- return future(namePrefix + " select '" + value + "'", function(done) {
+ $scenario.addFuture(namePrefix + " select '" + value + "'", function(done) {
var input = this.testDocument.
find(':radio[name$=@' + selector + '][value=' + value + ']');
jqLiteWrap(input[0]).trigger('click');
@@ -51,7 +47,7 @@ angular.scenario.dsl.repeater = function(selector) {
var namePrefix = "repeater '" + selector + "'";
return {
count: function() {
- return future(namePrefix + ' count', function(done) {
+ $scenario.addFuture(namePrefix + ' count', function(done) {
done(this.testDocument.find(selector).size());
});
}
--
cgit v1.2.3
From 989cffb43502744ab05baa741420c2082f137d69 Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Thu, 5 Aug 2010 16:03:47 -0700
Subject: fix build breakage by returning the added futures in the DSL
---
src/scenario/DSL.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js
index 944ca6f5..26157059 100644
--- a/src/scenario/DSL.js
+++ b/src/scenario/DSL.js
@@ -1,6 +1,6 @@
angular.scenario.dsl.browser = {
navigateTo: function(url){
- $scenario.addFuture('Navigate to: ' + url, function(done){
+ return $scenario.addFuture('Navigate to: ' + url, function(done){
var self = this;
this.testFrame.load(function(){
self.testFrame.unbind();
@@ -24,7 +24,7 @@ angular.scenario.dsl.input = function(selector) {
var namePrefix = "input '" + selector + "'";
return {
enter: function(value) {
- $scenario.addFuture(namePrefix + " enter '" + value + "'", function(done) {
+ return $scenario.addFuture(namePrefix + " enter '" + value + "'", function(done) {
var input = this.testDocument.find('input[name=' + selector + ']');
input.val(value);
this.testWindow.angular.element(input[0]).trigger('change');
@@ -32,7 +32,7 @@ angular.scenario.dsl.input = function(selector) {
});
},
select: function(value) {
- $scenario.addFuture(namePrefix + " select '" + value + "'", function(done) {
+ return $scenario.addFuture(namePrefix + " select '" + value + "'", function(done) {
var input = this.testDocument.
find(':radio[name$=@' + selector + '][value=' + value + ']');
jqLiteWrap(input[0]).trigger('click');
@@ -47,7 +47,7 @@ angular.scenario.dsl.repeater = function(selector) {
var namePrefix = "repeater '" + selector + "'";
return {
count: function() {
- $scenario.addFuture(namePrefix + ' count', function(done) {
+ return $scenario.addFuture(namePrefix + ' count', function(done) {
done(this.testDocument.find(selector).size());
});
}
--
cgit v1.2.3
From de8d0984c85ae3078fd72a9c7f010b0fd4397150 Mon Sep 17 00:00:00 2001
From: Andres Ornelas
Date: Fri, 6 Aug 2010 17:28:47 -0700
Subject: added repeater.collect to E2E DSL
---
src/scenario/DSL.js | 20 ++++++++++++++++++++
test/scenario/DSLSpec.js | 35 ++++++++++++++++++++++++++++++-----
2 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js
index 26157059..13576824 100644
--- a/src/scenario/DSL.js
+++ b/src/scenario/DSL.js
@@ -50,6 +50,26 @@ angular.scenario.dsl.repeater = function(selector) {
return $scenario.addFuture(namePrefix + ' count', function(done) {
done(this.testDocument.find(selector).size());
});
+ },
+ collect: function() {
+ return $scenario.addFuture(namePrefix + ' collect', function(done) {
+ var doCollect = bind(this, function() {
+ var repeaterArray = [];
+ this.testDocument.find(selector).each(function(index) {
+ var element = angular.extend(_jQuery(this),
+ {bindings: [],
+ boundTo: function(name) { return this.bindings[name]; }}
+ );
+ element.find('*').each(function(index) {
+ var bindName = _jQuery(this).attr('ng:bind');
+ element.bindings[bindName] = _jQuery(this).text();
+ });
+ repeaterArray[index] = element;
+ });
+ return repeaterArray;
+ });
+ done(doCollect());
+ });
}
};
};
diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js
index 47bedb80..64961e50 100644
--- a/test/scenario/DSLSpec.js
+++ b/test/scenario/DSLSpec.js
@@ -42,16 +42,41 @@ describe("DSL", function() {
var repeater = angular.scenario.dsl.repeater;
- it('should fetch the count of repeated elements', function() {
+ it('should count', function() {
var future = repeater('.repeater-row').count();
expect(future.name).toEqual("repeater '.repeater-row' count");
- executeFuture(future, "a
" +
- "b
",
- function(value) {
- future.fulfill(value);
+ executeFuture(future,
+ "a
" +
+ "b
",
+ 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,
+ "" +
+ "" +
+ "| John Marston | " +
+ "Red Dead Redemption | " +
+ "
" +
+ "" +
+ "| Nathan Drake | " +
+ "Uncharted 2 | " +
+ "
" +
+ "
",
+ 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');
+ });
});
});
--
cgit v1.2.3
From 21d2b43e6c81b7b6b55599f0274495d25411b4f0 Mon Sep 17 00:00:00 2001
From: Shyam Seshadri
Date: Mon, 9 Aug 2010 17:55:01 -0700
Subject: Add element DSL, to find an element. Has knowledge of finding ng:bind
elements and grabbing their contents.
---
src/scenario/DSL.js | 21 ++++++++++++++++++++-
test/scenario/DSLSpec.js | 37 ++++++++++++++++++++++++++++++++++++-
2 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js
index 13576824..fe834835 100644
--- a/src/scenario/DSL.js
+++ b/src/scenario/DSL.js
@@ -62,7 +62,9 @@ angular.scenario.dsl.repeater = function(selector) {
);
element.find('*').each(function(index) {
var bindName = _jQuery(this).attr('ng:bind');
- element.bindings[bindName] = _jQuery(this).text();
+ if (bindName) {
+ element.bindings[bindName] = _jQuery(this).text();
+ }
});
repeaterArray[index] = element;
});
@@ -73,3 +75,20 @@ angular.scenario.dsl.repeater = function(selector) {
}
};
};
+
+angular.scenario.dsl.element = function(selector) {
+ var nameSuffix = "element '" + selector + "'";
+ return $scenario.addFuture('Find ' + nameSuffix, function(done) {
+ var element = angular.extend(this.testDocument.find(selector), {
+ bindings: [],
+ boundTo: function(name) { return this.bindings[name]; }
+ });
+ element.find('*').each(function(index) {
+ var bindName = _jQuery(this).attr('ng:bind');
+ if (bindName) {
+ element.bindings[bindName] = _jQuery(this).text();
+ }
+ });
+ done(element);
+ });
+};
diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js
index 64961e50..a6a291f8 100644
--- a/test/scenario/DSLSpec.js
+++ b/test/scenario/DSLSpec.js
@@ -41,7 +41,6 @@ describe("DSL", function() {
describe('repeater', function() {
var repeater = angular.scenario.dsl.repeater;
-
it('should count', function() {
var future = repeater('.repeater-row').count();
expect(future.name).toEqual("repeater '.repeater-row' count");
@@ -79,4 +78,40 @@ describe("DSL", function() {
expect(future.value[1].boundTo('game')).toEqual('Uncharted 2');
});
});
+
+ describe('element', function() {
+ var element = angular.scenario.dsl.element;
+ var html;
+ beforeEach(function() {
+ html = '' +
+ '
' +
+ 'Description : ' +
+ 'Details...' +
+ '' +
+ 'Date created: ' +
+ '01/01/01' +
+ '' +
+ '
' +
+ '
';
+ });
+ 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();
+ });
+ });
});
--
cgit v1.2.3
From 86c2ef87d5069f0836079e171c0f33efcf2b5d24 Mon Sep 17 00:00:00 2001
From: Shyam Seshadri
Date: Tue, 10 Aug 2010 10:48:31 -0700
Subject: Inject jquery into future scope, and rename outer scenario to
_window, which is what it is
---
src/scenario/DSL.js | 14 ++++++++------
src/scenario/Runner.js | 1 +
test/scenario/DSLSpec.js | 7 ++++---
test/scenario/RunnerSpec.js | 24 ++++++++++++------------
test/scenario/TestContext.js | 8 ++++----
5 files changed, 29 insertions(+), 25 deletions(-)
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js
index fe834835..d57a61df 100644
--- a/src/scenario/DSL.js
+++ b/src/scenario/DSL.js
@@ -5,7 +5,7 @@ angular.scenario.dsl.browser = {
this.testFrame.load(function(){
self.testFrame.unbind();
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.notifyWhenNoOutstandingRequests =
bind(self.$browser, self.$browser.notifyWhenNoOutstandingRequests);
@@ -53,17 +53,18 @@ angular.scenario.dsl.repeater = function(selector) {
},
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(_jQuery(this),
+ var element = angular.extend(self.jQuery(this),
{bindings: [],
boundTo: function(name) { return this.bindings[name]; }}
);
element.find('*').each(function(index) {
- var bindName = _jQuery(this).attr('ng:bind');
+ var bindName = self.jQuery(this).attr('ng:bind');
if (bindName) {
- element.bindings[bindName] = _jQuery(this).text();
+ element.bindings[bindName] = self.jQuery(this).text();
}
});
repeaterArray[index] = element;
@@ -79,14 +80,15 @@ angular.scenario.dsl.repeater = function(selector) {
angular.scenario.dsl.element = function(selector) {
var nameSuffix = "element '" + selector + "'";
return $scenario.addFuture('Find ' + nameSuffix, function(done) {
+ var self = this;
var element = angular.extend(this.testDocument.find(selector), {
bindings: [],
boundTo: function(name) { return this.bindings[name]; }
});
element.find('*').each(function(index) {
- var bindName = _jQuery(this).attr('ng:bind');
+ var bindName = self.jQuery(this).attr('ng:bind');
if (bindName) {
- element.bindings[bindName] = _jQuery(this).text();
+ element.bindings[bindName] = self.jQuery(this).text();
}
});
done(element);
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 13dfbe7d..ac32559c 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -134,6 +134,7 @@ angular.scenario.Runner.prototype = {
},
specThis = createScope({
result: result,
+ jQuery: this.jQuery,
testFrame: this.testFrame,
testWindow: this.testWindow
}, angularService, {});
diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js
index a6a291f8..374f49c8 100644
--- a/test/scenario/DSLSpec.js
+++ b/test/scenario/DSLSpec.js
@@ -5,15 +5,16 @@ describe("DSL", function() {
beforeEach(function() {
setUpContext();
executeFuture = function(future, html, callback) {
- lastDocument =_jQuery('' + html + '
');
+ lastDocument = _jQuery('' + html + '
');
_jQuery(document.body).append(lastDocument);
var specThis = {
testWindow: window,
- testDocument: lastDocument
+ testDocument: lastDocument,
+ jQuery: _jQuery
};
future.behavior.call(specThis, callback || noop);
};
- Expect = scenario.expect;
+ Expect = _window.expect;
});
describe("input", function() {
diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js
index 2eb13f7f..b12c43c6 100644
--- a/test/scenario/RunnerSpec.js
+++ b/test/scenario/RunnerSpec.js
@@ -4,10 +4,10 @@ describe('Runner', function() {
beforeEach(function() {
setUpContext();
- Describe = scenario.describe;
- It = scenario.it;
- BeforeEach = scenario.beforeEach;
- AfterEach = scenario.afterEach;
+ Describe = _window.describe;
+ It = _window.it;
+ BeforeEach = _window.beforeEach;
+ AfterEach = _window.afterEach;
body = _jQuery('');
});
@@ -101,7 +101,7 @@ describe('Runner', function() {
});
$scenario.run(body);
expect(log).toEqual('future1;after;future2;after;');
- expect(scenario.$testrun.results).toEqual([
+ expect(_window.$testrun.results).toEqual([
{ name : 'describe name: it should text1',
passed : false,
error : 'AfterError',
@@ -186,7 +186,7 @@ describe('Runner', function() {
expect(spec.result.failed).toEqual(true);
expect(spec.result.finished).toEqual(true);
expect(spec.result.error).toEqual("MyError");
- expect(scenario.$testrun.results).toEqual([{
+ expect(_window.$testrun.results).toEqual([{
name: 'spec',
passed: false,
error: 'MyError',
@@ -217,16 +217,16 @@ describe('Runner', function() {
expect(log).toEqual('s1,s2,s3,s4,');
});
it('should publish done state and results as tests are run', function() {
- expect(scenario.$testrun.done).toBeFalsy();
- expect(scenario.$testrun.results).toEqual([]);
+ expect(_window.$testrun.done).toBeFalsy();
+ expect(_window.$testrun.results).toEqual([]);
$scenario.run(body);
- expect(scenario.$testrun.done).toBeFalsy();
- expect(scenario.$testrun.results).toEqual([
+ expect(_window.$testrun.done).toBeFalsy();
+ expect(_window.$testrun.results).toEqual([
{name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']}
]);
next();
- expect(scenario.$testrun.done).toBeTruthy();
- expect(scenario.$testrun.results).toEqual([
+ expect(_window.$testrun.done).toBeTruthy();
+ expect(_window.$testrun.results).toEqual([
{name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']},
{name: 'd1: it it2', passed: true, error: undefined, steps: ['s2', 's2.2']},
{name: 'd2: it it3', passed: true, error: undefined, steps: ['s3']},
diff --git a/test/scenario/TestContext.js b/test/scenario/TestContext.js
index ebb40b95..0c8e6143 100644
--- a/test/scenario/TestContext.js
+++ b/test/scenario/TestContext.js
@@ -1,4 +1,4 @@
-var scenario, runner, log, $scenario;
+var _window, runner, log, $scenario;
function logger(text) {
return function(done){
@@ -8,8 +8,8 @@ function logger(text) {
}
function setUpContext() {
- scenario = {};
- runner = new angular.scenario.Runner(scenario, _jQuery);
- $scenario = scenario.$scenario;
+ _window = {};
+ runner = new angular.scenario.Runner(_window, _jQuery);
+ $scenario = _window.$scenario;
log = '';
}
--
cgit v1.2.3