Added statement chaining to specs
This commit is contained in:
89
lib/jasmine.js
Normal file → Executable file
89
lib/jasmine.js
Normal file → Executable file
@@ -10,9 +10,11 @@ if (typeof Object.create !== 'function') {
|
||||
}
|
||||
|
||||
// Klass.method instead of Klass.prototype.name = function
|
||||
Function.prototype.method = function (name, func) {
|
||||
this.prototype[name] = func;
|
||||
return this;
|
||||
if (typeof Function.method !== 'function') {
|
||||
Function.prototype.method = function (name, func) {
|
||||
this.prototype[name] = func;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@@ -49,7 +51,7 @@ Matchers.method('should_not_equal', function (expected) {
|
||||
});
|
||||
|
||||
/*
|
||||
* expects helper method that allows for chaining Matcher
|
||||
* expects_hat helper method that allows for chaining Matcher
|
||||
*/
|
||||
var expects_that = function (actual) {
|
||||
return new Matchers(actual);
|
||||
@@ -59,12 +61,45 @@ var expects_that = function (actual) {
|
||||
* Jasmine spec constructor
|
||||
*/
|
||||
var it = function (description, func) {
|
||||
return {
|
||||
var that = {
|
||||
description: description,
|
||||
execute: func
|
||||
func: func,
|
||||
done: false,
|
||||
execute: function() {
|
||||
that.func.apply(that);
|
||||
}
|
||||
}
|
||||
return that;
|
||||
}
|
||||
|
||||
var it_async = function (description) {
|
||||
var that = {
|
||||
description: description,
|
||||
queue: [],
|
||||
waits: function (timeout) {
|
||||
return that;
|
||||
},
|
||||
done: false,
|
||||
execute: function () {
|
||||
for(i = 0; i < that.queue.length; i++) {
|
||||
that.queue[i]();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var addToQueue = function(func) {
|
||||
that.queue.push(func);
|
||||
return that;
|
||||
}
|
||||
|
||||
that.runs = addToQueue;
|
||||
that.then = addToQueue;
|
||||
|
||||
return that;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Jasmine constructor
|
||||
*/
|
||||
@@ -79,21 +114,27 @@ var jasmine_init = function () {
|
||||
*/
|
||||
var Jasmine = jasmine_init();
|
||||
|
||||
// spec: {
|
||||
// description: description,
|
||||
// func: func,
|
||||
// execute: function() {with(jasmine) {func();}}
|
||||
// },
|
||||
//
|
||||
// expects_that: function(actual) {
|
||||
//
|
||||
// this.actual = actual;
|
||||
// return this;
|
||||
// },
|
||||
//
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//var JasmineSpec = function(description, func) {
|
||||
//
|
||||
//}
|
||||
/*
|
||||
* TODO:
|
||||
* - add spec or description to results
|
||||
* - 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
|
||||
* - 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
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user