Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #81 from apiaryio/netmilk/protagonist-0-12
Browse files Browse the repository at this point in the history
Protagonist 0.12.0, showing blueprint parsing warnings
  • Loading branch information
Adam Kliment committed Jul 15, 2014
2 parents 39217bb + cfb7f4e commit 759e203
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"url": "https://github.com/apiaryio/dredd"
},
"dependencies": {
"gavel": "~0.3.3",
"gavel": "~0.3.4",
"winston": "~0.7.2",
"protagonist": "~0.11.0",
"protagonist": "~0.12.0",
"uri-template": "~0.4.1",
"async": "~0.9.0",
"optimist": "~0.6.0",
Expand Down
14 changes: 11 additions & 3 deletions src/dredd.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Dredd
config = @configuration
stats = @stats

fs.readFile config.blueprintPath, 'utf8', (parseError, data) ->
return callback(parseError, stats) if parseError
fs.readFile config.blueprintPath, 'utf8', (loadingError, data) ->
return callback(loadingError, stats) if loadingError
reporterCount = config.emitter.listeners('start').length
config.emitter.emit 'start', data, () ->
reporterCount--
Expand All @@ -41,7 +41,15 @@ class Dredd

blueprintParsingComplete = (protagonistError, result) =>
return callback(protagonistError, config.reporter) if protagonistError


if result['warnings'].length > 0
for warning in result['warnings']
message = 'Parser warning: ' + ' (' + warning.code + ') ' + warning.message
for loc in warning['location']
pos = loc.index + ':' + loc.length
message = message + ' ' + pos
logger.warn message

runtime = blueprintAstToRuntime result['ast']
runtimeError = handleRuntimeProblems runtime
return callback(runtimeError, stats) if runtimeError
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/warning-ambigous.apib
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ FORMAT: X-1A
## Delete Message [DELETE]
+ Parameters
+ name (required,`waldo`)
+ Response 204

13 changes: 10 additions & 3 deletions test/unit/dredd-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,18 @@ describe 'Dredd class', () ->
silent: true
dredd = new Dredd(configuration)

beforeEach () ->
beforeEach () ->
sinon.stub dredd.runner, 'executeTransaction', (transaction, callback) ->
callback()

afterEach () ->
afterEach () ->
dredd.runner.executeTransaction.restore()

it 'should exit with an error', (done) ->
dredd.run (error) ->
assert.ok error
done()


it 'should NOT execute any transaction', (done) ->
dredd.run () ->
assert.notOk dredd.runner.executeTransaction.called
Expand All @@ -132,15 +131,23 @@ describe 'Dredd class', () ->
beforeEach () ->
sinon.stub dredd.runner, 'run', (transaction, callback) ->
callback()
sinon.spy loggerStub, 'warn'

afterEach () ->
dredd.runner.run.restore()
loggerStub.warn.restore()

it 'should execute the runtime', (done) ->
dredd.run () ->
assert.ok dredd.runner.run.called
done()

it 'should write warnings to warn logger', (done) ->
dredd.run () ->
assert.ok loggerStub.warn.called
done()


describe 'when non existing Blueprint path', () ->

beforeEach () ->
Expand Down

0 comments on commit 759e203

Please sign in to comment.