prose/prose — pull request #801 by anandthakker (2014-12-20 17:28:05+00:00)
Title: Refactor test mocking

Continuing discussion from #798

@mikemorris @dereklieu Take a look and let me know what you think. Summary of the refactor:

- File structure in `test/mocks` that's intended to mirror the `app` directory.
- `test/mocks/helpers` module exposes a `distate` singleton ([implementation][0]), which holds on to dependency injection state that allows for coordinating mock objects as we [discussed][1]. Only has to be referenced explicitly in the mock code itself (i.e., test code need not be aware of it). Usage:
** mocks/mock/mocksomething.js **
```javascript
var distate = require('../helpers').distate;
module.exports = distate.register(myFunctionThatMakesAMockObject);
```
** a test **
```javascript
var mockSomething = require('../../mocks/mocksomething');
/* ... describe() blah blah ... */
beforeEach(function() { mockSomething.reset(); } // `distate.register` decorates the function with a reset(), which clears the distate.
it('does whatever', function() { var mockedObject = mockSomething(); })
```

[0]: https://github.com/prose/prose/commit/7aa68cba80418b2bec38a8205abe3040fe8ec15e#diff-aa0dd0f87320605191a89f92052b6045R9
[1]: https://github.com/prose/prose/pull/798#issuecomment-66705348