diff --git a/src/config-utils.coffee b/src/config-utils.coffee index 8cc9f40ed..df35b1b77 100644 --- a/src/config-utils.coffee +++ b/src/config-utils.coffee @@ -5,8 +5,8 @@ path = require 'path' configUtils = {} -configUtils.save = (argsOrigin, path) -> - path ?= path.normalize path.join __dirname, './dredd.yml' +configUtils.save = (argsOrigin, dreddYmlFilePath) -> + dreddYmlFilePath ?= path.normalize path.join(__dirname, '../dredd.yml') args = clone argsOrigin @@ -20,13 +20,13 @@ configUtils.save = (argsOrigin, path) -> delete args['_'] yamlArgs = yaml.dump args - fs.writeFileSync path, yamlArgs + fs.writeFileSync dreddYmlFilePath, yamlArgs -configUtils.load = (path) -> - path ?= path.normalize path.join __dirname, './dredd.yml' +configUtils.load = (dreddYmlFilePath) -> + dreddYmlFilePath ?= path.normalize path.join(__dirname, '../dredd.yml') - yamlData = fs.readFileSync path + yamlData = fs.readFileSync dreddYmlFilePath data = yaml.safeLoad yamlData data['_'] = [data['blueprint'], data['endpoint']] diff --git a/src/dredd-command.coffee b/src/dredd-command.coffee index 4ef1ca414..730b361f0 100644 --- a/src/dredd-command.coffee +++ b/src/dredd-command.coffee @@ -130,7 +130,7 @@ class DreddCommand return @_processExit(0) loadDreddFile: () -> - if fs.existsSync path.normalize(path.join __dirname, './dredd.yml') + if fs.existsSync path.normalize(path.join __dirname, '../dredd.yml') console.log 'Configuration dredd.yml found, ignoring other arguments.' @argv = configUtils.load() diff --git a/src/sandbox-hooks-code.coffee b/src/sandbox-hooks-code.coffee index 569785541..0878b4cd0 100644 --- a/src/sandbox-hooks-code.coffee +++ b/src/sandbox-hooks-code.coffee @@ -27,7 +27,7 @@ sandboxHooksCode = (hooksCode, callback) -> """ sandbox = new Pitboss(wrappedCode) - sandbox.run {libraries: {"_Hooks": path.normalize(path.join __dirname, './hooks'), "console", "console"}}, (err, result) -> + sandbox.run {libraries: {"_Hooks": path.normalize(path.join __dirname, '../lib/hooks'), "console", "console"}}, (err, result) -> sandbox.kill() return callback err if err callback(undefined, result) diff --git a/test/fixtures/ruby-hooks/hooks-worker-client.coffee b/test/fixtures/ruby-hooks/hooks-worker-client.coffee index 63f38b465..1b3a7c461 100644 --- a/test/fixtures/ruby-hooks/hooks-worker-client.coffee +++ b/test/fixtures/ruby-hooks/hooks-worker-client.coffee @@ -8,7 +8,7 @@ HOOK_TIMEOUT = 5000 WORKER_HOST = 'localhost' WORKER_PORT = 61321 WORKER_MESSAGE_DELIMITER = "\n" -WORKER_COMMAND = 'ruby ' + path.normalize(path.join __dirname, './test/fixtures/ruby-hooks/dredd-worker.rb') +WORKER_COMMAND = 'ruby ' + path.normalize(path.join __dirname, '../../fixtures/ruby-hooks/dredd-worker.rb') emitter = new EventEmitter diff --git a/test/integration/cli-test.coffee b/test/integration/cli-test.coffee index f83cdcffb..6b10e72c7 100644 --- a/test/integration/cli-test.coffee +++ b/test/integration/cli-test.coffee @@ -14,7 +14,7 @@ stdout = '' exitStatus = null requests = [] -binDredd = path.normalize(path.join __dirname, '../../bin/dredd') +binDredd = 'node ' + path.normalize(path.join __dirname, '../../bin/dredd') execCommand = (cmd, options = {}, callback) -> stderr = '' @@ -23,7 +23,9 @@ execCommand = (cmd, options = {}, callback) -> if typeof options is 'function' callback = options - options = undefined + options = {} + + options.cwd = path.normalize path.join __dirname, '../..' cli = exec CMD_PREFIX + cmd, options, (error, out, err) -> stdout = out diff --git a/test/integration/dredd-command-test.coffee b/test/integration/dredd-command-test.coffee index 6475a5006..30b1ca173 100644 --- a/test/integration/dredd-command-test.coffee +++ b/test/integration/dredd-command-test.coffee @@ -90,7 +90,7 @@ describe "DreddCommand class Integration", () -> app.get '/', (req, res) -> res.sendStatus 404 app.get '/file.apib', (req, res) -> - stream = fs.createReadStream(path.normalize path.join __dirname, './test/fixtures/single-get.apib') + stream = fs.createReadStream(path.normalize path.join __dirname, '../fixtures/single-get.apib') stream.pipe res.type('text') app.get '/machines', (req, res) -> diff --git a/test/unit/config-utils-test.coffee b/test/unit/config-utils-test.coffee index 63be2d14c..ea77fb837 100644 --- a/test/unit/config-utils-test.coffee +++ b/test/unit/config-utils-test.coffee @@ -2,6 +2,7 @@ proxyquire = require 'proxyquire' sinon = require 'sinon' clone = require 'clone' +path = require 'path' fsStub = require 'fs' @@ -60,7 +61,7 @@ argvData = q: false path: [] p: [] - '$0': 'node ./bin/dredd' + '$0': "node #{path.normalize path.join(__dirname, '../../bin/dredd')}" describe 'configUtils', () -> argv = null @@ -133,11 +134,11 @@ describe 'configUtils', () -> describe 'when path is given', () -> it 'should save to that path', () -> - path = 'some-other-location.yml ' - configUtils.save argv, path + otherPath = 'some-other-location.yml ' + configUtils.save argv, otherPath call = fsStub.writeFileSync.getCall(0) args = call.args - assert.include args[0], path + assert.include args[0], otherPath describe 'load(path)', () -> @@ -187,11 +188,11 @@ describe 'configUtils', () -> describe 'when path is given', () -> it 'should load from that path', () -> - path = 'some-other-location.yml ' - configUtils.load path + otherPath = 'some-other-location.yml ' + configUtils.load otherPath call = fsStub.readFileSync.getCall(0) args = call.args - assert.include args[0], path + assert.include args[0], otherPath it 'should move blueprint and enpoint to an array under _ key', () -> output = configUtils.load()