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

Stubbing inout parameter. #337

Open
kainosk opened this issue Mar 16, 2020 · 1 comment
Open

Stubbing inout parameter. #337

kainosk opened this issue Mar 16, 2020 · 1 comment
Labels

Comments

@kainosk
Copy link

kainosk commented Mar 16, 2020

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 😄 ❤️

@MatyasKriz MatyasKriz added the bug label Mar 20, 2020
@MatyasKriz
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants