diff --git a/lib/data/data-prefix.coffee b/lib/data/data-prefix.coffee index 0ea125f7..f050fd11 100644 --- a/lib/data/data-prefix.coffee +++ b/lib/data/data-prefix.coffee @@ -5,11 +5,12 @@ prefix = null exports.get = -> return prefix -exports.set = (newPrefix) -> +exports.set = (newPrefix, callback) -> if not fsUtils.isValidPath(newPrefix) - throw new Error('Invalid path') + return callback?(new Error('Invalid path')) prefix = newPrefix + return callback?(null, prefix) exports.clear = -> prefix = null diff --git a/lib/data/data-prefix.spec.coffee b/lib/data/data-prefix.spec.coffee index 0abcb66a..591f8fc0 100644 --- a/lib/data/data-prefix.spec.coffee +++ b/lib/data/data-prefix.spec.coffee @@ -22,19 +22,22 @@ describe 'DataPrefix:', -> describe '#set()', -> - it 'should be able to set a prefix', -> + it 'should be able to set a prefix', (done) -> expect(dataPrefix.get()).to.not.exist - dataPrefix.set(PREFIXES.main) - expect(dataPrefix.get()).to.equal(PREFIXES.main) + dataPrefix.set PREFIXES.main, (error) -> + expect(error).to.not.exist + expect(dataPrefix.get()).to.equal(PREFIXES.main) + done() - it 'should throw an error if passing an invalid path', -> - setInvalidPrefix = _.partial(dataPrefix.set, PREFIXES.invalid) - expect(setInvalidPrefix).to.throw(Error) + it 'should throw an error if passing an invalid path', (done) -> + dataPrefix.set PREFIXES.invalid, (error) -> + expect(error).to.be.an.instanceof(Error) + done() describe 'given a prefix', -> - beforeEach -> - dataPrefix.set(PREFIXES.main) + beforeEach (done) -> + dataPrefix.set(PREFIXES.main, done) describe '#get()', -> @@ -43,10 +46,12 @@ describe 'DataPrefix:', -> describe '#set()', -> - it 'should be able to override the prefix', -> + it 'should be able to override the prefix', (done) -> expect(dataPrefix.get()).to.equal(PREFIXES.main) - dataPrefix.set(PREFIXES.new) - expect(dataPrefix.get()).to.equal(PREFIXES.new) + dataPrefix.set PREFIXES.new, (error) -> + expect(error).to.not.exist + expect(dataPrefix.get()).to.equal(PREFIXES.new) + done() describe '#clear()', -> diff --git a/lib/data/data.spec.coffee b/lib/data/data.spec.coffee index 7a2cf27e..b84c53eb 100644 --- a/lib/data/data.spec.coffee +++ b/lib/data/data.spec.coffee @@ -58,9 +58,9 @@ describe 'Data:', -> describe 'given a prefix', -> - beforeEach -> + beforeEach (done) -> mock.fs.init(FILESYSTEM) - data.prefix.set(config.dataPrefix) + data.prefix.set(config.dataPrefix, done) afterEach -> mock.fs.restore() diff --git a/lib/fs-utils/fs-utils.spec.coffee b/lib/fs-utils/fs-utils.spec.coffee index 0a5a6095..0cf26fd6 100644 --- a/lib/fs-utils/fs-utils.spec.coffee +++ b/lib/fs-utils/fs-utils.spec.coffee @@ -39,9 +39,9 @@ describe 'FsUtils:', -> describe '#isDirectory()', -> - beforeEach -> + beforeEach (done) -> mock.fs.init(FILESYSTEM) - data.prefix.set(config.dataPrefix) + data.prefix.set(config.dataPrefix, done) afterEach -> mock.fs.restore()