diff --git a/lib/abao.coffee b/lib/abao.coffee index a6a57ec..f85423b 100644 --- a/lib/abao.coffee +++ b/lib/abao.coffee @@ -40,7 +40,7 @@ class Abao # Parse tests from RAML (raml, callback) -> if !config.options.server - if 'baseUri' in raml + if raml.baseUri config.options.server = raml.baseUri addTests raml, tests, hooks, callback, factory , diff --git a/test/cli-test.coffee b/test/cli-test.coffee index 6f5782f..4fea3c8 100644 --- a/test/cli-test.coffee +++ b/test/cli-test.coffee @@ -178,6 +178,51 @@ describe 'Command line interface', -> describe 'Arguments with existing RAML and responding server', () -> + describe 'when invoked without "--server" option', () -> + describe 'when RAML file hasn\'t correct baseUri', () -> + before (done) -> + ramlFile = "#{RAML_DIR}/no-base-uri.raml" + cmd = "#{ABAO_BIN} #{ramlFile} --reporter json" + + execCommand cmd, done + + it 'should exit with status 1', -> + assert.equal exitStatus, 1 + + it 'should print error message to stderr', -> + assert.include stderr, 'no API endpoint specified' + + describe 'when RAML file has correct baseUri', () -> + + before (done) -> + ramlFile = "#{RAML_DIR}/single-get.raml" + cmd = "#{ABAO_BIN} #{ramlFile} --reporter json" + + app = express() + + app.get '/machines', (req, res) -> + res.setHeader 'Content-Type', 'application/json' + machine = + type: 'bulldozer' + name: 'willy' + response = [machine] + res.status(200).send response + + server = app.listen PORT, () -> + execCommand cmd, () -> + server.close() + + server.on 'close', done + + it 'exit status should be 0', () -> + assert.equal exitStatus, 0 + + it 'should print count of tests run', -> + assert.equal 1, report.tests.length + assert.equal 1, report.passes.length + + it 'should print correct title for response', -> + assert.equal report.tests[0].fullTitle, 'GET /machines -> 200 Validate response code and body' describe 'when executing the command and the server is responding as specified in the RAML', () -> before (done) -> diff --git a/test/fixtures/no-base-uri.raml b/test/fixtures/no-base-uri.raml new file mode 100644 index 0000000..f485c7a --- /dev/null +++ b/test/fixtures/no-base-uri.raml @@ -0,0 +1,39 @@ +#%RAML 0.8 + +title: World Music API +version: v1 +traits: + - paged: + queryParameters: + pages: + description: The number of pages to return + type: number +/songs: + is: [ paged ] + get: + queryParameters: + genre: + description: filter the songs by genre + post: + /{songId}: + get: + responses: + 200: + body: + application/json: + schema: | + { "$schema": "http://json-schema.org/schema", + "type": "object", + "description": "A canonical song", + "properties": { + "title": { "type": "string" }, + "artist": { "type": "string" } + }, + "required": [ "title", "artist" ] + } + example: | + { "title": "A Beautiful Day", "artist": "Mike" } + application/xml: + delete: + description: | + This method will *delete* an **individual song** diff --git a/test/fixtures/single-get.raml b/test/fixtures/single-get.raml index 8a223e1..ff0a817 100644 --- a/test/fixtures/single-get.raml +++ b/test/fixtures/single-get.raml @@ -1,8 +1,7 @@ #%RAML 0.8 title: World Music API -baseUri: http://example.api.com/{version} -version: v1 +baseUri: http://localhost:3333 /machines: get: