Skip to content

Instantly share code, notes, and snippets.

@lawrencejones
Created June 8, 2014 13:29
Show Gist options
  • Save lawrencejones/8c4e49d3313697679970 to your computer and use it in GitHub Desktop.
Save lawrencejones/8c4e49d3313697679970 to your computer and use it in GitHub Desktop.
# Configure default remote server for dredd tests
REMOTE = 'http://localhost:55000'
desc 'Runs dredd to verify API matches the apiary docs'
task 'dredd', [], async: true, ->
title "Running dredd on ./apiary.apib with #{REMOTE} remote"
log 'Reading Imperial credentials from ~/.imp'
try [user, pass] =
fs.readFileSync("#{process.env.HOME}/.imp", 'utf8').split '\n'
catch err
fail 'Failed to read credentials from ~/.imp'
log "Atempting to auth against #{REMOTE}"
reqOpt =
url: "#{REMOTE}/authenticate"
method: 'POST'
json: user: user, pass: pass
request reqOpt, (err, res, body) ->
if err? then fail "Failed to reach #{REMOTE}. Is server running?"
if res.statusCode is not 200
fail "Failed to authenticate with code #{res.statusCode}"
token = body.token
log "Got token! #{token[0..14]}..."
chain\
( [ 'dredd'
, [ './apiary.apib', REMOTE, '-h', "Authorization: Bearer #{token}" ]
, 'Failed to run dredd. Is it installed globally?' ]
, [ 'Successfully completed dredd tests' ] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment