This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from apiaryio/fix-10
Fixing exit status and adding CLI tests
- Loading branch information
Showing
7 changed files
with
137 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/sh | ||
cd $(dirname $0)/.. | ||
find ./test/unit -name '*-test.coffee' | xargs mocha --reporter spec --compilers 'coffee:coffee-script' | ||
find ./test/ -name '*-test.coffee' | xargs mocha --reporter spec --compilers 'coffee:coffee-script' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FORMAT: X-1A | ||
|
||
# Machines API | ||
|
||
# Group Machines | ||
|
||
# Machines collection [/machines] | ||
|
||
## Get Machines [GET] | ||
|
||
- Response 202 (application/json) | ||
|
||
[ | ||
{ | ||
"type": "bulldozer", | ||
"name": "willy" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,89 @@ | ||
describe 'Command-Line interface', () -> | ||
describe '--dry-run option', () -> | ||
{assert} = require('chai') | ||
{exec} = require('child_process') | ||
express = require 'express' | ||
|
||
|
||
|
||
PORT = '3333' | ||
CMD_PREFIX = '' | ||
describe "Command line interface", () -> | ||
|
||
describe "Arguments with existing bleurpint and responding server", () -> | ||
describe "when executing the command and the server is responding as specified in the blueprint", () -> | ||
stderr = '' | ||
stdout = '' | ||
exitStatus = null | ||
requests = [] | ||
|
||
before (done) -> | ||
cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT}" | ||
|
||
app = express() | ||
|
||
app.get '/machines', (req, res) -> | ||
res.setHeader 'Content-Type', 'application/json' | ||
machine = | ||
type: 'bulldozer' | ||
name: 'willy' | ||
response = [machine] | ||
res.send 200, response | ||
|
||
server = app.listen PORT, () -> | ||
cli = exec CMD_PREFIX + cmd, (error, out, err) -> | ||
cli = exec cmd, (error, out, err) -> | ||
stdout = out | ||
stderr = err | ||
|
||
if error | ||
exitStatus = error.code | ||
|
||
eventName = if process.version.split('.')[1] is '6' then 'exit' else 'close' | ||
|
||
cli.on eventName, (code) -> | ||
exitStatus = code if exitStatus == null and code != undefined | ||
server.close() | ||
|
||
server.on 'close', done | ||
|
||
it 'exit status should be 0', () -> | ||
assert.equal exitStatus, 0 | ||
|
||
describe "when executing the command and the server is sending different response", () -> | ||
stderr = '' | ||
stdout = '' | ||
exitStatus = null | ||
requests = [] | ||
|
||
before (done) -> | ||
cmd = "./bin/dredd ./test/fixtures/single_get.md http://localhost:#{PORT}" | ||
|
||
app = express() | ||
|
||
app.get '/machines', (req, res) -> | ||
res.setHeader 'Content-Type', 'application/json' | ||
machine = | ||
kind: 'bulldozer' | ||
imatriculation: 'willy' | ||
response = [machine] | ||
res.send 201, response | ||
|
||
server = app.listen PORT, () -> | ||
cli = exec CMD_PREFIX + cmd, (error, out, err) -> | ||
cli = exec cmd, (error, out, err) -> | ||
stdout = out | ||
stderr = err | ||
|
||
if error | ||
exitStatus = error.code | ||
|
||
eventName = if process.version.split('.')[1] is '6' then 'exit' else 'close' | ||
|
||
cli.on eventName, (code) -> | ||
exitStatus = code if exitStatus == null and code != undefined | ||
|
||
server.close() | ||
|
||
server.on 'close', done | ||
|
||
it 'exit status should be 1', () -> | ||
assert.equal exitStatus, 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters