159
src/core/base.js
159
src/core/base.js
@@ -1,98 +1,101 @@
|
|||||||
getJasmineRequireObj().base = function(j$) {
|
getJasmineRequireObj().base = (function (jasmineGlobal) {
|
||||||
j$.unimplementedMethod_ = function() {
|
if (typeof module !== "undefined" && module.exports) {
|
||||||
throw new Error("unimplemented method");
|
jasmineGlobal = global;
|
||||||
};
|
}
|
||||||
|
|
||||||
j$.MAX_PRETTY_PRINT_DEPTH = 40;
|
return function(j$) {
|
||||||
j$.DEFAULT_TIMEOUT_INTERVAL = 5000;
|
j$.unimplementedMethod_ = function() {
|
||||||
|
throw new Error("unimplemented method");
|
||||||
|
};
|
||||||
|
|
||||||
j$.getGlobal = (function() {
|
j$.MAX_PRETTY_PRINT_DEPTH = 40;
|
||||||
var jasmineGlobal = eval.call(null, "this");
|
j$.DEFAULT_TIMEOUT_INTERVAL = 5000;
|
||||||
return function() {
|
|
||||||
|
j$.getGlobal = function() {
|
||||||
return jasmineGlobal;
|
return jasmineGlobal;
|
||||||
};
|
};
|
||||||
})();
|
|
||||||
|
|
||||||
j$.getEnv = function(options) {
|
j$.getEnv = function(options) {
|
||||||
var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options);
|
var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options);
|
||||||
//jasmine. singletons in here (setTimeout blah blah).
|
//jasmine. singletons in here (setTimeout blah blah).
|
||||||
return env;
|
return env;
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.isArray_ = function(value) {
|
j$.isArray_ = function(value) {
|
||||||
return j$.isA_("Array", value);
|
return j$.isA_("Array", value);
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.isString_ = function(value) {
|
j$.isString_ = function(value) {
|
||||||
return j$.isA_("String", value);
|
return j$.isA_("String", value);
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.isNumber_ = function(value) {
|
j$.isNumber_ = function(value) {
|
||||||
return j$.isA_("Number", value);
|
return j$.isA_("Number", value);
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.isA_ = function(typeName, value) {
|
j$.isA_ = function(typeName, value) {
|
||||||
return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
|
return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.isDomNode = function(obj) {
|
j$.isDomNode = function(obj) {
|
||||||
return obj.nodeType > 0;
|
return obj.nodeType > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.any = function(clazz) {
|
j$.any = function(clazz) {
|
||||||
return new j$.Any(clazz);
|
return new j$.Any(clazz);
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.objectContaining = function(sample) {
|
j$.objectContaining = function(sample) {
|
||||||
return new j$.ObjectContaining(sample);
|
return new j$.ObjectContaining(sample);
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.createSpy = function(name, originalFn) {
|
j$.createSpy = function(name, originalFn) {
|
||||||
|
|
||||||
var spyStrategy = new j$.SpyStrategy({
|
var spyStrategy = new j$.SpyStrategy({
|
||||||
name: name,
|
name: name,
|
||||||
fn: originalFn,
|
fn: originalFn,
|
||||||
getSpy: function() { return spy; }
|
getSpy: function() { return spy; }
|
||||||
}),
|
}),
|
||||||
callTracker = new j$.CallTracker(),
|
callTracker = new j$.CallTracker(),
|
||||||
spy = function() {
|
spy = function() {
|
||||||
callTracker.track({
|
callTracker.track({
|
||||||
object: this,
|
object: this,
|
||||||
args: Array.prototype.slice.apply(arguments)
|
args: Array.prototype.slice.apply(arguments)
|
||||||
});
|
});
|
||||||
return spyStrategy.exec.apply(this, arguments);
|
return spyStrategy.exec.apply(this, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var prop in originalFn) {
|
for (var prop in originalFn) {
|
||||||
if (prop === 'and' || prop === 'calls') {
|
if (prop === 'and' || prop === 'calls') {
|
||||||
throw new Error("Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon");
|
throw new Error("Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon");
|
||||||
|
}
|
||||||
|
|
||||||
|
spy[prop] = originalFn[prop];
|
||||||
}
|
}
|
||||||
|
|
||||||
spy[prop] = originalFn[prop];
|
spy.and = spyStrategy;
|
||||||
}
|
spy.calls = callTracker;
|
||||||
|
|
||||||
spy.and = spyStrategy;
|
return spy;
|
||||||
spy.calls = callTracker;
|
};
|
||||||
|
|
||||||
return spy;
|
j$.isSpy = function(putativeSpy) {
|
||||||
|
if (!putativeSpy) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return putativeSpy.and instanceof j$.SpyStrategy &&
|
||||||
|
putativeSpy.calls instanceof j$.CallTracker;
|
||||||
|
};
|
||||||
|
|
||||||
|
j$.createSpyObj = function(baseName, methodNames) {
|
||||||
|
if (!j$.isArray_(methodNames) || methodNames.length === 0) {
|
||||||
|
throw "createSpyObj requires a non-empty array of method names to create spies for";
|
||||||
|
}
|
||||||
|
var obj = {};
|
||||||
|
for (var i = 0; i < methodNames.length; i++) {
|
||||||
|
obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
})(this);
|
||||||
j$.isSpy = function(putativeSpy) {
|
|
||||||
if (!putativeSpy) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return putativeSpy.and instanceof j$.SpyStrategy &&
|
|
||||||
putativeSpy.calls instanceof j$.CallTracker;
|
|
||||||
};
|
|
||||||
|
|
||||||
j$.createSpyObj = function(baseName, methodNames) {
|
|
||||||
if (!j$.isArray_(methodNames) || methodNames.length === 0) {
|
|
||||||
throw "createSpyObj requires a non-empty array of method names to create spies for";
|
|
||||||
}
|
|
||||||
var obj = {};
|
|
||||||
for (var i = 0; i < methodNames.length; i++) {
|
|
||||||
obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]);
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user