From 517b5ceac32645d230f7f7fa15756b7d15f96064 Mon Sep 17 00:00:00 2001 From: Sam Coward Date: Fri, 8 May 2015 12:54:44 -0400 Subject: [PATCH] Include types with HaveReceived failure messages --- Source/Extensions/NSInvocation+Cedar.m | 4 +- Source/Headers/Doubles/HaveReceived.h | 10 ++- Spec/Doubles/HaveReceivedSpec.mm | 86 +++++++++++++------------- 3 files changed, 54 insertions(+), 46 deletions(-) diff --git a/Source/Extensions/NSInvocation+Cedar.m b/Source/Extensions/NSInvocation+Cedar.m index dcd3fd5d..e81128fb 100644 --- a/Source/Extensions/NSInvocation+Cedar.m +++ b/Source/Extensions/NSInvocation+Cedar.m @@ -83,7 +83,9 @@ - (NSArray *)arguments { [self getArgument:argBuffer atIndex:argIndex]; const char *argType = [methodSignature getArgumentTypeAtIndex:argIndex]; - [args addObject:[CDRTypeUtilities boxedObjectOfBytes:argBuffer ofObjCType:argType]]; + [args addObject:[NSString stringWithFormat:@"%@(%@)", + [CDRTypeUtilities boxedObjectOfBytes:argBuffer ofObjCType:argType], + [CDRTypeUtilities typeNameForEncoding:argType]]]; } return args; } diff --git a/Source/Headers/Doubles/HaveReceived.h b/Source/Headers/Doubles/HaveReceived.h index 8e6a7589..0944d5da 100644 --- a/Source/Headers/Doubles/HaveReceived.h +++ b/Source/Headers/Doubles/HaveReceived.h @@ -2,6 +2,7 @@ #import "InvocationMatcher.h" #import "CedarDouble.h" #import "NSInvocation+Cedar.h" +#import "CDRTypeUtilities.h" namespace Cedar { namespace Doubles { @@ -119,9 +120,14 @@ namespace Cedar { namespace Doubles { if (this->arguments().size()) { [message appendString:@", with arguments: <"]; arguments_vector_t::const_iterator cit = this->arguments().begin(); - [message appendString:(*cit++)->value_string()]; + [message appendString:[NSString stringWithFormat:@"%@(%@)", + (*cit)->value_string(), + [CDRTypeUtilities typeNameForEncoding:(*cit)->value_encoding()]]]; + ++cit; for (; cit != this->arguments().end(); ++cit) { - [message appendString:[NSString stringWithFormat:@", %@", (*cit)->value_string()]]; + [message appendString:[NSString stringWithFormat:@", %@(%@)", + (*cit)->value_string(), + [CDRTypeUtilities typeNameForEncoding:(*cit)->value_encoding()]]]; } [message appendString:@">"]; NSArray *recordedInvocations = [(id)value sent_messages]; diff --git a/Spec/Doubles/HaveReceivedSpec.mm b/Spec/Doubles/HaveReceivedSpec.mm index 08f1c469..863b33ae 100644 --- a/Spec/Doubles/HaveReceivedSpec.mm +++ b/Spec/Doubles/HaveReceivedSpec.mm @@ -152,11 +152,11 @@ describe(@"negative match", ^{ it(@"should fail with a sensible failure message", ^{ - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not have received message <%@>, with arguments: <%d>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not have received message <%@>, with arguments: <%d(unsigned short)>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to_not(have_received(method).with(expectedParameter)); }); - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not have received message <%@>, with arguments: <%d>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not have received message <%@>, with arguments: <%d(unsigned short)>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to_not(have_received("incrementBy:").with(expectedParameter)); }); }); @@ -168,18 +168,18 @@ describe(@"positive match", ^{ it(@"should fail with a sensible failure message", ^{ - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%d> but received messages:\n" - @" incrementBy:<2>\n" + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%d(unsigned short)> but received messages:\n" + @" incrementBy:<2(unsigned long)>\n" @" value\n" - @" setValue:<2>\n", + @" setValue:<2(unsigned long)>\n", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to(have_received(method).with(expectedParameter)); }); - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%d> but received messages:\n" - @" incrementBy:<2>\n" + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%d(unsigned short)> but received messages:\n" + @" incrementBy:<2(unsigned long)>\n" @" value\n" - @" setValue:<2>\n", + @" setValue:<2(unsigned long)>\n", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to(have_received("incrementBy:").with(expectedParameter)); }); @@ -200,11 +200,11 @@ describe(@"positive match", ^{ it(@"should fail with a sensible failure message", ^{ - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%ld>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%ld(long)>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to(have_received(method).with(expectedParameter)); }); - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%ld>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%ld(long)>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to(have_received("incrementBy:").with(expectedParameter)); }); }); @@ -261,11 +261,11 @@ describe(@"negative match", ^{ it(@"should fail with a sensible failure message", ^{ - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not have received message <%@>, with arguments: <%@>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not have received message <%@>, with arguments: <%@(id)>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to_not(have_received(method).with(expectedParameter)); }); - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not have received message <%@>, with arguments: <%@>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not have received message <%@>, with arguments: <%@(id)>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to_not(have_received("incrementByNumber:").with(expectedParameter)); }); }); @@ -277,19 +277,19 @@ describe(@"positive match", ^{ it(@"should fail with a sensible failure message", ^{ - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@> but received messages:\n" - @" incrementByNumber:<%@>\n" + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@(id)> but received messages:\n" + @" incrementByNumber:<%@(id)>\n" @" value\n" - @" setValue:<3>\n", + @" setValue:<3(unsigned long)>\n", incrementer, NSStringFromSelector(method), expectedParameter, actualParameter], ^{ expect(incrementer).to(have_received(method).with(expectedParameter)); }); - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@> but received messages:\n" - @" incrementByNumber:<%@>\n" + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@(id)> but received messages:\n" + @" incrementByNumber:<%@(id)>\n" @" value\n" - @" setValue:<3>\n", + @" setValue:<3(unsigned long)>\n", incrementer, NSStringFromSelector(method), expectedParameter, actualParameter], ^{ expect(incrementer).to(have_received("incrementByNumber:").with(expectedParameter)); @@ -311,18 +311,18 @@ describe(@"positive match", ^{ it(@"should fail with a sensible failure message", ^{ - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@> but received messages:\n" - @" incrementByNumber:<3>\n" + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@(id)> but received messages:\n" + @" incrementByNumber:<3(id)>\n" @" value\n" - @" setValue:<3>\n", + @" setValue:<3(unsigned long)>\n", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to(have_received(method).with(expectedParameter)); }); - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@> but received messages:\n" - @" incrementByNumber:<3>\n" + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@(id)> but received messages:\n" + @" incrementByNumber:<3(id)>\n" @" value\n" - @" setValue:<3>\n", + @" setValue:<3(unsigned long)>\n", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to(have_received("incrementByNumber:").with(expectedParameter)); }); @@ -342,18 +342,18 @@ describe(@"positive match", ^{ it(@"should fail with a sensible failure message", ^{ - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@> but received messages:\n" - @" incrementByNumber:<3>\n" + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@(id)> but received messages:\n" + @" incrementByNumber:<3(id)>\n" @" value\n" - @" setValue:<3>\n", + @" setValue:<3(unsigned long)>\n", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to(have_received(method).with(expectedParameter)); }); - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@> but received messages:\n" - @" incrementByNumber:<3>\n" + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@(id)> but received messages:\n" + @" incrementByNumber:<3(id)>\n" @" value\n" - @" setValue:<3>\n", + @" setValue:<3(unsigned long)>\n", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to(have_received("incrementByNumber:").with(expectedParameter)); }); @@ -375,11 +375,11 @@ describe(@"positive match", ^{ it(@"should fail with a sensible failure message", ^{ - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@(id)>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to(have_received(method).with(expectedParameter)); }); - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%@(id)>", incrementer, NSStringFromSelector(method), expectedParameter], ^{ expect(incrementer).to(have_received("incrementByNumber:").with(expectedParameter)); }); }); @@ -425,11 +425,11 @@ describe(@"negative match", ^{ it(@"should fail with a sensible failure message", ^{ - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not have received message <%@>, with arguments: <%d, %@>", incrementer, NSStringFromSelector(method), expectedFirstParameter, expectedSecondParameter], ^{ + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not have received message <%@>, with arguments: <%d(int), %@(id)>", incrementer, NSStringFromSelector(method), expectedFirstParameter, expectedSecondParameter], ^{ expect(incrementer).to_not(have_received(method).with(expectedFirstParameter, expectedSecondParameter)); }); - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not have received message <%@>, with arguments: <%d, %@>", incrementer, NSStringFromSelector(method), expectedFirstParameter, expectedSecondParameter], ^{ + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not have received message <%@>, with arguments: <%d(int), %@(id)>", incrementer, NSStringFromSelector(method), expectedFirstParameter, expectedSecondParameter], ^{ expect(incrementer).to_not(have_received("incrementByABit:andABitMore:").with(expectedFirstParameter, expectedSecondParameter)); }); }); @@ -442,18 +442,18 @@ describe(@"positive match", ^{ it(@"should fail with a sensible failure message", ^{ - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%llu, %@> but received messages:\n" - @" incrementByABit:andABitMore:<83, 32>\n" + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%llu(unsigned long), %@(id)> but received messages:\n" + @" incrementByABit:andABitMore:<83(unsigned int), 32(id)>\n" @" value\n" - @" setValue:<115>\n", + @" setValue:<115(unsigned long)>\n", incrementer, NSStringFromSelector(method), expectedFirstParameter, expectedSecondParameter], ^{ expect(incrementer).to(have_received(method).with(expectedFirstParameter, expectedSecondParameter)); }); - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%llu, %@> but received messages:\n" - @" incrementByABit:andABitMore:<83, 32>\n" + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%llu(unsigned long), %@(id)> but received messages:\n" + @" incrementByABit:andABitMore:<83(unsigned int), 32(id)>\n" @" value\n" - @" setValue:<115>\n", + @" setValue:<115(unsigned long)>\n", incrementer, NSStringFromSelector(method), expectedFirstParameter, expectedSecondParameter], ^{ expect(incrementer).to(have_received("incrementByABit:andABitMore:").with(expectedFirstParameter, expectedSecondParameter)); }); @@ -478,10 +478,10 @@ describe(@"positive match", ^{ it(@"should fail with a sensible error message", ^{ - expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%d, 666> but received messages:\n" - @" incrementByABit:andABitMore:<83, %@>\n" + expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to have received message <%@>, with arguments: <%d(int), 666(id)> but received messages:\n" + @" incrementByABit:andABitMore:<83(unsigned int), %@(id)>\n" @" value\n" - @" setValue:<83>\n", + @" setValue:<83(unsigned long)>\n", incrementer, NSStringFromSelector(method), actualFirstParameter, @""], ^{ expect(incrementer).to(have_received("incrementByABit:andABitMore:").with(actualFirstParameter, expectedSecondParameter)); });