Skip to content

Commit

Permalink
Yo man, I heard you like "node bin/dredd"
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-kubula committed Apr 24, 2015
1 parent f38f1f9 commit cbe9b59
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/config-utils.coffee
Expand Up @@ -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

Expand All @@ -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']]
Expand Down
2 changes: 1 addition & 1 deletion src/dredd-command.coffee
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/sandbox-hooks-code.coffee
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/ruby-hooks/hooks-worker-client.coffee
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions test/integration/cli-test.coffee
Expand Up @@ -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 = ''
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/integration/dredd-command-test.coffee
Expand Up @@ -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) ->
Expand Down
15 changes: 8 additions & 7 deletions test/unit/config-utils-test.coffee
Expand Up @@ -2,6 +2,7 @@
proxyquire = require 'proxyquire'
sinon = require 'sinon'
clone = require 'clone'
path = require 'path'

fsStub = require 'fs'

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)', () ->

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit cbe9b59

Please sign in to comment.