2008-11-30 02:12:55 +00:00
|
|
|
// Bootstrap Test Reporter function
|
|
|
|
var reporter = function () {
|
|
|
|
|
|
|
|
var total = 0;
|
|
|
|
var passes = 0;
|
|
|
|
var fails = 0;
|
|
|
|
|
|
|
|
var that = {
|
|
|
|
test: function (result, message) {
|
|
|
|
total++;
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
passes++;
|
|
|
|
iconElement = $('icons');
|
|
|
|
iconElement.appendChild(new Element('img', {src: '../images/accept.png'}));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fails++;
|
2008-12-01 20:26:12 +00:00
|
|
|
var fails_report = $('fails');
|
|
|
|
fails_report.show();
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
iconElement = $('icons');
|
|
|
|
iconElement.appendChild(new Element('img', {src: '../images/exclamation.png'}));
|
|
|
|
|
|
|
|
var failMessages = $('fail_messages');
|
2008-12-01 20:26:12 +00:00
|
|
|
var newFail = new Element('p', {'class': 'fail'});
|
2008-11-30 02:12:55 +00:00
|
|
|
newFail.innerHTML = message;
|
|
|
|
failMessages.appendChild(newFail);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
summary: function () {
|
2008-12-01 20:26:12 +00:00
|
|
|
summary = new Element('p', {'class': ((fails > 0) ? 'fail_in_summary' : '') });
|
|
|
|
summary.innerHTML = total + ' tests, ' + passes + ' passing, ' + fails + ' failed.';
|
|
|
|
|
|
|
|
var summaryElement = $('results_summary');
|
|
|
|
summaryElement.appendChild(summary);
|
|
|
|
summaryElement.show();
|
2008-11-30 02:12:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return that;
|
|
|
|
}();
|
|
|
|
|
|
|
|
var testMatchersComparisons = function () {
|
|
|
|
Jasmine = jasmine_init();
|
|
|
|
reporter.test(expects_that(true).should_equal(true),
|
2008-12-01 20:26:12 +00:00
|
|
|
'expects_that(true).should_equal(true) returned false');
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
reporter.test(!(expects_that(false).should_equal(true)),
|
2008-12-01 20:26:12 +00:00
|
|
|
'expects_that(true).should_equal(true) returned true');
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
reporter.test(expects_that(true).should_not_equal(false),
|
2008-12-01 20:26:12 +00:00
|
|
|
'expects_that(true).should_not_equal(false) retruned false');
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
reporter.test(!(expects_that(true).should_not_equal(true)),
|
2008-12-01 20:26:12 +00:00
|
|
|
'expects_that(true).should_not_equal(false) retruned true');
|
2008-11-30 02:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var testMatchersReporting = function () {
|
|
|
|
Jasmine = jasmine_init();
|
|
|
|
|
|
|
|
expects_that(true).should_equal(true);
|
|
|
|
expects_that(false).should_equal(true);
|
|
|
|
|
|
|
|
reporter.test((Jasmine.results.length == 2),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Jasmine results array doesn't have 2 results");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
reporter.test((Jasmine.results[0].passed == true),
|
2008-12-01 20:26:12 +00:00
|
|
|
"First spec didn't pass");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
reporter.test((Jasmine.results[1].passed == false),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Second spec did pass");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
Jasmine = jasmine_init();
|
|
|
|
|
|
|
|
expects_that(false).should_equal(true);
|
|
|
|
|
|
|
|
reporter.test((Jasmine.results[0].message == 'Expected true but got false.'),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Failed expectation didn't test the failure message");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
Jasmine = jasmine_init();
|
|
|
|
|
|
|
|
expects_that(true).should_equal(true);
|
|
|
|
|
|
|
|
reporter.test((Jasmine.results[0].message == 'Passed.'),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Passing expectation didn't test the passing message");
|
2008-11-30 02:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var testSpecs = function () {
|
|
|
|
Jasmine = jasmine_init();
|
|
|
|
var spec = it('new spec');
|
|
|
|
reporter.test((spec.description == 'new spec'),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Spec did not have a description");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
Jasmine = jasmine_init();
|
2008-12-01 20:26:12 +00:00
|
|
|
var another_spec = it('spec with an expectation', function () {
|
2008-11-30 02:12:55 +00:00
|
|
|
var foo = 'bar';
|
|
|
|
expects_that(foo).should_equal('bar');
|
|
|
|
});
|
|
|
|
another_spec.execute();
|
2008-12-01 20:26:12 +00:00
|
|
|
another_spec.done = true;
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
reporter.test((Jasmine.results.length == 1),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Results aren't there after a spec was executed");
|
2008-11-30 02:12:55 +00:00
|
|
|
reporter.test((Jasmine.results[0].passed == true),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Results has a result, but it's true");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
Jasmine = jasmine_init();
|
|
|
|
var yet_another_spec = it('spec with failing expectation', function () {
|
|
|
|
var foo = 'bar';
|
|
|
|
expects_that(foo).should_equal('baz');
|
|
|
|
});
|
|
|
|
yet_another_spec.execute();
|
2008-12-01 20:26:12 +00:00
|
|
|
another_spec.done = true;
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
reporter.test((Jasmine.results[0].passed == false),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Expectation that failed, passed");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
Jasmine = jasmine_init();
|
|
|
|
var yet_yet_another_spec = it('spec with multiple assertions', function () {
|
|
|
|
var foo = 'bar';
|
|
|
|
var baz = 'quux';
|
|
|
|
|
|
|
|
expects_that(foo).should_equal('bar');
|
|
|
|
expects_that(baz).should_equal('quux');
|
|
|
|
});
|
|
|
|
yet_yet_another_spec.execute();
|
2008-12-01 20:26:12 +00:00
|
|
|
another_spec.done = true;
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
reporter.test((Jasmine.results.length == 2),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Spec doesn't support multiple expectations");
|
|
|
|
}
|
|
|
|
|
|
|
|
var testAsyncSpecs = function () {
|
|
|
|
Jasmine = jasmine_init();
|
|
|
|
var foo = 0;
|
|
|
|
|
|
|
|
var a_spec = it_async('simple queue test').
|
|
|
|
runs(function () {
|
|
|
|
foo++;
|
|
|
|
}).then(function() {
|
|
|
|
expects_that(foo).should_equal(1)
|
|
|
|
});
|
|
|
|
|
|
|
|
reporter.test(a_spec.queue.length === 2,
|
|
|
|
'Spec queue length is not 2');
|
|
|
|
|
|
|
|
Jasmine = jasmine_init();
|
|
|
|
foo = 0;
|
|
|
|
a_spec = it_async('spec w/ queued statments').
|
|
|
|
runs(function () {
|
|
|
|
foo++;
|
|
|
|
}).then(function() {
|
2008-12-01 22:24:13 +00:00
|
|
|
expects_that(foo).should_equal(1);
|
2008-12-01 20:26:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
a_spec.execute();
|
|
|
|
|
|
|
|
reporter.test((Jasmine.results.length === 1),
|
2008-12-01 22:24:13 +00:00
|
|
|
'No call to waits(): Spec queue did not run all functions');
|
2008-12-01 20:26:12 +00:00
|
|
|
reporter.test((Jasmine.results[0].passed === true),
|
2008-12-01 22:24:13 +00:00
|
|
|
'No call to waits(): Queued expectation failed');
|
2008-12-01 20:26:12 +00:00
|
|
|
|
|
|
|
Jasmine = jasmine_init();
|
|
|
|
foo = 0;
|
|
|
|
a_spec = it_async('spec w/ queued statments').
|
|
|
|
runs(function () {
|
2008-12-01 22:24:13 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
foo++
|
|
|
|
}, 500);
|
|
|
|
}).waits(1000).
|
|
|
|
then(function() {
|
|
|
|
expects_that(foo).should_equal(1);
|
|
|
|
});
|
2008-12-01 20:26:12 +00:00
|
|
|
|
|
|
|
a_spec.execute();
|
2008-12-01 22:24:13 +00:00
|
|
|
setTimeout(function(){
|
|
|
|
reporter.test((Jasmine.results.length === 1),
|
|
|
|
'Calling waits(): Spec queue did not run all functions');
|
2008-12-01 20:26:12 +00:00
|
|
|
|
2008-12-01 22:24:13 +00:00
|
|
|
reporter.test((Jasmine.results[0].passed === true),
|
|
|
|
'Calling waits(): Queued expectation failed');
|
|
|
|
}, 1250);
|
2008-11-30 02:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var runTests = function () {
|
|
|
|
$('spinner').show();
|
|
|
|
|
2008-12-01 22:24:13 +00:00
|
|
|
testMatchersComparisons();
|
|
|
|
testMatchersReporting();
|
|
|
|
testSpecs();
|
2008-12-01 20:26:12 +00:00
|
|
|
testAsyncSpecs();
|
2008-12-01 22:24:13 +00:00
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
$('spinner').hide();
|
|
|
|
reporter.summary();
|
|
|
|
}, 1500);
|
2008-12-01 20:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//it('should be an async test') {
|
|
|
|
// run(function() {setup}).and.wait(2000).then.expects_that(true).should_equal(true).and.expects_that
|
|
|
|
//}
|
|
|
|
|
|
|
|
|