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

Associatedtype not parsing to mock #1333

Closed
SeRG1k17 opened this issue May 17, 2024 · 1 comment · Fixed by #1345
Closed

Associatedtype not parsing to mock #1333

SeRG1k17 opened this issue May 17, 2024 · 1 comment · Fixed by #1345
Assignees
Milestone

Comments

@SeRG1k17
Copy link

SeRG1k17 commented May 17, 2024

//sourcery:AutoMockable
protocol TestProtocol {
    associatedtype Value

    func getValue() -> Value
}

Generated.swift:

class TestProtocolMock: TestProtocol {
    //MARK: - getValue

    var getValueIntCallsCount = 0
    var getValueIntCalled: Bool {
        return getValueIntCallsCount > 0
    }
    var getValueIntReturnValue: Value!
    var getValueIntClosure: (() -> Value)?

    func getValue() -> Value {
        getValueIntCallsCount += 1
        if let getValueIntClosure = getValueIntClosure {
            return getValueIntClosure()
        } else {
            return getValueIntReturnValue
        }
    }
}

Also this doesn't work for primary associatedType
Environment:

  • Sourcery - 2.2.4
  • templete - AutoMockable.stencil (default)
  • command: Pods/Sourcery/bin/sourcery --sources ./SourceryMocks/Test.swift --templates Pods/Sourcery/Templates/AutoMockable.stencil --output ./SourceryMocks
@art-divin art-divin modified the milestone: 2.2.5 Jun 5, 2024
@art-divin
Copy link
Collaborator

Hey @SeRG1k17 ,

thank you for reporting this issue!

Do you have a vision what would be the expected generated mock?
Would you consider adding generics to the generated definition which would define the associatedType protocol requirement as a solution to this problem?

Thank you 🙏🏻

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

Successfully merging a pull request may close this issue.

2 participants