Clearer and more representative testing of method proxying
This commit is contained in:
parent
7bcb799ca6
commit
bb1388e879
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue