Cuckoo
Cuckoo copied to clipboard
Stubbing `inout` parameter.
I want to stub inout parameter. Like below.
// This is a protocol which uses `inout` parameter.
protocol InoutProtocol {
func doSomething(inoutValue: inout Int)
}
// In test code, I want to stub mock's behavior like below. But I got error.
let mock = MockInoutProtocol()
stub(mock) { mock in
when(mock.doSomething(inoutValue: any())).then { passedValue in
// I want to change passedValue as `inout` parameter. Like below.
passedValue = 999 // error: Cannot assign to value: 'passedValue' is a 'let' constant
print(passedValue)
}
}
Is there a workaround? Or, am I overlooking features? I attached project file to confirm this problem.
StubInout.zip
Thanks for great tool!! I love Cuckoo 😄 ❤️
Hey @kainosk, yeah, this is my oversight in the tests. It didn't occur to me when writing the inout test that I should try to mutate the value, I just tried printing it to verify that the mocks are properly generated.
I've skimmed over the codebase and at the moment I can't find a way to fix this with the way things work. I'll try to discuss this with more experienced programmers, but I don't want to get your hopes up.