Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed KWMessagePattern not matching class arguments. #517

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion Classes/Core/KWFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//

#import "KWFormatter.h"
#import <objc/runtime.h>

@implementation KWFormatter

Expand All @@ -18,7 +19,7 @@ + (NSString *)formatObject:(id)anObject {
else if ([anObject isKindOfClass:[NSDictionary class]])
return [anObject description]; // NSDictionary conforms to NSFastEnumeration

else if ([anObject conformsToProtocol:@protocol(NSFastEnumeration)])
else if ([anObject conformsToProtocol:@protocol(NSFastEnumeration)] && !class_isMetaClass(object_getClass(anObject)))
return [self formattedCollection:anObject];

return [anObject description];
Expand Down
4 changes: 2 additions & 2 deletions Kiwi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
9F982D9216A802920030A0B1 /* KWIntercept.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982C9316A802920030A0B1 /* KWIntercept.h */; };
9F982D9316A802920030A0B1 /* KWIntercept.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982C9316A802920030A0B1 /* KWIntercept.h */; };
9F982D9416A802920030A0B1 /* KWIntercept.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982C9416A802920030A0B1 /* KWIntercept.m */; };
9F982D9516A802920030A0B1 /* KWIntercept.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982C9416A802920030A0B1 /* KWIntercept.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
9F982D9516A802920030A0B1 /* KWIntercept.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982C9416A802920030A0B1 /* KWIntercept.m */; };
9F982D9616A802920030A0B1 /* KWInvocationCapturer.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982C9516A802920030A0B1 /* KWInvocationCapturer.h */; };
9F982D9716A802920030A0B1 /* KWInvocationCapturer.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982C9516A802920030A0B1 /* KWInvocationCapturer.h */; };
9F982D9816A802920030A0B1 /* KWInvocationCapturer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982C9616A802920030A0B1 /* KWInvocationCapturer.m */; settings = {COMPILER_FLAGS = ""; }; };
Expand Down Expand Up @@ -436,7 +436,7 @@
9F982DF216A802920030A0B1 /* KWStub.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982CC316A802920030A0B1 /* KWStub.h */; };
9F982DF316A802920030A0B1 /* KWStub.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982CC316A802920030A0B1 /* KWStub.h */; };
9F982DF416A802920030A0B1 /* KWStub.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982CC416A802920030A0B1 /* KWStub.m */; };
9F982DF516A802920030A0B1 /* KWStub.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982CC416A802920030A0B1 /* KWStub.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
9F982DF516A802920030A0B1 /* KWStub.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982CC416A802920030A0B1 /* KWStub.m */; };
9F982DFA16A802920030A0B1 /* KWUserDefinedMatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982CC716A802920030A0B1 /* KWUserDefinedMatcher.h */; };
9F982DFB16A802920030A0B1 /* KWUserDefinedMatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F982CC716A802920030A0B1 /* KWUserDefinedMatcher.h */; };
9F982DFC16A802920030A0B1 /* KWUserDefinedMatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F982CC816A802920030A0B1 /* KWUserDefinedMatcher.m */; settings = {COMPILER_FLAGS = ""; }; };
Expand Down
2 changes: 1 addition & 1 deletion NonARC/KWMessagePattern.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ + (id)messagePatternFromInvocation:(NSInvocation *)anInvocation {
void* argumentDataBuffer = malloc(KWObjCTypeLength(type));
[anInvocation getMessageArgument:argumentDataBuffer atIndex:i];
id object = nil;
if(*(id*)argumentDataBuffer != [KWAny any] && !KWObjCTypeIsObject(type)) {
if(*(id*)argumentDataBuffer != [KWAny any] && !KWObjCTypeIsObject(type) && !KWObjCTypeIsClass(type)) {
NSData *data = [anInvocation messageArgumentDataAtIndex:i];
object = [KWValue valueWithBytes:[data bytes] objCType:type];
} else {
Expand Down
8 changes: 8 additions & 0 deletions Tests/KWFormatterTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ - (void)testFormatsDictionariesWithKeysAndValuesMultiline {
STAssertEqualObjects([sampleDict description], [KWFormatter formatObject:sampleDict], @"Dictionaries should be not treated as NSEnumerable");
}

- (void)testClassObjects{
STAssertEqualObjects([KWFormatter formatObject:[NSNumber class]], @"NSNumber", @"Classes should get outputted with their name");
}

- (void)testTreatsNSEnumerableClassObjectAsClass{
STAssertNoThrow([KWFormatter formatObject:[NSArray class]], @"Enumerable classes should not be threated as their instances");
}

@end

#endif // #if KW_TESTS_ENABLED
12 changes: 12 additions & 0 deletions Tests/KWFunctionalTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,18 @@ @interface KWExampleSuiteBuilder ()

SPEC_END

SPEC_BEGIN(FunctionalMatchers)

describe(@"receive matcher",^{
it(@"Recognizes params with classes",^{
NSMutableArray *array = [NSMutableArray array];
[[[array should] receive] isKindOfClass:[NSArray class]];
[array isKindOfClass:[NSArray class]];
});
});

SPEC_END

#if KW_TESTS_ENABLED
@interface KWFunctionalTests : SenTestCase
@end
Expand Down