idottv/dependable — pull request #20 by mickhansen (2013-12-13 11:28:58+00:00)
Title: save/restore state

This feature allows a user to export the current factories via saveState, and then re-instate them with restoreState.
This is handy when doing testing with mocks, mocks in one test with register might conflict with another tests that need the real object.

container.register('redis', require('redis'));

beforeEach(function () {
if (this.dependencyState) container.restoreState(this.dependencyState);

// General test prep

if (!this.dependencyState) this.dependencyState = container.saveState();
});

it('should call redis methods', function () {
container.register('redis', {
get: sinon.spy()
});

// ... tests
})

it('should use redis', function () {
var redis = container.get('redis');

redis.get(key, function (err, results) {
// ... tests
});
});