Permalink
Browse files

add coverage and badges

  • Loading branch information...
1 parent bb1f68a commit c77a83dad8be40deb235ac515860a4b844dd5293 @jonathanong jonathanong committed Sep 2, 2014
Showing with 102 additions and 27 deletions.
  1. +23 −1 .gitignore
  2. +6 −0 .travis.yml
  3. +22 −0 LICENSE
  4. +0 −6 Makefile
  5. +15 −5 package.json
  6. +22 −1 readme.md
  7. +14 −14 { → test}/test.js
View
@@ -1 +1,23 @@
-node_modules
+# OS X
+.DS_Store*
+Icon?
+._*
+
+# Windows
+Thumbs.db
+ehthumbs.db
+Desktop.ini
+
+# Linux
+.directory
+*~
+
+
+# npm
+node_modules
+*.log
+*.gz
+
+
+# Coveralls
+coverage
View
@@ -0,0 +1,6 @@
+node_js:
+- "0.10"
+- "0.11"
+language: node_js
+script: "npm run-script test-travis"
+after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
View
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2014
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,6 +0,0 @@
-test:
- @./node_modules/.bin/mocha \
- --reporter spec \
- --bail
-
-.PHONY: test
View
@@ -3,11 +3,21 @@
"version": "1.0.1",
"description": "assert with status codes",
"devDependencies": {
- "mocha": "~1.17.0"
+ "istanbul": "~0.3.0",
+ "mocha": "~1.17"
},
- "repository": {
- "type": "git",
- "url": "https://github.com/eivindfjeldstad/http-assert.git"
+ "repository": "jshttp/http-assert",
+ "files": [
+ "LICENSE",
+ "index.js"
+ ],
+ "scripts": {
+ "test": "mocha --reporter spec --bail --check-leaks test/",
+ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
+ "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
- "license": "MIT"
+ "keywords": [
+ "assert",
+ "http"
+ ]
}
View
@@ -1,4 +1,12 @@
#http-assert
+
+[![NPM version][npm-image]][npm-url]
+[![Build status][travis-image]][travis-url]
+[![Test coverage][coveralls-image]][coveralls-url]
+[![Dependency Status][david-image]][david-url]
+[![License][license-image]][license-url]
+[![Downloads][downloads-image]][downloads-url]
+
Assert with status codes. Like ctx.throw() in Koa, but with a guard.
##Example
@@ -16,4 +24,17 @@ try {
```
##Licence
-MIT
+MIT
+
+[npm-image]: https://img.shields.io/npm/v/http-assert.svg?style=flat-square
+[npm-url]: https://npmjs.org/package/http-assert
+[travis-image]: https://img.shields.io/travis/jshttp/http-assert.svg?style=flat-square
+[travis-url]: https://travis-ci.org/jshttp/http-assert
+[coveralls-image]: https://img.shields.io/coveralls/jshttp/http-assert.svg?style=flat-square
+[coveralls-url]: https://coveralls.io/r/jshttp/http-assert?branch=master
+[david-image]: http://img.shields.io/david/jshttp/http-assert.svg?style=flat-square
+[david-url]: https://david-dm.org/jshttp/http-assert
+[license-image]: http://img.shields.io/npm/l/http-assert.svg?style=flat-square
+[license-url]: LICENSE
+[downloads-image]: http://img.shields.io/npm/dm/http-assert.svg?style=flat-square
+[downloads-url]: https://npmjs.org/package/http-assert
@@ -1,68 +1,68 @@
-var assert = require('./');
+var assert = require('..');
var ok = require('assert');
describe('assert()', function () {
it('should throw when guard is falsy', function () {
var err;
-
+
try {
assert(false, 401, 'fail');
} catch (e) {
err = e;
}
-
+
ok(err);
ok(err.status == 401);
ok(err.message == 'fail');
ok(err.expose);
})
-
+
it('should not throw when guard is truthy', function () {
assert(true, 401, 'fail');
})
-
+
it('should accept options for the error object', function () {
var err;
-
+
try {
assert(false, 401, 'fail', { expose: false });
} catch (e) {
err = e;
}
-
+
ok(err);
ok(err.status == 401);
ok(err.message == 'fail');
ok(!err.expose);
})
-
+
it('should not expose 5xx errors', function () {
var err;
-
+
try {
assert(false, 500);
} catch (e) {
err = e;
}
-
+
ok(err);
ok(err.status == 500);
ok(err.message == 'Internal Server Error');
ok(!err.expose);
});
-
+
it('should default to status code 500', function () {
var err;
-
+
try {
assert(false, 'fail');
} catch (e) {
err = e;
}
-
+
ok(err);
ok(err.status == 500);
ok(err.message == 'fail');
ok(!err.expose);
});
-})
+})

0 comments on commit c77a83d

Please sign in to comment.