> Unfortunately, there's actually a bug in mockery.js which prevents the node
> module cache from being cleared.

The bug has been fixed in Mockery 1.1.2, now available via npm. The
cause was a change in the Node module loader starting in Node v0.6.10.
The latest Mockery now works with both older and newer versions of
Node.

--
Martin Cooper


On Mon, Mar 12, 2012 at 12:12 AM, Aneil Mallavarapu <an...@blipboard.com> wrote:
> Hi Bryan -
> The way mockery suggests you handle this issue is by calling
>
>      mockery.registerAllowable("modulePath",true);
>
> Where the second argument is "unhook", a signal which tells
>
>      mockery.deregisterAll()
>
> to remove the module from the node module cache.
>
> Unfortunately, there's actually a bug in mockery.js which prevents the node
> module cache from being cleared.
>
> I've committed a fix to my fork: https://github.com/amallavarapu/mockery
>
> Details of the bug are in this pull request:
>  https://github.com/mfncooper/mockery/pull/6
>
> I've also added functions to ensure ALL modules are cleared from the module
> cache after tests are run in this commit.  Just call:
>
>      mockery.registerAllAllowableStart(true)
>
> In the before() block before you load the modules required for the test.
>  Then call:
>
>      mockery.registerAllAllowableEnd();
>      mockery.deregisterAll();
>
> In the after() block.  This removes from the cache all the modules loaded
> between the start and end calls.
>
> Aneil
> On Monday, December 19, 2011 6:33:55 PM UTC-8, Bryan Donovan wrote:
>>
>> I'm currently using Mocha with Mockery for unit testing.  I can't figure
>> out a good way to deal with this situation:
>>
>> Test A requires a real module.
>> Test B and mocks that same module.
>>
>> Running Test A in isolation passes.
>> Running Test B in isolation passes.
>> Running both at once: Test B fails every time.
>>
>> In the third scenario, Test B fails because the real module has already
>> been loaded (even if Test A hasn't run yet).
>>
>> This occurred with Gently as well, and with nodeunit instead of Mocha, so
>> I don't think it's an issue with Mockery or Mocha.  But I'm still guessing
>> there's an easy solution to what is a trivial problem in other languages,
>> and I'm just missing it.  I'm fine with using a different mocking library if
>> that's the solution, as long as it's simple to use and doesn't require me to
>> pollute source files with weird statements like Gently does.
>>
>> I have a repeatable set of source code and tests
>> here: https://github.com/BryanDonovan/nodejs-mock-test
>>
>> Any advice would be greatly appreciated.
>>
>>
>> Thanks,
>>
>> Bryan
>>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to