Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create some way to do stub a function a certain number of times #33

Open
brandonsturgeon opened this issue Nov 21, 2022 · 0 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested

Comments

@brandonsturgeon
Copy link
Member

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:

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.

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()?

@brandonsturgeon brandonsturgeon added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested labels Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant