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

when().thenReturn() always return nil #367

Open
alopezh opened this issue Aug 21, 2020 · 3 comments
Open

when().thenReturn() always return nil #367

alopezh opened this issue Aug 21, 2020 · 3 comments
Labels
awaiting reply A Cuckoo maintainer is awaiting reply from the issue/PR creator. help wanted This issue is asking for a way to solve a problem.

Comments

@alopezh
Copy link

alopezh commented Aug 21, 2020

I'm trying to make getExpositionInfo() to return a value like this

        stub(expositionInfoRepository!) { stub in
            
            let expositionInfo = ExpositionInfo(level: .Healthy)
            when(stub.getExpositionInfo()).thenReturn(expositionInfo)
           
         }

When the call to the stubbed method is done inside the sut it returns nil

I've been debugging and when setting up the return value:

public extension StubFunctionThenReturnTrait {
    @discardableResult
    func thenReturn(_ output: OutputType, _ outputs: OutputType...) -> Self {
        ([output] + outputs).forEach { output in
            stub.appendAction(.returnValue(output))
        }
        return self
    }
}

output parameter is always nil, it look like it's overwrited somewhere.

Is there anything wrong with my code?

Regards

@MatyasKriz MatyasKriz added the help wanted This issue is asking for a way to solve a problem. label Aug 22, 2020
@MatyasKriz
Copy link
Collaborator

Hey @alopezh, could you please include the mocked type? I'll try to reproduce your issue, but if I fail, I will need you to either fork Cuckoo and add the test case that covers this issue or create a minimal project where this issue occurs.

@MatyasKriz MatyasKriz added the awaiting reply A Cuckoo maintainer is awaiting reply from the issue/PR creator. label Aug 22, 2020
@alopezh
Copy link
Author

alopezh commented Aug 26, 2020

Hi,

Te mocked type is a protocol:

protocol ExpositionInfoRepository {
    func getExpositionInfo() -> ExpositionInfo?
    func save(expositionInfo: ExpositionInfo)
    func clearData()
}

ExpositionInfo is the value that is always nil:

struct ExpositionInfo: Codable, Equatable {

    var level: Level
    var lastCheck: Date?
    var since: Date?
    var error: DomainError?

    public init(level: Level) {
        self.level = level
    }

    enum Level: String, Codable {
         case healthy
         case exposed
         case infected
    }

}

@alopezh
Copy link
Author

alopezh commented Sep 11, 2020

@MatyasKriz any hepl on this?

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reply A Cuckoo maintainer is awaiting reply from the issue/PR creator. help wanted This issue is asking for a way to solve a problem.
Projects
None yet
Development

No branches or pull requests

2 participants