Closed mrrogge closed 3 years ago
Aha, just found out this works:
local testModule = {
testFunction=function() end
}
stub(testModule, 'testFunction', function() print('replaced original') end)
testModule.testFunction() --'replaced original'
If I find time I'll do a PR to update the docs with this info. I'll go ahead and close the issue.
From the busted docs:
So spies call the original function, and stubs do not. I'm wondering if there is a way to replace a function with a spy or stub that also calls a new function. For example:
For now I'm just monkeypatching the original as a workaround, but it would be nice if I could use the
revert()
to undo the change at the end of the test.Edit: reworded my question a little bit