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

Cannot use reset to reset several mocks of different types #103

Closed
rbeeger opened this issue Feb 20, 2017 · 2 comments
Closed

Cannot use reset to reset several mocks of different types #103

rbeeger opened this issue Feb 20, 2017 · 2 comments

Comments

@rbeeger
Copy link

rbeeger commented Feb 20, 2017

public func reset<M : Mock>(_ mocks: M...)

can be called with more than one mock, but that's more confusing than useful, because the following will not work:

reset(typeAMock, typeBMock)

The compiler will complain that typeBMock is not of the same type as typeAMock. The problem here is that M is bound to the type of the first parameter.

I don't see how this could be fixed with varargs as there is no common supertype that can be used here. So probably providing different versions with fixed parameter counts would be a useful workaround here

public func <M1: Mock>reset(_ mock1: M1)
public func <M1: Mock, M2: Mock>reset(_ mock1: M1, _ mock2: M2)
@TadeasKriz
Copy link
Member

I'll add one more protocol that will look like this:

protocol HasMockManager {
    var manager: MockManager { get }
}

and the Mock protocol will be inheriting from this new one. Then the HasMockManager protocol won't have any associatedtype and will be possible to use for the reset function like so: func reset(_ mocks: HasMockManager...)

@TadeasKriz
Copy link
Member

Fixed in master. Will be part of 0.9.2 released later today.

arnlen pushed a commit to arnlen/Cuckoo that referenced this issue May 4, 2017
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

No branches or pull requests

2 participants