From d05e065cb9e2a820f2f03b5e45fb2bebb57276cf Mon Sep 17 00:00:00 2001 From: Dave MacLachlan Date: Sat, 6 Jun 2020 11:53:38 -0700 Subject: [PATCH] Add basic descriptions for invocation actions. Helps in debugging and error reporting. --- Source/OCMock/OCMBlockCaller.m | 5 +++++ Source/OCMock/OCMExceptionReturnValueProvider.m | 5 +++++ Source/OCMock/OCMIndirectReturnValueProvider.m | 5 +++++ Source/OCMock/OCMNonRetainingObjectReturnValueProvider.m | 5 +++++ Source/OCMock/OCMNotificationPoster.m | 4 ++++ Source/OCMock/OCMRealObjectForwarder.m | 4 ++++ 6 files changed, 28 insertions(+) diff --git a/Source/OCMock/OCMBlockCaller.m b/Source/OCMock/OCMBlockCaller.m index f8e4def0..4a2fbaf1 100644 --- a/Source/OCMock/OCMBlockCaller.m +++ b/Source/OCMock/OCMBlockCaller.m @@ -43,4 +43,9 @@ - (void)handleInvocation:(NSInvocation *)anInvocation } } +- (NSString *)description +{ + return [NSString stringWithFormat:@"[%@ - %p]: Calls `%@`", [self class], self, block]; +} + @end diff --git a/Source/OCMock/OCMExceptionReturnValueProvider.m b/Source/OCMock/OCMExceptionReturnValueProvider.m index d63cd285..bd1e4add 100644 --- a/Source/OCMock/OCMExceptionReturnValueProvider.m +++ b/Source/OCMock/OCMExceptionReturnValueProvider.m @@ -27,4 +27,9 @@ - (void)handleInvocation:(NSInvocation *)anInvocation [[NSException exceptionWithName:OCMStubbedException reason:@"Exception stubbed in test." userInfo:@{ @"exception": returnValue }] raise]; } +- (NSString *)description +{ + return [NSString stringWithFormat:@"[%@ - %p]: Throws `%@`", [self class], self, returnValue]; +} + @end diff --git a/Source/OCMock/OCMIndirectReturnValueProvider.m b/Source/OCMock/OCMIndirectReturnValueProvider.m index a74e7294..f9cee094 100644 --- a/Source/OCMock/OCMIndirectReturnValueProvider.m +++ b/Source/OCMock/OCMIndirectReturnValueProvider.m @@ -49,4 +49,9 @@ - (void)handleInvocation:(NSInvocation *)anInvocation [anInvocation setSelector:originalSelector]; } +- (NSString *)description +{ + return [NSString stringWithFormat:@"[%@ - %p]: Calls `%@` on `%@`", [self class], self, NSStringFromSelector(selector), provider]; +} + @end diff --git a/Source/OCMock/OCMNonRetainingObjectReturnValueProvider.m b/Source/OCMock/OCMNonRetainingObjectReturnValueProvider.m index ee694f15..448f5527 100644 --- a/Source/OCMock/OCMNonRetainingObjectReturnValueProvider.m +++ b/Source/OCMock/OCMNonRetainingObjectReturnValueProvider.m @@ -36,5 +36,10 @@ - (void)handleInvocation:(NSInvocation *)anInvocation } [anInvocation setReturnValue:&returnValue]; } + +- (NSString *)description +{ + return [NSString stringWithFormat:@"[%@ - %p]: Returns `%@`", [self class], self, returnValue]; +} @end diff --git a/Source/OCMock/OCMNotificationPoster.m b/Source/OCMock/OCMNotificationPoster.m index 766476f3..0d6d690e 100644 --- a/Source/OCMock/OCMNotificationPoster.m +++ b/Source/OCMock/OCMNotificationPoster.m @@ -40,5 +40,9 @@ - (void)handleInvocation:(NSInvocation *)anInvocation [[NSNotificationCenter defaultCenter] postNotification:notification]; } +- (NSString *)description +{ + return [NSString stringWithFormat:@"[%@ - %p]: Posts `%@`", [self class], self, notification]; +} @end diff --git a/Source/OCMock/OCMRealObjectForwarder.m b/Source/OCMock/OCMRealObjectForwarder.m index c3606799..e7841d82 100644 --- a/Source/OCMock/OCMRealObjectForwarder.m +++ b/Source/OCMock/OCMRealObjectForwarder.m @@ -60,5 +60,9 @@ - (void)handleInvocation:(NSInvocation *)anInvocation } } +- (NSString *)description +{ + return [NSString stringWithFormat:@"[%@ - %p]", [self class], self]; +} @end