Open brandonsturgeon opened 1 year ago
When making a stub, it may be desirable to only stub the function for a single call.
You can do this now, like:
local hookStub hookStub = stub( hook, "Call" ).with( function() hookStub:Restore() end ) hook.Call( "blah" ) expect( hookStub ).to.haveBeenCalled()
But if you don't localize hookStub first, as would be common for these sorts of tests:
hookStub
local hookStub = stub( hook, "Call" ).with( function() hookStub:Restore() end )
You would get an error on your hook.Call invocation, with the error message attempt to index global 'hookStub', a nil value.
hook.Call
attempt to index global 'hookStub', a nil value
This of course makes sense, but it can be confusing. Instead, perhaps we could have something like:
local hookStub = stubOnce( hook, "Call" ) hook.Call( "blah" ) expect( hookStub ).to.haveBeenCalled()
More realistically, we should allow a hook to be stubbed for any number of calls. Maybe as an optional third parameter to stub()?
stub()
When making a stub, it may be desirable to only stub the function for a single call.
You can do this now, like:
But if you don't localize
hookStub
first, as would be common for these sorts of tests:You would get an error on your
hook.Call
invocation, with the error messageattempt to index global 'hookStub', a nil value
.This of course makes sense, but it can be confusing. Instead, perhaps we could have something like:
More realistically, we should allow a hook to be stubbed for any number of calls. Maybe as an optional third parameter to
stub()
?