dwf: refactored Jasmine for less coupling; adding Crockford's helper

methods; crafted a new 'bootstrap' test in order to allow name
collisions with JSpec; better formatting of results in bootstrap test.
This commit is contained in:
Davis W. Frank
2008-11-29 18:12:55 -08:00
parent a2802923e2
commit 9f2d3e0540
10 changed files with 4611 additions and 45 deletions

View File

@@ -20,44 +20,63 @@ Function.prototype.method = function (name, func) {
******************************************************************************/
/*
* Jasmine expectation constructor
* Matchers methods; add your own with Matchers.method()
*/
var expects = function (actual) {
var that = {};
that.actual = actual;
that.should_equal = function(expected) {
var message = 'Passed.';
result = (that.actual === expected);
if (!result) {
message = 'Expected ' + expected + ' but got ' + that.actual + '.';
}
Jasmine.results.push({
passed: result,
message: message
});
return result;
}
return that;
Matchers = function (actual) {
this.actual = actual;
this.passing_message = 'Passed.'
}
var spec = function (description, func) {
Matchers.method('report', function (result, failing_message) {
Jasmine.results.push({
passed: result,
message: result ? this.passing_message : failing_message
});
return result;
});
Matchers.method('should_equal', function (expected) {
return this.report((this.actual === expected),
'Expected ' + expected + ' but got ' + this.actual + '.');
});
Matchers.method('should_not_equal', function (expected) {
return this.report((this.actual !== expected),
'Expected ' + expected + ' to not equal ' + this.actual + ', but it does.');
});
/*
* expects helper method that allows for chaining Matcher
*/
var expects_that = function (actual) {
return new Matchers(actual);
}
/*
* Jasmine spec constructor
*/
var it = function (description, func) {
return {
description: description,
execute: func
}
}
/*
* Jasmine constructor
*/
var jasmine_init = function () {
return {
results: []
}
}
/*
* Jasmine instance
*/
var Jasmine = jasmine_init();
// spec: {
@@ -78,4 +97,3 @@ var Jasmine = jasmine_init();
//var JasmineSpec = function(description, func) {
//
//}