diff --git a/CHANGELOG.md b/CHANGELOG.md index ffd887a0..80ff9d8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ OCMockito now requires OCHamcrest v5.4.0 or higher. - Prevent argument captor from capturing values twice. - Prevent over-releasing mock object that is stubbed as return value for copy method. +- Fixed crash when comparing literals to mocked protocols. Version 3.0.2 diff --git a/Source/OCMockito/Mocking/MKTProtocolMock.m b/Source/OCMockito/Mocking/MKTProtocolMock.m index 91d0f49f..8204f883 100644 --- a/Source/OCMockito/Mocking/MKTProtocolMock.m +++ b/Source/OCMockito/Mocking/MKTProtocolMock.m @@ -53,4 +53,11 @@ - (BOOL)respondsToSelector:(SEL)aSelector return [self methodSignatureForSelector:aSelector] != nil; } +#pragma mark Support being called as isEqual: argument + +- (BOOL)isNSArray__ { return NO; } +- (BOOL)isNSDictionary__ { return NO; } +- (BOOL)isNSNumber__ { return NO; } +- (BOOL)isNSString__ { return NO; } + @end diff --git a/Source/Tests/MKTProtocolMockTests.m b/Source/Tests/MKTProtocolMockTests.m index e77f262e..99940d71 100644 --- a/Source/Tests/MKTProtocolMockTests.m +++ b/Source/Tests/MKTProtocolMockTests.m @@ -147,4 +147,32 @@ - (void)testShouldNotRespondToUnrelatedSelector XCTAssertFalse([mockImplementer respondsToSelector:@selector(objectAtIndex:)]); } +- (void)testArray_ShouldBeAbleToCompareToMock +{ + id obj = @[]; + + XCTAssertFalse([obj isEqual:mockImplementer]); +} + +- (void)testDictionary_ShouldBeAbleToCompareToMock +{ + id obj = @{}; + + XCTAssertFalse([obj isEqual:mockImplementer]); +} + +- (void)testNumber_ShouldBeAbleToCompareToMock +{ + id obj = @0; + + XCTAssertFalse([obj isEqual:mockImplementer]); +} + +- (void)testString_ShouldBeAbleToCompareToMock +{ + id obj = @""; + + XCTAssertFalse([obj isEqual:mockImplementer]); +} + @end