2013-11-13 17:01:15 +00:00
|
|
|
|
|
|
|
var context = require('../context');
|
|
|
|
var assert = require('assert');
|
|
|
|
|
2013-11-19 01:38:12 +00:00
|
|
|
describe('ctx.throw(msg)', function(){
|
2013-11-13 17:01:15 +00:00
|
|
|
it('should set .status to 500', function(done){
|
|
|
|
var ctx = context();
|
|
|
|
|
|
|
|
try {
|
2013-11-19 01:38:12 +00:00
|
|
|
ctx.throw('boom');
|
2013-11-13 17:01:15 +00:00
|
|
|
} catch (err) {
|
|
|
|
assert(500 == err.status);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2013-11-19 01:38:12 +00:00
|
|
|
describe('ctx.throw(msg, status)', function(){
|
2013-11-13 17:01:15 +00:00
|
|
|
it('should throw an error', function(done){
|
|
|
|
var ctx = context();
|
|
|
|
|
|
|
|
try {
|
2013-11-19 01:38:12 +00:00
|
|
|
ctx.throw('name required', 400);
|
2013-11-13 17:01:15 +00:00
|
|
|
} catch (err) {
|
|
|
|
assert('name required' == err.message);
|
|
|
|
assert(400 == err.status);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2013-11-19 01:38:12 +00:00
|
|
|
describe('ctx.throw(status)', function(){
|
2013-11-13 17:01:15 +00:00
|
|
|
it('should throw an error', function(done){
|
|
|
|
var ctx = context();
|
|
|
|
|
|
|
|
try {
|
2013-11-19 01:38:12 +00:00
|
|
|
ctx.throw(400);
|
2013-11-13 17:01:15 +00:00
|
|
|
} catch (err) {
|
|
|
|
assert('Bad Request' == err.message);
|
|
|
|
assert(400 == err.status);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|