Skip to content

Commit b892788

Browse files
authored
Merge pull request #182 from cybertk/fix-baseUri
Fix #180
2 parents a5b0451 + 6857c0b commit b892788

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

lib/abao.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Abao
4040
# Parse tests from RAML
4141
(raml, callback) ->
4242
if !config.options.server
43-
if 'baseUri' in raml
43+
if raml.baseUri
4444
config.options.server = raml.baseUri
4545
addTests raml, tests, hooks, callback, factory
4646
,

test/cli-test.coffee

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,51 @@ describe 'Command line interface', ->
178178

179179

180180
describe 'Arguments with existing RAML and responding server', () ->
181+
describe 'when invoked without "--server" option', () ->
182+
describe 'when RAML file hasn\'t correct baseUri', () ->
183+
before (done) ->
184+
ramlFile = "#{RAML_DIR}/no-base-uri.raml"
185+
cmd = "#{ABAO_BIN} #{ramlFile} --reporter json"
186+
187+
execCommand cmd, done
188+
189+
it 'should exit with status 1', ->
190+
assert.equal exitStatus, 1
191+
192+
it 'should print error message to stderr', ->
193+
assert.include stderr, 'no API endpoint specified'
194+
195+
describe 'when RAML file has correct baseUri', () ->
196+
197+
before (done) ->
198+
ramlFile = "#{RAML_DIR}/single-get.raml"
199+
cmd = "#{ABAO_BIN} #{ramlFile} --reporter json"
200+
201+
app = express()
202+
203+
app.get '/machines', (req, res) ->
204+
res.setHeader 'Content-Type', 'application/json'
205+
machine =
206+
type: 'bulldozer'
207+
name: 'willy'
208+
response = [machine]
209+
res.status(200).send response
210+
211+
server = app.listen PORT, () ->
212+
execCommand cmd, () ->
213+
server.close()
214+
215+
server.on 'close', done
216+
217+
it 'exit status should be 0', () ->
218+
assert.equal exitStatus, 0
219+
220+
it 'should print count of tests run', ->
221+
assert.equal 1, report.tests.length
222+
assert.equal 1, report.passes.length
223+
224+
it 'should print correct title for response', ->
225+
assert.equal report.tests[0].fullTitle, 'GET /machines -> 200 Validate response code and body'
181226

182227
describe 'when executing the command and the server is responding as specified in the RAML', () ->
183228
before (done) ->

test/fixtures/no-base-uri.raml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#%RAML 0.8
2+
3+
title: World Music API
4+
version: v1
5+
traits:
6+
- paged:
7+
queryParameters:
8+
pages:
9+
description: The number of pages to return
10+
type: number
11+
/songs:
12+
is: [ paged ]
13+
get:
14+
queryParameters:
15+
genre:
16+
description: filter the songs by genre
17+
post:
18+
/{songId}:
19+
get:
20+
responses:
21+
200:
22+
body:
23+
application/json:
24+
schema: |
25+
{ "$schema": "http://json-schema.org/schema",
26+
"type": "object",
27+
"description": "A canonical song",
28+
"properties": {
29+
"title": { "type": "string" },
30+
"artist": { "type": "string" }
31+
},
32+
"required": [ "title", "artist" ]
33+
}
34+
example: |
35+
{ "title": "A Beautiful Day", "artist": "Mike" }
36+
application/xml:
37+
delete:
38+
description: |
39+
This method will *delete* an **individual song**

test/fixtures/single-get.raml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#%RAML 0.8
22

33
title: World Music API
4-
baseUri: http://example.api.com/{version}
5-
version: v1
4+
baseUri: http://localhost:3333
65

76
/machines:
87
get:

0 commit comments

Comments
 (0)