dwf: made Jasmine & Jasmine.Reporters namespaces; the instance of Jasmine is now just jasmine.

This commit is contained in:
pivotal
2008-12-08 13:01:06 -08:00
parent b8a8dc4562
commit 821fb54934
9 changed files with 157 additions and 158 deletions

View File

@@ -152,17 +152,35 @@ var queuedFunction = function(func, timeout, spec) {
* Jasmine
******************************************************************************/
var Jasmine = {}
Jasmine.init = function () {
var that = {
currentSpec: null,
currentSuite: null,
currentRunner: null,
execute: function () {
that.currentRunner.execute();
}
}
return that;
}
var jasmine = Jasmine.init();
/*
* Matchers methods; add your own with Matchers.method()
* Jasmine.Matchers methods; add your own with Jasmine.Matchers.method() - don't forget to write a test
*
*/
Matchers = function (actual, results) {
Jasmine.Matchers = function (actual, results) {
this.actual = actual;
this.passing_message = 'Passed.'
this.results = results || nestedResults();
}
Matchers.method('report', function (result, failing_message) {
Jasmine.Matchers.method('report', function (result, failing_message) {
this.results.push({
passed: result,
@@ -172,12 +190,12 @@ Matchers.method('report', function (result, failing_message) {
return result;
});
Matchers.method('should_equal', function (expected) {
Jasmine.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) {
Jasmine.Matchers.method('should_not_equal', function (expected) {
return this.report((this.actual !== expected),
'Expected ' + expected + ' to not equal ' + this.actual + ', but it does.');
});
@@ -196,7 +214,7 @@ var it = function (description, func) {
results: nestedResults(),
expects_that: function (actual) {
return new Matchers(actual, that.results);
return new Jasmine.Matchers(actual, that.results);
},
waits: function (timeout) {
@@ -209,8 +227,8 @@ var it = function (description, func) {
},
finishCallback: function () {
if (Jasmine.reporter) {
Jasmine.reporter.reportSpecResults(that.results);
if (jasmine.reporter) {
jasmine.reporter.reportSpecResults(that.results);
}
},
@@ -243,8 +261,8 @@ var it = function (description, func) {
that.runs = addToQueue;
currentSuite.specs.push(that);
currentSpec = that;
jasmine.currentSuite.specs.push(that);
jasmine.currentSpec = that;
if (func) {
func();
@@ -255,19 +273,19 @@ var it = function (description, func) {
}
var runs = function (func) {
currentSpec.runs(func);
jasmine.currentSpec.runs(func);
}
var waits = function (timeout) {
currentSpec.waits(timeout);
jasmine.currentSpec.waits(timeout);
}
var beforeEach = function (beforeEach) {
currentSuite.beforeEach = beforeEach;
jasmine.currentSuite.beforeEach = beforeEach;
}
var afterEach = function (afterEach) {
currentSuite.afterEach = afterEach;
jasmine.currentSuite.afterEach = afterEach;
}
var describe = function (description, spec_definitions) {
@@ -276,16 +294,16 @@ var describe = function (description, spec_definitions) {
that.description = description;
that.specs = that.actions;
currentSuite = that;
Jasmine.suites.push(that);
jasmine.currentSuite = that;
jasmine.currentRunner.suites.push(that);
spec_definitions();
that.results.description = description;
that.finishCallback = function () {
if (Jasmine.reporter) {
Jasmine.reporter.reportSuiteResults(that.results);
if (jasmine.reporter) {
jasmine.reporter.reportSuiteResults(that.results);
}
}
@@ -299,26 +317,24 @@ var Runner = function () {
that.results.description = 'All Jasmine Suites';
that.finishCallback = function () {
if (that.reporter) {
that.reporter.reportRunnerResults(that.results);
if (jasmine.reporter) {
jasmine.reporter.reportRunnerResults(that.results);
}
}
Jasmine = that;
jasmine.currentRunner = that;
return that;
}
var Jasmine = Runner();
var currentSuite;
var currentSpec;
jasmine.currentRunner = Runner();
/* JasmineReporters.reporter
* Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to
* descendants of this object to do something with the results (see json_reporter.js)
*/
var JasmineReporters = {};
Jasmine.Reporters = {};
JasmineReporters.reporter = function (callbacks) {
Jasmine.Reporters.reporter = function (callbacks) {
var that = {
callbacks: callbacks || {},

View File

@@ -3,8 +3,8 @@
* Basic reporter that keeps a JSON string of the most recent Spec, Suite or Runner
* result. Calling application can then do whatever it wants/needs with the string;
*/
JasmineReporters.JSON = function () {
var that = JasmineReporters.reporter();
Jasmine.Reporters.JSON = function () {
var that = Jasmine.Reporters.reporter();
that.specJSON = '';
that.suiteJSON = '';
that.runnerJSON = '';
@@ -27,7 +27,7 @@ JasmineReporters.JSON = function () {
return that;
}
var domWriter = function (elementId) {
Jasmine.Reporters.domWriter = function (elementId) {
var that = {
element: document.getElementById(elementId),
@@ -43,10 +43,10 @@ var domWriter = function (elementId) {
return that;
}
JasmineReporters.JSONtoDOM = function (elementId) {
var that = JasmineReporters.JSON();
Jasmine.Reporters.JSONtoDOM = function (elementId) {
var that = Jasmine.Reporters.JSON();
that.domWriter = domWriter(elementId);
that.domWriter = Jasmine.Reporters.domWriter(elementId);
var writeRunnerResults = function (results) {
that.domWriter.write(Object.toJSON(results));
@@ -56,18 +56,3 @@ JasmineReporters.JSONtoDOM = function (elementId) {
return that;
}
//JasmineReporters.IncrementalJSON = function (elementId) {
// var that = JasmineReporters.reporter(elementId);
//
// that.reportSpecResults = function (results) {
// that.output = Object.toJSON(results);
// if (that.element) {
// that.element.innerHTML += that.output;
// }
// }
//
// return that;
//}