added error handling on scenario definition

This commit is contained in:
Andres Ornelas 2010-05-24 15:25:30 -07:00
parent f6c67e28c9
commit 3fab5d9879
10 changed files with 67 additions and 27 deletions

View file

@ -7,6 +7,7 @@ load:
- test/jquery_alias.js
- src/Angular.js
- src/*.js
- src/scenario/Runner.js
- src/scenario/*.js
- test/testabilityPatch.js
- test/angular-mocks.js

View file

@ -7,6 +7,7 @@ load:
- test/jquery_remove.js
- src/Angular.js
- src/*.js
- src/scenario/Runner.js
- src/scenario/*.js
- test/testabilityPatch.js
- test/angular-mocks.js

View file

@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="../src/scenario/bootstrap.js"></script>
<script type="text/javascript" src="widgets-scenario2.js"></script>
<script type="text/javascript" src="widgets-scenario.js"></script>
</head>
<body>
</body>

View file

@ -0,0 +1,20 @@
describe('widgets', function(){
it('should verify that basic widgets work', function(){
browser.navigateTo('widgets.html');
expect('{{text.basic}}').toEqual('');
input('text.basic').enter('John');
expect('{{text.basic}}').toEqual('John');
expect('{{text.password}}').toEqual('');
input('text.password').enter('secret');
expect('{{text.password}}').toEqual('secret');
expect('{{text.hidden}}').toEqual('hiddenValue');
expect('{{gender}}').toEqual('male');
input('gender').select('female');
expect('{{gender}}').toEqual('female');
});
});

View file

@ -26,8 +26,8 @@
</tr>
<tr>
<td>hidden</td>
<td><input type="hidden" name="hidden" value="hiddenValue" /></td>
<td>hidden={{hidden}}</td>
<td><input type="hidden" name="text.hidden" value="hiddenValue" /></td>
<td>text.hidden={{text.hidden}}</td>
</tr>
<tr><th colspan="3">Input selection field</th></tr>
<tr>

View file

@ -1,4 +1,4 @@
browser = {
angular.scenario.dsl.browser = {
navigateTo: function(url){
$scenario.addStep('Navigate to: ' + url, function(done){
var self = this;
@ -16,21 +16,22 @@ browser = {
}
};
function input(selector) {
angular.scenario.dsl.input = function(selector) {
return {
enter: function(value){
$scenario.addStep("Set input text of '" + selector + "' to value '" + value + "'", function(done){
var input = this.testDocument.find('input[name=' + selector + ']');
input.val(value);
input.trigger('change');
this.testWindow.angular.element(input[0]).trigger('change');
done();
$scenario.addStep("Set input text of '" + selector + "' to value '" +
value + "'", function(done){
var input = this.testDocument.find('input[name=' + selector + ']');
input.val(value);
input.trigger('change');
this.testWindow.angular.element(input[0]).trigger('change');
done();
});
}
};
}
};
function expect(selector) {
angular.scenario.dsl.expect = function(selector) {
return {
toEqual: function(expected) {
$scenario.addStep("Expect that " + selector + " equals '" + expected + "'", function(done){
@ -43,13 +44,4 @@ function expect(selector) {
});
}
};
}
describe('widgets', function(){
it('should verify that basic widgets work', function(){
browser.navigateTo('widgets.html');
expect('{{text.basic}}').toEqual('');
input('text.basic').enter('John');
expect('{{text.basic}}').toEqual('John');
});
});
};

View file

@ -1,9 +1,11 @@
angular['scenario'] = (angular['scenario'] = {});
angular['scenario'] = (angular['scenario'] = {});
angular.scenario['dsl'] = (angular.scenario['dsl'] = {});
angular.scenario.Runner = function(scope, jQuery){
var self = scope.$scenario = this;
this.scope = scope;
this.jQuery = jQuery;
angular.extend(scope, angular.scenario.dsl);
var specs = this.specs = {};
var path = [];
@ -18,7 +20,13 @@ angular.scenario.Runner = function(scope, jQuery){
name: specName,
steps:[]
};
body();
try {
body();
} catch(err) {
self.addStep(err.message || 'ERROR', function(){
throw err;
});
}
self.currentSpec = null;
};
this.logger = function returnNoop(){
@ -55,6 +63,7 @@ angular.scenario.Runner.prototype = {
return angular.extend(logger(element), {
close: function(){
element.removeClass('running');
console.scrollTop(console[0].scrollHeight);
},
fail: function(){
element.removeClass('running');
@ -66,7 +75,7 @@ angular.scenario.Runner.prototype = {
current = current.parent();
}
}
});;
});
};
}
this.logger = logger(console);

View file

@ -29,6 +29,7 @@
addScript("../../lib/jquery/jquery-1.4.2.js");
addScript("../angular-bootstrap.js");
addScript("Runner.js");
addScript("DSL.js");
document.write('<script type="text/javascript">' +
'$scenarioRunner = new angular.scenario.Runner(window, jQuery);' +
'</script>');

View file

@ -37,7 +37,23 @@ describe('Runner', function(){
});
it('should camplain on duplicate it', angular.noop);
it('should create a failing step if there is a javascript error', function(){
var spec;
Describe('D1', function(){
It('I1', function(){
spec = $scenario.currentSpec;
throw {message: 'blah'};
});
});
var step = spec.steps[0];
expect(step.name).toEqual('blah');
try {
step.fn();
fail();
} catch (e) {
expect(e.message).toEqual('blah');
};
});
});
});