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

Commit 3cfd1bd

Browse files
author
Adam Kliment
committed
Tested cliUtils
1 parent 73f27c0 commit 3cfd1bd

File tree

5 files changed

+110
-13
lines changed

5 files changed

+110
-13
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# WARNING! NOT STABLE, UNDER STRONG DEVELOPMENT
2-
31
# Dredd—API Blueprint Testing Tool
42

53
[![Build Status](https://travis-ci.org/apiaryio/dredd.png?branch=master)](https://travis-ci.org/apiaryio/dredd)

src/cli.coffee

+11-11
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,8 @@ cli = (configuration, callback) ->
1919
callback()
2020
else
2121
runtime = blueprintAstToRuntime result['ast']
22-
if runtime['errors'].length > 0
23-
cliUtils.exit 1
24-
for error in runtime['errors']
25-
message = error['message']
26-
origin = error['origin']
2722

28-
cliUtils.log "Runtime compilation error: \"" + error['message'] + "\" on " + \
29-
origin['resourceGroupName'] + \
30-
' > ' + origin['resourceName'] + \
31-
' > ' + origin['actionName']
32-
3323
if runtime['warnings'].length > 0
34-
cliUtils.exit 1
3524
for warning in runtime['warnings']
3625
message = warning['message']
3726
origin = warning['origin']
@@ -41,6 +30,17 @@ cli = (configuration, callback) ->
4130
' > ' + origin['resourceName'] + \
4231
' > ' + origin['actionName']
4332

33+
if runtime['errors'].length > 0
34+
for error in runtime['errors']
35+
message = error['message']
36+
origin = error['origin']
37+
38+
cliUtils.log "Runtime compilation error: \"" + error['message'] + "\" on " + \
39+
origin['resourceGroupName'] + \
40+
' > ' + origin['resourceName'] + \
41+
' > ' + origin['actionName']
42+
cliUtils.exit 1
43+
4444
tranasctionsWithConfigutration = []
4545

4646
for transaction in runtime['transactions']

test/fixtures/warning-ambigous.apib

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FORMAT: X-1A
2+
3+
# Machines API
4+
# Group Machines
5+
6+
# Machine [/machines/{name}]
7+
8+
9+
## Update a Machine [PUT]
10+
11+
+ Request (application/json)
12+
13+
{
14+
"name": "waldo"
15+
}
16+
17+
+ Response 200 (application/json)
18+
19+
{
20+
"type": "bulldozer",
21+
"name": "waldo",
22+
"_id": "5229c6e8e4b0bd7dbb07e29c"
23+
}
24+
25+
## Retrieve a Machine [GET]
26+
+ Parameters
27+
+ name (required,`waldo`)
28+
29+
+ Response 200 (text/plain)
30+
31+
{
32+
"type": "bulldozer",
33+
"name": "waldo",
34+
"_id": "5229c6e8e4b0bd7dbb07e29c"
35+
}
36+
37+
## Delete Message [DELETE]
38+
+ Parameters
39+
+ name (required,`waldo`)
40+
+ Response 204

test/unit/cli-test.coffee

+20
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ describe 'cli()', () ->
134134
assert.ok cliUtilsStub.exit.calledWith(1)
135135
done()
136136

137+
describe 'when runtime contains any warning', () ->
138+
before () ->
139+
configuration =
140+
blueprintPath: './test/fixtures/warning-ambigous.apib'
141+
server: 'http://localhost:3000/'
142+
143+
executeTransactionStub.reset()
144+
145+
it 'should execute some transaction', (done) ->
146+
cli configuration, () ->
147+
assert.ok executeTransactionStub.called
148+
done()
149+
150+
it 'should print runtime warnings to stdout'
151+
152+
it 'should not exit', (done) ->
153+
cli configuration, () ->
154+
assert.ok cliUtilsStub.exit.calledWith(0)
155+
done()
156+
137157
describe 'when runtime is without errors and warnings', () ->
138158
beforeEach () ->
139159
executeTransactionStub.reset()

test/unit/cli-utils-test.coffee

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{assert} = require 'chai'
2+
sinon = require 'sinon'
3+
cliUtils = require '../../src/cli-utils'
4+
5+
describe 'cliUtils', () ->
6+
describe 'exit', () ->
7+
beforeEach () ->
8+
sinon.stub process, 'exit'
9+
10+
afterEach () ->
11+
process.exit.restore()
12+
13+
it 'should call process.exit', () ->
14+
cliUtils.exit(0)
15+
assert.ok process.exit.called
16+
17+
18+
describe 'log', () ->
19+
beforeEach () ->
20+
sinon.stub console, 'log'
21+
22+
afterEach () ->
23+
console.log.restore()
24+
25+
it 'should call console.log', () ->
26+
cliUtils.log('log entry')
27+
assert.ok console.log.called
28+
29+
describe 'error', () ->
30+
beforeEach () ->
31+
sinon.stub console, 'error'
32+
33+
afterEach () ->
34+
console.error.restore()
35+
36+
it 'should call console.log', () ->
37+
cliUtils.error('error entry')
38+
assert.ok console.error.called
39+

0 commit comments

Comments
 (0)