forked from 1602/compound
/
controllers.js
36 lines (30 loc) · 1021 Bytes
/
controllers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require('./spec_helper').init(exports);
global.app = {root: __dirname + '/..'};
var c = require('../lib/controller').load('test_controller.js');
it('should load controller', function (test) {
test.ok(c.respondTo('test'));
test.ok(c.respondTo('action'));
test.done();
});
it('should perform test action', perform('test', 'beforeAllExceptTest'));
it('should perform action action', perform('action', 'beforeTestOnly'));
function perform (action, except) {
return function (test) {
var req = {
notify: sinon.spy(function (msg) {
test.notEqual(msg, except);
if (msg == 'done') done();
c.next();
}),
render: function () {},
send: function () {},
redirect: function () {},
flash: function () {}
};
c.perform(action, req, 'res');
function done () {
test.equal(req.notify.callCount, 4);
test.done();
}
}
}