From f94be290472e83dacdbd9db5285a1233ffbb32f2 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 15 Jan 2015 11:39:18 -0300 Subject: [PATCH] Remove unused error.handleCallback function --- lib/errors/errors.coffee | 8 ------ lib/errors/errors.spec.coffee | 49 ----------------------------------- 2 files changed, 57 deletions(-) diff --git a/lib/errors/errors.coffee b/lib/errors/errors.coffee index 4c36a48f..e2b4b95c 100644 --- a/lib/errors/errors.coffee +++ b/lib/errors/errors.coffee @@ -21,11 +21,3 @@ exports.handle = (error, exit = true) -> errorCode = 1 process.exit(errorCode) if exit - -exports.handleCallback = (callback, context, exit) -> - if not _.isFunction(callback) - throw new Error('Callback is not a function') - - return (error, args...) -> - exports.handle(error, exit) if error? - return callback.apply(context, args) diff --git a/lib/errors/errors.spec.coffee b/lib/errors/errors.spec.coffee index 02498ef2..c029e11d 100644 --- a/lib/errors/errors.spec.coffee +++ b/lib/errors/errors.spec.coffee @@ -77,52 +77,3 @@ describe 'Errors:', -> checkProcessExitOption error, false, (processExitStub, logErrorStub) -> expect(logErrorStub).to.have.been.calledOnce expect(logErrorStub).to.have.been.calledWith('No such file or directory: hello') - - describe '#handleCallback()', -> - - it 'should throw an error if callback is not a function', -> - expect -> - errors.handleCallback('hello') - .to.throw('Callback is not a function') - - it 'should return a new function', -> - callback = errors.handleCallback(_.noop) - expect(callback).to.be.an.instanceof(Function) - - describe 'given no error', -> - - it 'should pass arguments back to the callback', -> - spy = sinon.spy() - callback = errors.handleCallback(spy) - callback.call(null, null, 'Hello World', 123) - expect(spy).to.have.been.calledOnce - expect(spy).to.have.been.calledWithExactly('Hello World', 123) - - it 'should be able to pass a context', -> - spy = sinon.spy() - context = - foo: 'bar' - callback = errors.handleCallback(spy, context) - callback.call(null, null, 'Hello World', 123) - expect(spy).to.have.been.calledOn(context) - - describe 'given an error', -> - - beforeEach -> - @handleStub = sinon.stub(errors, 'handle') - @error = new Error('hello') - - afterEach -> - @handleStub.restore() - - it 'should call handle() with the error', -> - callback = errors.handleCallback(_.noop) - callback.call(null, @error) - expect(@handleStub).to.have.been.calledOnce - expect(@handleStub).to.have.been.calledWith(@error) - - it 'should call handle() with the exit boolean parameter', -> - callback = errors.handleCallback(_.noop, null, false) - callback.call(null, @error) - expect(@handleStub).to.have.been.calledOnce - expect(@handleStub).to.have.been.calledWithExactly(@error, false)