mfncooper/mockery — pull request #21 by MauriceButler (2014-07-10 02:16:34+00:00)
Title: changed to be able to instancate a new instance with different cache

I use mockery heavily in modular test structures, ie running tests would require multiple test files which would require mockery many times.

This means that until now a mock that was registered in a previous test file will also be available to other tests. Which is sometime good but not always.

The fact that tests also run asynchronously means that other tests can change the mock at inopportune times...

I have now made it so a new instance of mockery can be created which has its own registered cache so that different tests can be separated from each other cleanly and stop the async code changing my mocks before I want them too.

This means a new instance of mockery can now be instantiated like so:

var Mockery = require('mockery'),
mockery = new Mockery();

You will see in mockery.js line:334 I have added some code to allow backwards compatibility with the original syntax and functionality so this change will not break existing installations and mockery can still be used as such:

var mockery = require('mockery');

I have ensured the existing tests still pass and the new functionality has been tested in exactly the same way.