Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions Source/OCMock/OCMockObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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]];
}
}

Expand All @@ -498,39 +503,26 @@ - (void)doesNotRecognizeSelector:(SEL)aSelector __unused

#pragma mark Helper methods

- (NSString *)_stubDescriptions:(BOOL)onlyExpectations
- (NSString *)stubDescriptions
{
NSMutableString *outputString = [NSMutableString string];
NSArray *stubsCopy = nil;
@synchronized(stubs)
{
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;
}

Expand Down
18 changes: 17 additions & 1 deletion Source/OCMockTests/OCMockObjectMacroTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down