Brightify / Cuckoo

Boilerplate-free mocking framework for Swift!
MIT License
1.67k stars 175 forks source link

Can't call verifyNoMoreInteractions with more than one argument #384

Closed soucolline closed 3 years ago

soucolline commented 3 years ago

Hello,

I'm trying to add multiple arguments to a verifyNoMoreInteractions instead of calling them one by one on my mocks. The function signature indicates that it should be possible as it takes a variadic argument (like Mockito). However I have an error when doing so :

verifyNoMoreInteractions(mockLoginView, mockLoginUser)

-> Conflicting arguments to generic parameter 'M'

Is there a way to make it work this way ?

Cheers

MatyasKriz commented 3 years ago

Hey, @soucolline. It seems like verifyNoMoreInteractions has been implemented using a single generic parameter, I suppose to allow for multiple instances of the same type to be verified at once.

To verify instances of different classes at once, you have 2 options:

  1. Call verifyNoMoreInteractions for each type individually.

    verifyNoMoreInteractions(mockLoginView)
    verifyNoMoreInteractions(mockLoginUser)
  2. Define helper functions (this could also get included in Cuckoo)

    // For 2 different types:
    // For 3 types just add M3 and another parameter and `verifyNoMoreInteractions` method call in the function.
    // For 4 types M4 is needed and so on.
    func verifyNoMoreInteractions<M1: Mock, M2: Mock>(_ mock1: M1, _ mock2: M2, file: StaticString = #file, line: UInt = #line) {
    mock1.cuckoo_manager.verifyNoMoreInteractions((file, line))
    mock2.cuckoo_manager.verifyNoMoreInteractions((file, line))
    }
soucolline commented 3 years ago

Hi @MatyasKriz, thanks a lot for the tip, I've added the second option to our project and it's working perfectly fine (would be a great addition to the lib for sure !)