Move most jasmine global usage into boot.
- thor build scripts broken for now.
This commit is contained in:
555
src/core/Env.js
555
src/core/Env.js
@@ -3,298 +3,305 @@
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
jasmine.Env = function() {
|
||||
this.currentSpec = null;
|
||||
this.currentSuite = null;
|
||||
this.currentRunner_ = new jasmine.Runner(this);
|
||||
(function() {
|
||||
|
||||
this.reporter = new jasmine.MultiReporter();
|
||||
function createSpec(env, suite, description) {
|
||||
return new jasmine.Spec(env, suite, description);
|
||||
}
|
||||
|
||||
this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
|
||||
this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
this.lastUpdate = 0;
|
||||
this.specFilter = function() {
|
||||
return true;
|
||||
jasmine.Env = function() {
|
||||
this.currentSpec = null;
|
||||
this.currentSuite = null;
|
||||
this.currentRunner_ = new jasmine.Runner(this);
|
||||
|
||||
this.reporter = new jasmine.MultiReporter();
|
||||
|
||||
this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
|
||||
this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
this.lastUpdate = 0;
|
||||
this.specFilter = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
this.nextSpecId_ = 0;
|
||||
this.nextSuiteId_ = 0;
|
||||
this.equalityTesters_ = [];
|
||||
|
||||
// wrap matchers
|
||||
this.matchersClass = function() {
|
||||
jasmine.Matchers.apply(this, arguments);
|
||||
};
|
||||
jasmine.util.inherit(this.matchersClass, jasmine.Matchers);
|
||||
|
||||
jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass);
|
||||
};
|
||||
|
||||
this.nextSpecId_ = 0;
|
||||
this.nextSuiteId_ = 0;
|
||||
this.equalityTesters_ = [];
|
||||
|
||||
// wrap matchers
|
||||
this.matchersClass = function() {
|
||||
jasmine.Matchers.apply(this, arguments);
|
||||
};
|
||||
jasmine.util.inherit(this.matchersClass, jasmine.Matchers);
|
||||
jasmine.Env.prototype.setTimeout = jasmine.setTimeout;
|
||||
jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
|
||||
jasmine.Env.prototype.setInterval = jasmine.setInterval;
|
||||
jasmine.Env.prototype.clearInterval = jasmine.clearInterval;
|
||||
|
||||
jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass);
|
||||
};
|
||||
|
||||
|
||||
jasmine.Env.prototype.setTimeout = jasmine.setTimeout;
|
||||
jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
|
||||
jasmine.Env.prototype.setInterval = jasmine.setInterval;
|
||||
jasmine.Env.prototype.clearInterval = jasmine.clearInterval;
|
||||
|
||||
/**
|
||||
* @returns an object containing jasmine version build info, if set.
|
||||
*/
|
||||
jasmine.Env.prototype.version = function () {
|
||||
if (jasmine.version_) {
|
||||
return jasmine.version_;
|
||||
} else {
|
||||
throw new Error('Version not set');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns string containing jasmine version build info, if set.
|
||||
*/
|
||||
jasmine.Env.prototype.versionString = function() {
|
||||
if (!jasmine.version_) {
|
||||
return "version unknown";
|
||||
}
|
||||
|
||||
var version = this.version();
|
||||
var versionString = version.major + "." + version.minor + "." + version.build;
|
||||
if (version.release_candidate) {
|
||||
versionString += ".rc" + version.release_candidate;
|
||||
}
|
||||
versionString += " revision " + version.revision;
|
||||
return versionString;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns a sequential integer starting at 0
|
||||
*/
|
||||
jasmine.Env.prototype.nextSpecId = function () {
|
||||
return this.nextSpecId_++;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns a sequential integer starting at 0
|
||||
*/
|
||||
jasmine.Env.prototype.nextSuiteId = function () {
|
||||
return this.nextSuiteId_++;
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a reporter to receive status updates from Jasmine.
|
||||
* @param {jasmine.Reporter} reporter An object which will receive status updates.
|
||||
*/
|
||||
jasmine.Env.prototype.addReporter = function(reporter) {
|
||||
this.reporter.addReporter(reporter);
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.execute = function() {
|
||||
this.currentRunner_.execute();
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.describe = function(description, specDefinitions) {
|
||||
var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite);
|
||||
|
||||
var parentSuite = this.currentSuite;
|
||||
if (parentSuite) {
|
||||
parentSuite.add(suite);
|
||||
} else {
|
||||
this.currentRunner_.add(suite);
|
||||
}
|
||||
|
||||
this.currentSuite = suite;
|
||||
|
||||
var declarationError = null;
|
||||
try {
|
||||
specDefinitions.call(suite);
|
||||
} catch(e) {
|
||||
declarationError = e;
|
||||
}
|
||||
|
||||
if (declarationError) {
|
||||
this.it("encountered a declaration exception", function() {
|
||||
throw declarationError;
|
||||
});
|
||||
}
|
||||
|
||||
this.currentSuite = parentSuite;
|
||||
|
||||
return suite;
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.beforeEach = function(beforeEachFunction) {
|
||||
if (this.currentSuite) {
|
||||
this.currentSuite.beforeEach(beforeEachFunction);
|
||||
} else {
|
||||
this.currentRunner_.beforeEach(beforeEachFunction);
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.currentRunner = function () {
|
||||
return this.currentRunner_;
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.afterEach = function(afterEachFunction) {
|
||||
if (this.currentSuite) {
|
||||
this.currentSuite.afterEach(afterEachFunction);
|
||||
} else {
|
||||
this.currentRunner_.afterEach(afterEachFunction);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) {
|
||||
return {
|
||||
execute: function() {
|
||||
/**
|
||||
* @returns an object containing jasmine version build info, if set.
|
||||
*/
|
||||
jasmine.Env.prototype.version = function () {
|
||||
if (jasmine.version_) {
|
||||
return jasmine.version_;
|
||||
} else {
|
||||
throw new Error('Version not set');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.it = function(description, func) {
|
||||
var spec = new jasmine.Spec(this, this.currentSuite, description);
|
||||
this.currentSuite.add(spec);
|
||||
this.currentSpec = spec;
|
||||
|
||||
if (func) {
|
||||
spec.runs(func);
|
||||
}
|
||||
|
||||
return spec;
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.xit = function(desc, func) {
|
||||
return {
|
||||
id: this.nextSpecId(),
|
||||
runs: function() {
|
||||
/**
|
||||
* @returns string containing jasmine version build info, if set.
|
||||
*/
|
||||
jasmine.Env.prototype.versionString = function() {
|
||||
if (!jasmine.version_) {
|
||||
return "version unknown";
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.compareRegExps_ = function(a, b, mismatchKeys, mismatchValues) {
|
||||
if (a.source != b.source)
|
||||
mismatchValues.push("expected pattern /" + b.source + "/ is not equal to the pattern /" + a.source + "/");
|
||||
|
||||
if (a.ignoreCase != b.ignoreCase)
|
||||
mismatchValues.push("expected modifier i was" + (b.ignoreCase ? " " : " not ") + "set and does not equal the origin modifier");
|
||||
|
||||
if (a.global != b.global)
|
||||
mismatchValues.push("expected modifier g was" + (b.global ? " " : " not ") + "set and does not equal the origin modifier");
|
||||
|
||||
if (a.multiline != b.multiline)
|
||||
mismatchValues.push("expected modifier m was" + (b.multiline ? " " : " not ") + "set and does not equal the origin modifier");
|
||||
|
||||
if (a.sticky != b.sticky)
|
||||
mismatchValues.push("expected modifier y was" + (b.sticky ? " " : " not ") + "set and does not equal the origin modifier");
|
||||
|
||||
return (mismatchValues.length === 0);
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) {
|
||||
if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) {
|
||||
return true;
|
||||
}
|
||||
|
||||
a.__Jasmine_been_here_before__ = b;
|
||||
b.__Jasmine_been_here_before__ = a;
|
||||
|
||||
var hasKey = function(obj, keyName) {
|
||||
return obj !== null && obj[keyName] !== jasmine.undefined;
|
||||
var version = this.version();
|
||||
var versionString = version.major + "." + version.minor + "." + version.build;
|
||||
if (version.release_candidate) {
|
||||
versionString += ".rc" + version.release_candidate;
|
||||
}
|
||||
versionString += " revision " + version.revision;
|
||||
return versionString;
|
||||
};
|
||||
|
||||
for (var property in b) {
|
||||
if (!hasKey(a, property) && hasKey(b, property)) {
|
||||
mismatchKeys.push("expected has key '" + property + "', but missing from actual.");
|
||||
/**
|
||||
* @returns a sequential integer starting at 0
|
||||
*/
|
||||
jasmine.Env.prototype.nextSpecId = function () {
|
||||
return this.nextSpecId_++;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns a sequential integer starting at 0
|
||||
*/
|
||||
jasmine.Env.prototype.nextSuiteId = function () {
|
||||
return this.nextSuiteId_++;
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a reporter to receive status updates from Jasmine.
|
||||
* @param {jasmine.Reporter} reporter An object which will receive status updates.
|
||||
*/
|
||||
jasmine.Env.prototype.addReporter = function(reporter) {
|
||||
this.reporter.addReporter(reporter);
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.execute = function() {
|
||||
this.currentRunner_.execute();
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.describe = function(description, specDefinitions) {
|
||||
var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite);
|
||||
|
||||
var parentSuite = this.currentSuite;
|
||||
if (parentSuite) {
|
||||
parentSuite.add(suite);
|
||||
} else {
|
||||
this.currentRunner_.add(suite);
|
||||
}
|
||||
}
|
||||
for (property in a) {
|
||||
if (!hasKey(b, property) && hasKey(a, property)) {
|
||||
mismatchKeys.push("expected missing key '" + property + "', but present in actual.");
|
||||
|
||||
this.currentSuite = suite;
|
||||
|
||||
var declarationError = null;
|
||||
try {
|
||||
specDefinitions.call(suite);
|
||||
} catch(e) {
|
||||
declarationError = e;
|
||||
}
|
||||
}
|
||||
for (property in b) {
|
||||
if (property == '__Jasmine_been_here_before__') continue;
|
||||
if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) {
|
||||
mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual.");
|
||||
|
||||
if (declarationError) {
|
||||
this.it("encountered a declaration exception", function() {
|
||||
throw declarationError;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) {
|
||||
mismatchValues.push("arrays were not the same length");
|
||||
}
|
||||
this.currentSuite = parentSuite;
|
||||
|
||||
delete a.__Jasmine_been_here_before__;
|
||||
delete b.__Jasmine_been_here_before__;
|
||||
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
|
||||
};
|
||||
return suite;
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
|
||||
mismatchKeys = mismatchKeys || [];
|
||||
mismatchValues = mismatchValues || [];
|
||||
|
||||
for (var i = 0; i < this.equalityTesters_.length; i++) {
|
||||
var equalityTester = this.equalityTesters_[i];
|
||||
var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
|
||||
if (result !== jasmine.undefined) return result;
|
||||
}
|
||||
|
||||
if (a === b) return true;
|
||||
|
||||
if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) {
|
||||
return (a == jasmine.undefined && b == jasmine.undefined);
|
||||
}
|
||||
|
||||
if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) {
|
||||
return a === b;
|
||||
}
|
||||
|
||||
if (a instanceof Date && b instanceof Date) {
|
||||
return a.getTime() == b.getTime();
|
||||
}
|
||||
|
||||
if (a.jasmineMatches) {
|
||||
return a.jasmineMatches(b);
|
||||
}
|
||||
|
||||
if (b.jasmineMatches) {
|
||||
return b.jasmineMatches(a);
|
||||
}
|
||||
|
||||
if (a instanceof jasmine.Matchers.ObjectContaining) {
|
||||
return a.matches(b);
|
||||
}
|
||||
|
||||
if (b instanceof jasmine.Matchers.ObjectContaining) {
|
||||
return b.matches(a);
|
||||
}
|
||||
|
||||
if (jasmine.isString_(a) && jasmine.isString_(b)) {
|
||||
return (a == b);
|
||||
}
|
||||
|
||||
if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) {
|
||||
return (a == b);
|
||||
}
|
||||
|
||||
if (a instanceof RegExp && b instanceof RegExp) {
|
||||
return this.compareRegExps_(a, b, mismatchKeys, mismatchValues);
|
||||
}
|
||||
|
||||
if (typeof a === "object" && typeof b === "object") {
|
||||
return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
|
||||
}
|
||||
|
||||
//Straight check
|
||||
return (a === b);
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.contains_ = function(haystack, needle) {
|
||||
if (jasmine.isArray_(haystack)) {
|
||||
for (var i = 0; i < haystack.length; i++) {
|
||||
if (this.equals_(haystack[i], needle)) return true;
|
||||
jasmine.Env.prototype.beforeEach = function(beforeEachFunction) {
|
||||
if (this.currentSuite) {
|
||||
this.currentSuite.beforeEach(beforeEachFunction);
|
||||
} else {
|
||||
this.currentRunner_.beforeEach(beforeEachFunction);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return haystack.indexOf(needle) >= 0;
|
||||
};
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.addEqualityTester = function(equalityTester) {
|
||||
this.equalityTesters_.push(equalityTester);
|
||||
};
|
||||
jasmine.Env.prototype.currentRunner = function () {
|
||||
return this.currentRunner_;
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.afterEach = function(afterEachFunction) {
|
||||
if (this.currentSuite) {
|
||||
this.currentSuite.afterEach(afterEachFunction);
|
||||
} else {
|
||||
this.currentRunner_.afterEach(afterEachFunction);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) {
|
||||
return {
|
||||
execute: function() {
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.it = function(description, func) {
|
||||
var spec = createSpec(this, this.currentSuite, description);
|
||||
this.currentSuite.add(spec);
|
||||
this.currentSpec = spec;
|
||||
|
||||
if (func) {
|
||||
spec.runs(func);
|
||||
}
|
||||
|
||||
return spec;
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.xit = function(desc, func) {
|
||||
return {
|
||||
id: this.nextSpecId(),
|
||||
runs: function() {
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.compareRegExps_ = function(a, b, mismatchKeys, mismatchValues) {
|
||||
if (a.source != b.source)
|
||||
mismatchValues.push("expected pattern /" + b.source + "/ is not equal to the pattern /" + a.source + "/");
|
||||
|
||||
if (a.ignoreCase != b.ignoreCase)
|
||||
mismatchValues.push("expected modifier i was" + (b.ignoreCase ? " " : " not ") + "set and does not equal the origin modifier");
|
||||
|
||||
if (a.global != b.global)
|
||||
mismatchValues.push("expected modifier g was" + (b.global ? " " : " not ") + "set and does not equal the origin modifier");
|
||||
|
||||
if (a.multiline != b.multiline)
|
||||
mismatchValues.push("expected modifier m was" + (b.multiline ? " " : " not ") + "set and does not equal the origin modifier");
|
||||
|
||||
if (a.sticky != b.sticky)
|
||||
mismatchValues.push("expected modifier y was" + (b.sticky ? " " : " not ") + "set and does not equal the origin modifier");
|
||||
|
||||
return (mismatchValues.length === 0);
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) {
|
||||
if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) {
|
||||
return true;
|
||||
}
|
||||
|
||||
a.__Jasmine_been_here_before__ = b;
|
||||
b.__Jasmine_been_here_before__ = a;
|
||||
|
||||
var hasKey = function(obj, keyName) {
|
||||
return obj !== null && obj[keyName] !== jasmine.undefined;
|
||||
};
|
||||
|
||||
for (var property in b) {
|
||||
if (!hasKey(a, property) && hasKey(b, property)) {
|
||||
mismatchKeys.push("expected has key '" + property + "', but missing from actual.");
|
||||
}
|
||||
}
|
||||
for (property in a) {
|
||||
if (!hasKey(b, property) && hasKey(a, property)) {
|
||||
mismatchKeys.push("expected missing key '" + property + "', but present in actual.");
|
||||
}
|
||||
}
|
||||
for (property in b) {
|
||||
if (property == '__Jasmine_been_here_before__') continue;
|
||||
if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) {
|
||||
mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual.");
|
||||
}
|
||||
}
|
||||
|
||||
if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) {
|
||||
mismatchValues.push("arrays were not the same length");
|
||||
}
|
||||
|
||||
delete a.__Jasmine_been_here_before__;
|
||||
delete b.__Jasmine_been_here_before__;
|
||||
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
|
||||
mismatchKeys = mismatchKeys || [];
|
||||
mismatchValues = mismatchValues || [];
|
||||
|
||||
for (var i = 0; i < this.equalityTesters_.length; i++) {
|
||||
var equalityTester = this.equalityTesters_[i];
|
||||
var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
|
||||
if (result !== jasmine.undefined) return result;
|
||||
}
|
||||
|
||||
if (a === b) return true;
|
||||
|
||||
if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) {
|
||||
return (a == jasmine.undefined && b == jasmine.undefined);
|
||||
}
|
||||
|
||||
if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) {
|
||||
return a === b;
|
||||
}
|
||||
|
||||
if (a instanceof Date && b instanceof Date) {
|
||||
return a.getTime() == b.getTime();
|
||||
}
|
||||
|
||||
if (a.jasmineMatches) {
|
||||
return a.jasmineMatches(b);
|
||||
}
|
||||
|
||||
if (b.jasmineMatches) {
|
||||
return b.jasmineMatches(a);
|
||||
}
|
||||
|
||||
if (a instanceof jasmine.Matchers.ObjectContaining) {
|
||||
return a.matches(b);
|
||||
}
|
||||
|
||||
if (b instanceof jasmine.Matchers.ObjectContaining) {
|
||||
return b.matches(a);
|
||||
}
|
||||
|
||||
if (jasmine.isString_(a) && jasmine.isString_(b)) {
|
||||
return (a == b);
|
||||
}
|
||||
|
||||
if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) {
|
||||
return (a == b);
|
||||
}
|
||||
|
||||
if (a instanceof RegExp && b instanceof RegExp) {
|
||||
return this.compareRegExps_(a, b, mismatchKeys, mismatchValues);
|
||||
}
|
||||
|
||||
if (typeof a === "object" && typeof b === "object") {
|
||||
return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
|
||||
}
|
||||
|
||||
//Straight check
|
||||
return (a === b);
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.contains_ = function(haystack, needle) {
|
||||
if (jasmine.isArray_(haystack)) {
|
||||
for (var i = 0; i < haystack.length; i++) {
|
||||
if (this.equals_(haystack[i], needle)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return haystack.indexOf(needle) >= 0;
|
||||
};
|
||||
|
||||
jasmine.Env.prototype.addEqualityTester = function(equalityTester) {
|
||||
this.equalityTesters_.push(equalityTester);
|
||||
};
|
||||
}());
|
||||
|
||||
158
src/core/base.js
158
src/core/base.js
@@ -1,4 +1,3 @@
|
||||
var isCommonJS = typeof window == "undefined" && typeof exports == "object";
|
||||
|
||||
/**
|
||||
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
|
||||
@@ -6,7 +5,7 @@ var isCommonJS = typeof window == "undefined" && typeof exports == "object";
|
||||
* @namespace
|
||||
*/
|
||||
var jasmine = {};
|
||||
if (isCommonJS) exports.jasmine = jasmine;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@@ -128,6 +127,7 @@ jasmine.ExpectationResult.prototype.passed = function () {
|
||||
*/
|
||||
jasmine.getEnv = function() {
|
||||
var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
|
||||
//jasmine. singletons in here (setTimeout blah blah).
|
||||
return env;
|
||||
};
|
||||
|
||||
@@ -462,160 +462,6 @@ jasmine.log = function() {
|
||||
spec.log.apply(spec, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* Function that installs a spy on an existing object's method name. Used within a Spec to create a spy.
|
||||
*
|
||||
* @example
|
||||
* // spy example
|
||||
* var foo = {
|
||||
* not: function(bool) { return !bool; }
|
||||
* }
|
||||
* spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
|
||||
*
|
||||
* @see jasmine.createSpy
|
||||
* @param obj
|
||||
* @param methodName
|
||||
* @return {jasmine.Spy} a Jasmine spy that can be chained with all spy methods
|
||||
*/
|
||||
var spyOn = function(obj, methodName) {
|
||||
return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
|
||||
};
|
||||
if (isCommonJS) exports.spyOn = spyOn;
|
||||
|
||||
/**
|
||||
* Creates a Jasmine spec that will be added to the current suite.
|
||||
*
|
||||
* // TODO: pending tests
|
||||
*
|
||||
* @example
|
||||
* it('should be true', function() {
|
||||
* expect(true).toEqual(true);
|
||||
* });
|
||||
*
|
||||
* @param {String} desc description of this specification
|
||||
* @param {Function} func defines the preconditions and expectations of the spec
|
||||
*/
|
||||
var it = function(desc, func) {
|
||||
return jasmine.getEnv().it(desc, func);
|
||||
};
|
||||
if (isCommonJS) exports.it = it;
|
||||
|
||||
/**
|
||||
* Creates a <em>disabled</em> Jasmine spec.
|
||||
*
|
||||
* A convenience method that allows existing specs to be disabled temporarily during development.
|
||||
*
|
||||
* @param {String} desc description of this specification
|
||||
* @param {Function} func defines the preconditions and expectations of the spec
|
||||
*/
|
||||
var xit = function(desc, func) {
|
||||
return jasmine.getEnv().xit(desc, func);
|
||||
};
|
||||
if (isCommonJS) exports.xit = xit;
|
||||
|
||||
/**
|
||||
* Starts a chain for a Jasmine expectation.
|
||||
*
|
||||
* It is passed an Object that is the actual value and should chain to one of the many
|
||||
* jasmine.Matchers functions.
|
||||
*
|
||||
* @param {Object} actual Actual value to test against and expected value
|
||||
* @return {jasmine.Matchers}
|
||||
*/
|
||||
var expect = function(actual) {
|
||||
return jasmine.getEnv().currentSpec.expect(actual);
|
||||
};
|
||||
if (isCommonJS) exports.expect = expect;
|
||||
|
||||
/**
|
||||
* Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
|
||||
*
|
||||
* @param {Function} func Function that defines part of a jasmine spec.
|
||||
*/
|
||||
var runs = function(func) {
|
||||
jasmine.getEnv().currentSpec.runs(func);
|
||||
};
|
||||
if (isCommonJS) exports.runs = runs;
|
||||
|
||||
/**
|
||||
* Waits a fixed time period before moving to the next block.
|
||||
*
|
||||
* @deprecated Use waitsFor() instead
|
||||
* @param {Number} timeout milliseconds to wait
|
||||
*/
|
||||
var waits = function(timeout) {
|
||||
jasmine.getEnv().currentSpec.waits(timeout);
|
||||
};
|
||||
if (isCommonJS) exports.waits = waits;
|
||||
|
||||
/**
|
||||
* Waits for the latchFunction to return true before proceeding to the next block.
|
||||
*
|
||||
* @param {Function} latchFunction
|
||||
* @param {String} optional_timeoutMessage
|
||||
* @param {Number} optional_timeout
|
||||
*/
|
||||
var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
|
||||
jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
|
||||
};
|
||||
if (isCommonJS) exports.waitsFor = waitsFor;
|
||||
|
||||
/**
|
||||
* A function that is called before each spec in a suite.
|
||||
*
|
||||
* Used for spec setup, including validating assumptions.
|
||||
*
|
||||
* @param {Function} beforeEachFunction
|
||||
*/
|
||||
var beforeEach = function(beforeEachFunction) {
|
||||
jasmine.getEnv().beforeEach(beforeEachFunction);
|
||||
};
|
||||
if (isCommonJS) exports.beforeEach = beforeEach;
|
||||
|
||||
/**
|
||||
* A function that is called after each spec in a suite.
|
||||
*
|
||||
* Used for restoring any state that is hijacked during spec execution.
|
||||
*
|
||||
* @param {Function} afterEachFunction
|
||||
*/
|
||||
var afterEach = function(afterEachFunction) {
|
||||
jasmine.getEnv().afterEach(afterEachFunction);
|
||||
};
|
||||
if (isCommonJS) exports.afterEach = afterEach;
|
||||
|
||||
/**
|
||||
* Defines a suite of specifications.
|
||||
*
|
||||
* Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared
|
||||
* are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization
|
||||
* of setup in some tests.
|
||||
*
|
||||
* @example
|
||||
* // TODO: a simple suite
|
||||
*
|
||||
* // TODO: a simple suite with a nested describe block
|
||||
*
|
||||
* @param {String} description A string, usually the class under test.
|
||||
* @param {Function} specDefinitions function that defines several specs.
|
||||
*/
|
||||
var describe = function(description, specDefinitions) {
|
||||
return jasmine.getEnv().describe(description, specDefinitions);
|
||||
};
|
||||
if (isCommonJS) exports.describe = describe;
|
||||
|
||||
/**
|
||||
* Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
|
||||
*
|
||||
* @param {String} description A string, usually the class under test.
|
||||
* @param {Function} specDefinitions function that defines several specs.
|
||||
*/
|
||||
var xdescribe = function(description, specDefinitions) {
|
||||
return jasmine.getEnv().xdescribe(description, specDefinitions);
|
||||
};
|
||||
if (isCommonJS) exports.xdescribe = xdescribe;
|
||||
|
||||
|
||||
// Provide the XMLHttpRequest class for IE 5.x-6.x:
|
||||
jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
|
||||
function tryIt(f) {
|
||||
|
||||
Reference in New Issue
Block a user