From bb1388e879ed00af0f884d341fd4acab20c406d5 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Wed, 6 Nov 2013 15:23:32 -0800 Subject: [PATCH] Clearer and more representative testing of method proxying --- test/dist/specs/utils.spec.js | 41 +++++++++++++++++++------------- test/src/specs/utils.spec.coffee | 21 +++++++++------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/test/dist/specs/utils.spec.js b/test/dist/specs/utils.spec.js index 5f2e091..79eef1e 100644 --- a/test/dist/specs/utils.spec.js +++ b/test/dist/specs/utils.spec.js @@ -14,24 +14,31 @@ }); }); return describe("#proxyFunctionsToObject", function() { - var TestClass, proxyObject; - proxyObject = { - asString: function() { - return "[object ProxyObject]"; - }, - toString: function() { - return "[object ProxyObject]"; - }, - returnString: function(string) { + var ProxyClass, TestClass, methods; + methods = ['asString', 'toString', 'returnString']; + ProxyClass = (function() { + function ProxyClass() {} + + ProxyClass.prototype.asString = function() { + return "[object ProxyClass]"; + }; + + ProxyClass.prototype.toString = function() { + return "[object ProxyClass]"; + }; + + ProxyClass.prototype.returnString = function(string) { return string; - } - }; + }; + + return ProxyClass; + + })(); TestClass = (function() { function TestClass() { - var methods; - this.myself = this; - methods = ['asString', 'toString', 'returnString']; - proxyFunctionsToObject(methods, proxyObject, this.myself, true); + this.self = this; + this.testInstance = new ProxyClass; + proxyFunctionsToObject(methods, this.testInstance, this.self, true); } return TestClass; @@ -41,13 +48,13 @@ var testclass; testclass = new TestClass; assert(typeof testclass.asString === 'function'); - return testclass.asString().should.be.equal("[object ProxyObject]"); + return testclass.asString().should.be.equal("[object ProxyClass]"); }); it('can alias existing methods if forced to', function() { var testclass; testclass = new TestClass; assert(typeof testclass.toString === 'function'); - return testclass.toString().should.be.equal("[object ProxyObject]"); + return testclass.toString().should.be.equal("[object ProxyClass]"); }); return it('can alias methods with arguments', function() { var testclass; diff --git a/test/src/specs/utils.spec.coffee b/test/src/specs/utils.spec.coffee index 6e4bdb4..c2e3dde 100644 --- a/test/src/specs/utils.spec.coffee +++ b/test/src/specs/utils.spec.coffee @@ -11,27 +11,30 @@ describe "Utils", -> 1.second().should.be.equal 1000 describe "#proxyFunctionsToObject", -> - proxyObject = { - asString: -> "[object ProxyObject]" - toString: -> "[object ProxyObject]" + methods = ['asString', 'toString', 'returnString'] + + class ProxyClass + constructor: -> # noop + + asString: -> "[object ProxyClass]" + toString: -> "[object ProxyClass]" returnString: (string) -> string - } class TestClass constructor: -> - @myself = this - methods = ['asString', 'toString', 'returnString'] - proxyFunctionsToObject(methods, proxyObject, @myself, true) + @self = this + @testInstance = new ProxyClass + proxyFunctionsToObject methods, @testInstance, @self, true it 'can alias methods', -> testclass = new TestClass assert typeof testclass.asString is 'function' - testclass.asString().should.be.equal "[object ProxyObject]" + testclass.asString().should.be.equal "[object ProxyClass]" it 'can alias existing methods if forced to', -> testclass = new TestClass assert typeof testclass.toString is 'function' - testclass.toString().should.be.equal "[object ProxyObject]" + testclass.toString().should.be.equal "[object ProxyClass]" it 'can alias methods with arguments', -> testclass = new TestClass