Closed Kochise closed 2 years ago
not necessarily Busted, but you could use Lua's dynamic nature.
When testing internals I typically use a global variable to indicate we're testing and export addition functions.
if _TEST then
local original = private -- store original private value
function _set_private(func) -- export as public
private = func
end
function _unset_private(func) -- export as public
private = original
end
end
in the test do _G._TEST = true
before loading the module, and then use the before/after handlers to set/unset mock functions
You mean in the test code ?
I cannot touch the original code.
No, those flags would work from the source code. So if you cannot touch the source, then I guess you're out of luck.
Damn, I feel so relieved...
Again.
Btw, thank for your insightful help.
I appreciate that.
I really do.
Hi, using busted to mock some public functions. Yet those public functions are using local/private functions. Those public functions are calling other modules and/or the std functions.
Now to test stress the public functions, I cannot stub the local/private functions. Stubbing the other modules and/or the std functions is a breeze, somewhat. The main problem is that some of those functions are called multiple times.
If I stub them, I can only return one "expected" result at a time. But to test the public functions I need to make the call tree fail->succeed one at a time. Hence modules and/or the std functions should return another result with each call.
Is there a way to emulate this behavior using busted ? Like creating a table that will be used to answer each "line" after another for each call. So that I could provide a table that fails at first, then push valid results to test try every code path.
Regards.