Created
April 16, 2012 13:59
-
-
Save muhammadghazali/2399002 to your computer and use it in GitHub Desktop.
Here's a sample of the boilerplate code that APIeasy eliminates when using APIeasy to test an API
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
// Get more info about APIEasy: https://github.com/flatiron/api-easy | |
// This example is originated from the Readme page of APIEasy project page. | |
// I made this gist just to keep the collection of Vows examples test suite I have to learn. | |
var request = require('request'), | |
vows = require('vows'), | |
assert = require('assert'); | |
vows.describe('your/awesome/api').addBatch({ | |
"When using your awesome api": { | |
"and your awesome resource": { | |
"A POST to /awesome": { | |
topic: function () { | |
request({ | |
uri: 'http://localhost:8080/awesome', | |
method: 'POST', | |
body: JSON.stringify({ test: 'data' }), | |
headers: { | |
'Content-Type': 'application/json' | |
} | |
}, this.callback) | |
}, | |
"should respond with 200": function (err, res, body) { | |
assert.equal(res.statusCode, 200); | |
}, | |
"should respond with ok": function (err, res, body) { | |
var result = JSON.parse(body); | |
assert.equal(result.ok, true); | |
}, | |
"should respond with x-test-header": function (err, res, body) { | |
assert.include(res.headers, 'x-test-header'); | |
} | |
} | |
} | |
} | |
}).export(module); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment