diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index a3ee39b4..21f7215f 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -209,6 +209,11 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { }; j$.createSpyObj = function(baseName, methodNames) { + if (j$.isArray_(baseName) && j$.util.isUndefined(methodNames)) { + methodNames = baseName; + baseName = 'unknown'; + } + if (!j$.isArray_(methodNames) || methodNames.length === 0) { throw 'createSpyObj requires a non-empty array of method names to create spies for'; } diff --git a/spec/core/SpySpec.js b/spec/core/SpySpec.js index d69059b4..1262e328 100644 --- a/spec/core/SpySpec.js +++ b/spec/core/SpySpec.js @@ -7,7 +7,7 @@ describe('Spies', function () { TestClass.prototype.someFunction = function() {}; TestClass.prototype.someFunction.bob = "test"; }); - + it("preserves the properties of the spied function", function() { var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction); @@ -68,6 +68,14 @@ describe('Spies', function () { expect(spyObj.method2.and.identity()).toEqual('BaseName.method2'); }); + it("should allow you to omit the baseName", function() { + var spyObj = j$.createSpyObj(['method1', 'method2']); + + expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)}); + expect(spyObj.method1.and.identity()).toEqual('unknown.method1'); + expect(spyObj.method2.and.identity()).toEqual('unknown.method2'); + }); + it("should throw if you do not pass an array argument", function() { expect(function() { j$.createSpyObj('BaseName'); diff --git a/src/core/base.js b/src/core/base.js index f8291d3d..418a690f 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -105,6 +105,11 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { }; j$.createSpyObj = function(baseName, methodNames) { + if (j$.isArray_(baseName) && j$.util.isUndefined(methodNames)) { + methodNames = baseName; + baseName = 'unknown'; + } + if (!j$.isArray_(methodNames) || methodNames.length === 0) { throw 'createSpyObj requires a non-empty array of method names to create spies for'; }