Add addProxy() method to Adaptor class

This commit is contained in:
Andrew Stewart 2013-10-23 12:18:18 -07:00
parent 1209686388
commit 9452739244
2 changed files with 15 additions and 0 deletions

View File

@ -11,3 +11,6 @@
module.exports = class Adaptor
constructor: (opts) ->
@name = opts.name
addProxy: (object, method) ->
this[method] = (args...) -> object[method](args...)

View File

@ -11,3 +11,15 @@ describe "Adaptor", ->
it "should be able to connect"
it "should be able to disconnect"
it 'can alias methods with addProxy()', ->
proxyObject = { toString: -> "[object ProxyObject]" }
adaptor.addProxy(proxyObject, 'toString')
assert typeof adaptor.toString is 'function'
adaptor.toString().should.be.equal "[object ProxyObject]"
it 'can alias methods with arguments with addProxy()', ->
proxyObject = { returnString: (string) -> string }
adaptor.addProxy(proxyObject, 'returnString')
assert typeof adaptor.returnString is 'function'
adaptor.returnString("testString").should.be.equal "testString"