diff --git a/Source/OCMock/OCMockObject.m b/Source/OCMock/OCMockObject.m index d78cba44..ddeae300 100644 --- a/Source/OCMock/OCMockObject.m +++ b/Source/OCMock/OCMockObject.m @@ -246,8 +246,13 @@ - (id)verifyAtLocation:(OCMLocation *)location } else if([unsatisfiedExpectations count] > 0) { + NSMutableString *unsatisfiedExpectationList = [NSMutableString string]; + for(OCMInvocationExpectation *expectation in unsatisfiedExpectations) + { + [unsatisfiedExpectationList appendFormat:@"\n\t%@", [expectation description]]; + } NSString *description = [NSString stringWithFormat:@"%@: %@ expected methods were not invoked: %@", - [self description], @([unsatisfiedExpectations count]), [self _stubDescriptions:YES]]; + [self description], @([unsatisfiedExpectations count]), unsatisfiedExpectationList]; OCMReportFailure(location, description); } @@ -474,7 +479,7 @@ - (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation { [NSException raise:NSInternalInconsistencyException format:@"%@: unexpected method invoked: %@ %@", - [self description], [anInvocation invocationDescription], [self _stubDescriptions:NO]]; + [self description], [anInvocation invocationDescription], [self stubDescriptions]]; } } @@ -498,7 +503,7 @@ - (void)doesNotRecognizeSelector:(SEL)aSelector __unused #pragma mark Helper methods -- (NSString *)_stubDescriptions:(BOOL)onlyExpectations +- (NSString *)stubDescriptions { NSMutableString *outputString = [NSMutableString string]; NSArray *stubsCopy = nil; @@ -506,31 +511,18 @@ - (NSString *)_stubDescriptions:(BOOL)onlyExpectations { stubsCopy = [stubs copy]; } + NSArray *expectationsCopy = nil; + @synchronized(expectations) + { + expectationsCopy = [expectations copy]; + } for(OCMStubRecorder *stub in stubsCopy) { - BOOL expectationsContainStub = NO; - @synchronized(expectations) - { - expectationsContainStub = [expectations containsObject:stub]; - } - - NSString *prefix = @""; - - if(onlyExpectations) - { - if(expectationsContainStub == NO) - continue; - } - else - { - if(expectationsContainStub) - prefix = @"expected:\t"; - else - prefix = @"stubbed:\t"; - } + NSString *prefix = [expectationsCopy containsObject:stub] ? @"expected:\t" : @"stubbed:\t"; [outputString appendFormat:@"\n\t%@%@", prefix, [stub description]]; } [stubsCopy release]; + [expectationsCopy release]; return outputString; } diff --git a/Source/OCMockTests/OCMockObjectMacroTests.m b/Source/OCMockTests/OCMockObjectMacroTests.m index 5c885fdd..0a5a3357 100644 --- a/Source/OCMockTests/OCMockObjectMacroTests.m +++ b/Source/OCMockTests/OCMockObjectMacroTests.m @@ -152,7 +152,23 @@ - (void)testReportsVerifyFailureWithCorrectLocation OCMVerifyAll(mock); const char *expectedFile = __FILE__; int expectedLine = __LINE__; shouldCaptureFailure = NO; - XCTAssertNotNil(reportedDescription, @"Should have recorded a failure with description."); + XCTAssertEqualObjects(reportedDescription, @"OCClassMockObject(NSString): expected method was not invoked: lowercaseString"); + XCTAssertTrue([reportedFile hasSuffix:[NSString stringWithUTF8String:expectedFile]], @"Should have reported correct file."); + XCTAssertEqual(expectedLine, (int)reportedLine, @"Should have reported correct line"); +} + +- (void)testReportsVerifyFailuresWithCorrectLocation +{ + id mock = OCMClassMock([NSString class]); + + OCMExpect([mock lowercaseString]); + OCMExpect([mock uppercaseString]); + + shouldCaptureFailure = YES; + OCMVerifyAll(mock); const char *expectedFile = __FILE__; int expectedLine = __LINE__; + shouldCaptureFailure = NO; + + XCTAssertEqualObjects(reportedDescription, @"OCClassMockObject(NSString): 2 expected methods were not invoked: \n\tlowercaseString\n\tuppercaseString"); XCTAssertTrue([reportedFile hasSuffix:[NSString stringWithUTF8String:expectedFile]], @"Should have reported correct file."); XCTAssertEqual(expectedLine, (int)reportedLine, @"Should have reported correct line"); }