CFC-Servers / GLuaTest

An exciting and nimble unit testing framework for GLua projects
https://discord.gg/epJK9Xx3pc
GNU General Public License v3.0
51 stars 2 forks source link

Allow stubs to replace non-function values too #37

Open brandonsturgeon opened 1 year ago

brandonsturgeon commented 1 year ago

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
}