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

Allow stubs to replace non-function values too #37

Open
brandonsturgeon opened this issue Dec 6, 2022 · 0 comments
Open

Allow stubs to replace non-function values too #37

brandonsturgeon opened this issue Dec 6, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@brandonsturgeon
Copy link
Member

Sometimes you want to stub non-function values, like convars, strings, etc. from tables. Right now, you'd have to manually keep track of and clean up the changes:

{
    name = "Example"
    func = function( state )
        state.original_foo = state.original_foo or myProject.foo

        myProject.foo = "bar"
        expect( myProject:returnFoo() ).to.equal( "bar" )
    end,

    cleanup = function( state )
        myProject.foo = state.original_foo
    end
}

It would be nice if we could do:

{
    name = "Example"
    func = function( state )
        stub( myProject, "foo" ).with( "bar" )
        expect( myProject:returnFoo() ).to.equal( "bar" )
    end
}
@brandonsturgeon brandonsturgeon added enhancement New feature or request good first issue Good for newcomers labels Dec 6, 2022
@brandonsturgeon brandonsturgeon self-assigned this Dec 6, 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
Projects
None yet
Development

No branches or pull requests

1 participant