[mocha-developer] Mocha Mock's hanging on after test run?

James Mead jamesmead44 at gmail.com
Wed Jan 17 18:24:21 EST 2007

On 17/01/07, Kevin Clark <kevin.clark at gmail.com> wrote:
> Oh, or re-reading this, if you'd like to push a bugfix it would make
> my life easy :)

Hi Kevin,

I've just had another quick look at this and I think it requires more work
than I first thought. My suggested fix only clears the expectations - it
does not return the method to its original implementation.

The assumption made by Mocha is that any concrete instances on which
expectations are set will not be re-used between tests. In the example you
give, state (in the form of the Routes constant which references an instance
of RouteSet) is being preserved between tests - hence Mocha's assumption is
broken. It shouldn't be too hard to ensure that Mocha deals with this
scenario, but I need to get some sleep now. I'll take another look in the

I assume that you're retro-fitting tests to code that you don't want to
change. Otherwise I'd suggest re-writing the code to be more easily testable
and avoid retaining state between tests.

More information about the mocha-developer mailing list