How to double a class with _init(value).
Hey, on the Doubles wiki page you mentioned, that it is possible to double a class which has for example _init(value). I couldnt get it working. It would be nice to have an example in the wiki.
Good find. Here is the specific section where the link should have gone: https://github.com/bitwes/Gut/wiki/Stubbing#stubbing-method-paramter-defaults. But that section doesn't explain in detail how to stub _init. The following should be added to the Doubling or Stubbing page.
To stub _init you would do the following:
Given:
class StubMyInit:
var bar = 1
func _init(foo):
bar = foo
Stubbing _init in a test like this:
func test_foo_init_param_stub():
# stubbing _init parameters must be done using the class, and
# happen before calling double since the defaults will be
# used when new is called.
stub(StubMyInit, '_init').param_defaults([99])
var dbl = double(StubMyInit).new()
assert_eq(dbl.bar, 99)
Test.zip This does not work for me. I use Godot 3.5 and uploaded a test project. The file for testing are in the folder test.
Sorry, I forgot another condition is that all _init params must have defaults. Changing _init to this made the test pass:
func _init(foo=1):