Skip to content

Commit 9d8646b

Browse files
author
Andres Ornelas
committed
all tests passing with new futures concept
1 parent e664186 commit 9d8646b

5 files changed

Lines changed: 111 additions & 102 deletions

File tree

src/scenario/DSL.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
angular.scenario.dsl.browser = {
22
navigateTo: function(url){
3-
$scenario.addStep('Navigate to: ' + url, function(done){
3+
$scenario.addFuture('Navigate to: ' + url, function(done){
44
var self = this;
55
this.testFrame.load(function(){
66
self.testFrame.unbind();
@@ -22,7 +22,7 @@ angular.scenario.dsl.browser = {
2222
angular.scenario.dsl.input = function(selector) {
2323
return {
2424
enter: function(value){
25-
$scenario.addStep("Set input text of '" + selector + "' to '" +
25+
$scenario.addFuture("Set input text of '" + selector + "' to '" +
2626
value + "'", function(done){
2727
var input = this.testDocument.find('input[name=' + selector + ']');
2828
input.val(value);
@@ -31,7 +31,7 @@ angular.scenario.dsl.input = function(selector) {
3131
});
3232
},
3333
select: function(value){
34-
$scenario.addStep("Select radio '" + selector + "' to '" +
34+
$scenario.addFuture("Select radio '" + selector + "' to '" +
3535
value + "'", function(done){
3636
var input = this.testDocument.
3737
find(':radio[name$=@' + selector + '][value=' + value + ']');
@@ -49,7 +49,7 @@ angular.scenario.dsl.expect = {
4949
return {
5050
count: {
5151
toEqual: function(number) {
52-
$scenario.addStep("Expect that there are " + number + " items in Repeater with selector '" + selector + "'", function(done) {
52+
$scenario.addFuture("Expect that there are " + number + " items in Repeater with selector '" + selector + "'", function(done) {
5353
var items = this.testDocument.find(selector);
5454
if (items.length != number) {
5555
this.result.fail("Expected " + number + " but was " + items.length);

src/scenario/Future.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function Future(name, behavior) {
2-
this.value = undefined;
32
this.name = name;
43
this.behavior = behavior;
54
this.fulfilled = false;
5+
this.value = undefined;
66
}
77

88
Future.prototype = {
@@ -11,25 +11,6 @@ Future.prototype = {
1111
this.value = value;
1212
}
1313
};
14-
15-
function future(name, behavior) {
16-
return new Future(name, behavior);
17-
};
18-
19-
function repeater(selector) {
20-
var repeaterFuture = future('repeater ' + selector, function(done) {
21-
done($(selector));
22-
});
23-
24-
repeaterFuture.count = function(){
25-
return future(repeaterFuture.name + ' count', function(done) {
26-
done(repeaterFuture.value.size());
27-
});
28-
};
29-
30-
return repeaterFuture;
31-
}
32-
3314
function Matcher(future, logger) {
3415
var self = this;
3516
this.logger = logger;
@@ -52,6 +33,28 @@ Matcher.addMatcher = function(name, matcher){
5233

5334
Matcher.addMatcher('toEqual', function(a,b){ return a == b; });
5435

55-
function expect(future) {
36+
/*
37+
38+
function future(name, behavior) {
39+
return new Future(name, behavior);
40+
};
41+
42+
function repeater(selector) {
43+
var repeaterFuture = future('repeater ' + selector, function(done) {
44+
done($(selector));
45+
});
46+
47+
repeaterFuture.count = function(){
48+
return future(repeaterFuture.name + ' count', function(done) {
49+
done(repeaterFuture.value.size());
50+
});
51+
};
52+
53+
return repeaterFuture;
54+
}
55+
56+
function expectX(future) {
5657
return new Matcher(future, window.alert);
5758
}
59+
60+
*/

src/scenario/Runner.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ angular.scenario.Runner = function(scope, jQuery){
2626
var specName = path.join(' ') + ': it ' + name;
2727
self.currentSpec = specs[specName] = {
2828
name: specName,
29-
steps:[]
29+
futures: []
3030
};
3131
try {
3232
beforeEach();
3333
body();
3434
} catch(err) {
35-
self.addStep(err.message || 'ERROR', function(){
35+
self.addFuture(err.message || 'ERROR', function(){
3636
throw err;
3737
});
3838
} finally {
@@ -107,14 +107,16 @@ angular.scenario.Runner.prototype = {
107107
callback();
108108
},
109109

110-
addStep: function(name, step) {
111-
this.currentSpec.steps.push({name:name, fn:step});
110+
addFuture: function(name, behavior) {
111+
var future = new Future(name, behavior);
112+
this.currentSpec.futures.push(future);
113+
return future;
112114
},
113115

114116
execute: function(name, callback) {
115117
var spec = this.specs[name],
116118
self = this,
117-
stepsDone = [],
119+
futuresFulfilled = [],
118120
result = {
119121
passed: false,
120122
failed: false,
@@ -132,29 +134,32 @@ angular.scenario.Runner.prototype = {
132134
testWindow: this.testWindow
133135
}, angularService, {});
134136
this.self = specThis;
135-
var stepLogger = this.logger('spec', name);
136-
spec.nextStepIndex = 0;
137+
var futureLogger = this.logger('spec', name);
138+
spec.nextFutureIndex = 0;
137139
function done() {
138140
result.finished = true;
139-
stepLogger.close();
141+
futureLogger.close();
140142
self.self = null;
141143
(callback||noop).call(specThis);
142144
}
143-
function next(){
144-
var step = spec.steps[spec.nextStepIndex];
145+
function next(value){
146+
if (spec.nextFutureIndex > 0) {
147+
spec.futures[spec.nextFutureIndex - 1].fulfill(value);
148+
}
149+
var future = spec.futures[spec.nextFutureIndex];
145150
(result.log || {close:noop}).close();
146151
result.log = null;
147-
if (step) {
148-
spec.nextStepIndex ++;
149-
result.log = stepLogger('step', step.name);
150-
stepsDone.push(step.name);
152+
if (future) {
153+
spec.nextFutureIndex ++;
154+
result.log = futureLogger('future', future.name);
155+
futuresFulfilled.push(future.name);
151156
try {
152-
step.fn.call(specThis, next);
157+
future.behavior.call(specThis, next);
153158
} catch (e) {
154159
console.error(e);
155160
result.fail(e);
156161
self.scope.$testrun.results.push(
157-
{name: name, passed: false, error: e, steps: stepsDone});
162+
{name: name, passed: false, error: e, steps: futuresFulfilled});
158163
done();
159164
}
160165
} else {
@@ -163,7 +168,7 @@ angular.scenario.Runner.prototype = {
163168
name: name,
164169
passed: !result.failed,
165170
error: result.error,
166-
steps: stepsDone});
171+
steps: futuresFulfilled});
167172
done();
168173
}
169174
};

test/scenario/DSLSpec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
describe("DSL", function() {
22

3-
var lastStep, executeStep, lastDocument;
3+
var lastFuture, executeFuture, lastDocument;
44

55
beforeEach(function() {
6-
lastStep = null;
6+
lastFuture = null;
77
$scenario = {
8-
addStep: function(name, stepFunction) {
9-
lastStep = { name:name, fn: stepFunction};
8+
addFuture: function(name, behavior) {
9+
lastFuture = { name:name, behavior: behavior};
1010
}
1111
};
12-
executeStep = function(step, html, callback) {
12+
executeFuture = function(future, html, callback) {
1313
lastDocument =_jQuery('<div>' + html + '</div>');
1414
_jQuery(document.body).append(lastDocument);
1515
var specThis = {
1616
testWindow: window,
1717
testDocument: lastDocument
1818
};
19-
step.fn.call(specThis, callback || noop);
19+
future.behavior.call(specThis, callback || noop);
2020
};
2121
});
2222

@@ -25,15 +25,15 @@ describe("DSL", function() {
2525
var input = angular.scenario.dsl.input;
2626
it('should enter', function() {
2727
input('name').enter('John');
28-
expect(lastStep.name).toEqual("Set input text of 'name' to 'John'");
29-
executeStep(lastStep, '<input type="text" name="name" />');
28+
expect(lastFuture.name).toEqual("Set input text of 'name' to 'John'");
29+
executeFuture(lastFuture, '<input type="text" name="name" />');
3030
expect(lastDocument.find('input').val()).toEqual('John');
3131
});
3232

3333
it('should select', function() {
3434
input('gender').select('female');
35-
expect(lastStep.name).toEqual("Select radio 'gender' to 'female'");
36-
executeStep(lastStep,
35+
expect(lastFuture.name).toEqual("Select radio 'gender' to 'female'");
36+
executeFuture(lastFuture,
3737
'<input type="radio" name="0@gender" value="male" checked/>' +
3838
'<input type="radio" name="0@gender" value="female"/>');
3939
expect(lastDocument.find(':radio:checked').length).toEqual(1);
@@ -46,9 +46,9 @@ describe("DSL", function() {
4646
describe('repeater', function() {
4747
it('should check the count of repeated elements', function() {
4848
dslExpect.repeater('.repeater-row').count.toEqual(2);
49-
expect(lastStep.name).toEqual("Expect that there are 2 items in Repeater with selector '.repeater-row'");
49+
expect(lastFuture.name).toEqual("Expect that there are 2 items in Repeater with selector '.repeater-row'");
5050
var html = "<div class='repeater-row'>a</div><div class='repeater-row'>b</div>";
51-
executeStep(lastStep, html);
51+
executeFuture(lastFuture, html);
5252
});
5353
});
5454
});

0 commit comments

Comments
 (0)