erikdoe / ocmock

Mock objects for Objective-C
http://ocmock.org
Apache License 2.0
2.16k stars 606 forks source link

Crash using Nimble 5.0.0 & OCMock 3.3.1 #319

Closed joeljfischer closed 7 years ago

joeljfischer commented 8 years ago

I'm seeing a crash when running tests using the Swift 3 version of Quick / Nimble that I was not seeing on the Swift 2.3 version.

The test code causing the error:

expect(testManager.delegate).to(equal(managerDelegateMock)); // TODO: Broken on OCMock 3.3.1 & Swift 3 Quick / Nimble

The location it's breaking

// Stringers.swift
public func stringify<T>(_ value: T?) -> String {
    if let unboxed = value {
        return stringify(unboxed)
    }
    return "nil"
}

with this error:

Could not cast value of type 'OCProtocolMockObject' (0x11db0e518) to 'Swift.CustomDebugStringConvertible' (0x11d9ab0e8).
joeljfischer commented 8 years ago

Also seeing this error elsewhere:

Could not cast value of type 'OCClassMockObject' (0x111f31518) to 'Swift.CustomDebugStringConvertible' (0x111e590e8).

for this code:

__block id fileManagerMock = OCMClassMock([SDLFileManager class]);
// ...
expect(testManager.fileManager).toNot(beNil());
erikdoe commented 7 years ago

It feels like there are a lot of moving parts and I'm not sure I fully understand yet what you're doing.

It's clear that you are using the Nimble framework. From looking at its page on Github it looks like it's written in Swift but can be used from Objective-C, right? Based on the code snippet in your second comment I assume your tests are written in Objective-C, right?

Now, it sounds like you've updated the version of Nimble and kept the same version of OCMock. After the update of Nimble, some of your tests are breaking with this error you mention. If I understand you correctly the error occurs in the function you included in the issue. Where exactly? What are the arguments?

Could you provide a small self-contained tests that always fails?

modocache commented 7 years ago

@joeljfischer I think this error should be fixed within Nimble itself. Could you close this issue and create one on the Nimble repository instead?

As the error message indicates, OCClassMockObject cannot be converted to Swift's CustomDebugStringConvertible protocol -- meaning, as far as I can tell, it doesn't implement -debugDescription. Nimble's stringify function attempts to handle cases in which the subject of an expectation doesn't conform to CustomDebugStringConvertible, so I'm not sure why it's failing here. But I think we can fix the problem in Nimble, rather than forcing OCMock code to change.

erikdoe commented 7 years ago

Closing due to inactivity. Hopefully this has been fixed by the Nimble team. @modocache?

modocache commented 7 years ago

Thanks, @erikdoe, I created an issue on the Nimble repository to track this.