Skip to content

Commit

Permalink
Fix #180
Browse files Browse the repository at this point in the history
  • Loading branch information
galkin committed Sep 30, 2016
1 parent a5b0451 commit 447c34c
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/abao.coffee
Expand Up @@ -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
,
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "abao",
"version": "0.4.1-beta.0",
"version": "0.4.1-beta.1",
"description": "RAML testing tool",
"bin": "bin/abao",
"main": "lib/index.js",
Expand Down
45 changes: 45 additions & 0 deletions test/cli-test.coffee
Expand Up @@ -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) ->
Expand Down
39 changes: 39 additions & 0 deletions 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**
3 changes: 1 addition & 2 deletions 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:
Expand Down

0 comments on commit 447c34c

Please sign in to comment.