Is there a way of stubbing member variables?
Hi!
I was wondering if it is possible to stub member variables:
class_name PlayerController extends Reference
var player_name : String
func _init():
self.player_name = ""
extends GutTest
func test_member_variable_stub():
var player_controller_double = double(PlayerController).new()
var stubbed_player_name = "StubbedPlayerName"
stub(player_controller_double, "player_name").to_return(stubbed_player_name)
assert_eq(player_controller_double.player_name, stubbed_player_name)
since I'm forced to change PlayerController to be:
class_name PlayerController extends Reference
var _player_name : String
func _init():
self._player_name = ""
func request_play():
pass
func get_player_name(): -> String
return self._player_name
and stub get_player_name.
Thanks in advance! Love your work!
You cannot stub member variables, but they exist in the double so you can set it.
On Fri, Jul 22, 2022, 5:17 PM Alejandro Lozano @.***> wrote:
Hi!
I was wondering if it is possible to stub member variables:
class_name PlayerController extends Reference var player_name : String func _init(): self.player_name = ""
extends GutTest func test_member_variable_stub(): var player_controller_double = double(PlayerController).new()
var stubbed_player_name = "StubbedPlayerName" stub(player_controller_double, "player_name").to_return(stubbed_player_name) assert_eq(player_controller_double.player_name, stubbed_player_name)since I'm forced to change PlayerController to be:
class_name PlayerController extends Reference var _player_name : String func _init(): self._player_name = "" func request_play(): pass func get_player_name(): -> String return self._player_name
and stub get_player_name.
Thanks in advance! Love your work!
— Reply to this email directly, view it on GitHub https://github.com/bitwes/Gut/issues/373, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI2LKANNEMM4UL42PESNELVVMFYLANCNFSM54MZGEYA . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Oh god, how could I not see it? :')
I think this should be a nice addition to the stubs documentation, in case anyone in the future has my same doubt.
Thanks for the quick response!
There was a blurb about this on the doubles wiki page but it wasn't where you would expect it to be. I moved it up to the top.