Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test harness to dispatch #6

Open
pacovell opened this issue Oct 25, 2011 · 0 comments
Open

Add test harness to dispatch #6

pacovell opened this issue Oct 25, 2011 · 0 comments
Milestone

Comments

@pacovell
Copy link
Member

I've added a test harness to my production code that needs to be re-integrated into dispatch:

https://gist.github.com/1311173

It relies on the controllers.js lib file, which may also be reasonable to integrate into dispatch:

https://gist.github.com/1311177

It gets used together with sinon.js in a controller vows test like this:

var Asks = new ControlChain('asks');

function mockFindUser(user) {
    return function () {
        models.User.findById = function (id, callback) {
            callback(null, user);
        };
        sinon.spy(models.User, 'findById');
    };
}

vows.describe('Ask Controller').addBatch({
    'my, user logged in' : {
        topic : Asks.get('my', { session : { currentUserId : '123456789abc' } },
            { before : [ mockFindUser(mockObjects.user), mockFindAsks() ] }),
        'finds user' : function (err, req, res) {
            assert.ok(models.User.findById.calledOnce);
            assert.equal(mockObjects.user.id, models.User.findById.getCall(0).args[0]);
        },
        'finds asks' : function (err, req, res) {
            assert.ok(models.Ask.find.calledOnce);
        },
        'should have status OK' : function (err, req, res) {
            assert.equal(res.statusCode, 200);
        },
        'should have correct return value' : function (err, req, res) {
            assert.deepEqual(mockObjects.asks, JSON.parse(res.body));
        }
    }
}).export(module);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant