[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lemock mock out another function along with SUT in the same module
- From: Tom N Harris <telliamed@...>
- Date: Tue, 22 Jul 2014 14:16:48 -0400
On Tuesday, July 22, 2014 03:10:23 PM albert_200200 wrote:
> Hi, guys, I'm using lunit and lemock to test my code,
> Here is the situation: the function I should mock is in the same module
> of the function I'm testing.
I'm not entirely familiar with lemock, however...
> package.path = "./?.lua;"..package.path
> local foo = require("foo")
> package.loaded.foo.dowork_internal = nil
> package.preload["foo.dowork_internal"] = function()
> return self.mock_dowork_internal
> local val = foo.dowork(vala, valb)
> assert_equal(val, 2)
That isn't how package.preload works. The preload functions are module
loaders. The loader function is called by require to create the module table.
The value returned by the loader is then stored in package.loaded.foo and also
returned by require.
I think all you need is to assign the mock function to foo.dowork_internal.