2008-11-27 22:30:46 +00:00
|
|
|
// Crockford's helpers
|
|
|
|
|
|
|
|
// Object.create instead of new Object
|
|
|
|
if (typeof Object.create !== 'function') {
|
|
|
|
Object.create = function (o) {
|
2008-12-01 22:24:13 +00:00
|
|
|
var F = function () {
|
|
|
|
};
|
|
|
|
F.prototype = o;
|
|
|
|
return new F();
|
2008-11-27 22:30:46 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Klass.method instead of Klass.prototype.name = function
|
2008-12-01 20:26:12 +00:00
|
|
|
if (typeof Function.method !== 'function') {
|
|
|
|
Function.prototype.method = function (name, func) {
|
|
|
|
this.prototype[name] = func;
|
|
|
|
return this;
|
|
|
|
}
|
2008-11-27 22:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Jasmine
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/*
|
2008-11-30 02:12:55 +00:00
|
|
|
* Matchers methods; add your own with Matchers.method()
|
2008-11-27 22:30:46 +00:00
|
|
|
*/
|
2008-12-01 23:59:41 +00:00
|
|
|
Matchers = function (actual, results) {
|
2008-11-30 02:12:55 +00:00
|
|
|
this.actual = actual;
|
|
|
|
this.passing_message = 'Passed.'
|
2008-12-01 23:59:41 +00:00
|
|
|
this.results = results || [];
|
2008-11-30 02:12:55 +00:00
|
|
|
}
|
2008-11-27 22:30:46 +00:00
|
|
|
|
2008-11-30 02:12:55 +00:00
|
|
|
Matchers.method('report', function (result, failing_message) {
|
2008-11-27 22:30:46 +00:00
|
|
|
|
2008-12-01 23:59:41 +00:00
|
|
|
this.results.push({
|
2008-11-30 02:12:55 +00:00
|
|
|
passed: result,
|
|
|
|
message: result ? this.passing_message : failing_message
|
|
|
|
});
|
2008-11-27 22:30:46 +00:00
|
|
|
|
2008-11-30 02:12:55 +00:00
|
|
|
return result;
|
|
|
|
});
|
|
|
|
|
|
|
|
Matchers.method('should_equal', function (expected) {
|
|
|
|
return this.report((this.actual === expected),
|
2008-12-01 22:24:13 +00:00
|
|
|
'Expected ' + expected + ' but got ' + this.actual + '.');
|
|
|
|
|
2008-11-30 02:12:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Matchers.method('should_not_equal', function (expected) {
|
|
|
|
return this.report((this.actual !== expected),
|
2008-12-01 22:24:13 +00:00
|
|
|
'Expected ' + expected + ' to not equal ' + this.actual + ', but it does.');
|
2008-11-30 02:12:55 +00:00
|
|
|
});
|
2008-11-27 22:30:46 +00:00
|
|
|
|
2008-11-30 02:12:55 +00:00
|
|
|
/*
|
|
|
|
* Jasmine spec constructor
|
|
|
|
*/
|
2008-12-01 20:26:12 +00:00
|
|
|
|
2008-12-01 22:24:13 +00:00
|
|
|
var queuedFunction = function(func, timeout, spec) {
|
|
|
|
var that = {
|
|
|
|
func: func,
|
2008-12-01 23:15:34 +00:00
|
|
|
next: function () {
|
|
|
|
spec.finish(); // default value is to be done after one function
|
|
|
|
},
|
|
|
|
execute: function () {
|
2008-12-01 22:24:13 +00:00
|
|
|
if (timeout > 0) {
|
|
|
|
setTimeout(function () {
|
2008-12-01 23:59:41 +00:00
|
|
|
that.func.apply(spec);
|
2008-12-01 22:24:13 +00:00
|
|
|
that.next();
|
|
|
|
}, timeout);
|
|
|
|
} else {
|
2008-12-01 23:59:41 +00:00
|
|
|
that.func.apply(spec);
|
2008-12-01 22:24:13 +00:00
|
|
|
that.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return that;
|
|
|
|
}
|
|
|
|
|
2008-12-01 23:59:41 +00:00
|
|
|
|
2008-12-01 23:15:34 +00:00
|
|
|
var it = function (description) {
|
2008-12-01 20:26:12 +00:00
|
|
|
var that = {
|
|
|
|
description: description,
|
|
|
|
queue: [],
|
2008-12-01 22:24:13 +00:00
|
|
|
currentTimeout: 0,
|
2008-12-02 00:32:14 +00:00
|
|
|
finished: false,
|
|
|
|
suite: {next:function() {}},
|
2008-12-01 23:59:41 +00:00
|
|
|
results: [],
|
|
|
|
|
|
|
|
expects_that: function (actual) {
|
|
|
|
return new Matchers(actual, that.results);
|
|
|
|
},
|
2008-12-01 23:15:34 +00:00
|
|
|
|
2008-12-01 20:26:12 +00:00
|
|
|
waits: function (timeout) {
|
2008-12-01 22:24:13 +00:00
|
|
|
that.currentTimeout = timeout;
|
2008-12-01 20:26:12 +00:00
|
|
|
return that;
|
|
|
|
},
|
2008-12-01 23:15:34 +00:00
|
|
|
|
2008-12-01 22:24:13 +00:00
|
|
|
resetTimeout: function() {
|
|
|
|
that.currentTimeout = 0;
|
|
|
|
},
|
2008-12-01 23:15:34 +00:00
|
|
|
|
2008-12-01 22:24:13 +00:00
|
|
|
finish: function() {
|
2008-12-02 00:32:14 +00:00
|
|
|
that.finished = true;
|
2008-12-01 22:24:13 +00:00
|
|
|
},
|
2008-12-01 23:15:34 +00:00
|
|
|
|
2008-12-01 20:26:12 +00:00
|
|
|
execute: function () {
|
2008-12-01 22:24:13 +00:00
|
|
|
if (that.queue[0]) {
|
|
|
|
that.queue[0].execute();
|
2008-12-01 20:26:12 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-01 22:24:13 +00:00
|
|
|
};
|
2008-12-01 20:26:12 +00:00
|
|
|
|
|
|
|
var addToQueue = function(func) {
|
2008-12-01 23:15:34 +00:00
|
|
|
var currentFunction = queuedFunction(func, that.currentTimeout, that);
|
2008-12-01 22:24:13 +00:00
|
|
|
that.queue.push(currentFunction);
|
2008-12-01 23:15:34 +00:00
|
|
|
|
|
|
|
if (that.queue.length > 1) {
|
|
|
|
var previousFunction = that.queue[that.queue.length - 2];
|
|
|
|
previousFunction.next = function () {
|
2008-12-01 22:24:13 +00:00
|
|
|
currentFunction.execute();
|
|
|
|
}
|
|
|
|
}
|
2008-12-01 23:15:34 +00:00
|
|
|
|
2008-12-01 22:24:13 +00:00
|
|
|
that.resetTimeout();
|
2008-12-01 23:15:34 +00:00
|
|
|
|
2008-12-01 20:26:12 +00:00
|
|
|
return that;
|
2008-11-27 22:30:46 +00:00
|
|
|
}
|
2008-12-01 20:26:12 +00:00
|
|
|
|
|
|
|
that.runs = addToQueue;
|
|
|
|
that.then = addToQueue;
|
|
|
|
|
|
|
|
return that;
|
2008-11-27 22:30:46 +00:00
|
|
|
}
|
|
|
|
|
2008-12-01 20:26:12 +00:00
|
|
|
|
2008-11-30 02:12:55 +00:00
|
|
|
/*
|
|
|
|
* Jasmine constructor
|
|
|
|
*/
|
2008-11-27 22:30:46 +00:00
|
|
|
var jasmine_init = function () {
|
|
|
|
return {
|
|
|
|
results: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-30 02:12:55 +00:00
|
|
|
/*
|
|
|
|
* Jasmine instance
|
|
|
|
*/
|
2008-11-27 22:30:46 +00:00
|
|
|
var Jasmine = jasmine_init();
|
|
|
|
|
2008-12-01 20:26:12 +00:00
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* - add spec or description to results
|
2008-12-02 00:32:14 +00:00
|
|
|
//* - spec.execute needs to wait until the spec is done
|
|
|
|
//* - an async test will be killed after X ms if not done and then listed as failed with an "async fail" message of some sort
|
2008-12-01 20:26:12 +00:00
|
|
|
* - Suite to run tests in order, constructed with a function called describe
|
|
|
|
* - Suite supports before
|
|
|
|
* - Suite supports after
|
|
|
|
* - Suite supports before_each
|
|
|
|
* - Suite supports after_each
|
|
|
|
* - Suite supports asynch
|
|
|
|
* - Runner that runs suites in order
|
|
|
|
* - Runner supports async
|
|
|
|
* - HTML reporter
|
|
|
|
* - Shows pass/fail progress (just like bootstrap reporter)
|
|
|
|
* - Lists a Summary: total # specs, # of passed, # of failed
|
|
|
|
* - Failed reports lists all specs that failed and what the failure was
|
|
|
|
* - Failed output is styled with red
|
|
|
|
* - JSON reporter
|
|
|
|
* - Lists full results as a JSON object/string
|
|
|
|
* - Luna reporter
|
|
|
|
* - each result calls back into widgets for rendering to Luna views
|
|
|
|
*/
|
|
|
|
|