I am trying to do TDD with XCode while building simple framework. I
have successfully setup my framework and test targets. Made test
target dependent on framework so that framework is built before
running the test suite. I have written failing test which expects NO
to be YES. It all works.
When I'm trying to test the actual code from my framework (framework
adds a couple of convenience methods to NSArray class' category) the
build results say that I have sent unrecognized selector to an NSArray
instance. Here is my code for framework and for test:
--- NSArray+Iterators.h
#import <Foundation/NSArray.h>
@interface NSArray (Iterators)
- (NSArray *)each:(void (^)(id obj))block;
@end
---
The implementation file looks like this:
--- NSArray+Iterators.m
#import "NSArray+Iterators.h"
@implementation NSArray (Iterators)
- (NSArray *)each:(void (^)(id obj))block
{
return self;
}
@end
----
Now the test file looks like this:
--- EachTests.m
#import "EachTests.h"
#import "WSEnumerable.h"
@implementation EachTests
- (void)testEachReturnValue
{
NSArray *newArray = [array each:(id)^(NSString *name) {
NSLog(@"%@", name);
}];
STAssertEqualObjects(array, newArray, @"Expected returned array to
be equal to iterated array.");
}
- (void)setUp
{
[self setArray:[NSArray arrayWithObjects:@"Melissa", @"Kasandra",
@"Bermudo", @"Asha", @"Lukoh", nil]];
}
---
The error itself looks like this:
---
otest-i386[3500:903] -[NSCFArray each:]: unrecognized selector sent to
instance 0x1437c0
---
Oddly enough - when I wrote the test, XCode's autocompletion did find
the method in question.
Any help is much appreciated
// E.
It sounds like the category isn't getting linked in to the test rig.
Try adding -all_load to the "Linker Flags" build setting for your unit
test target.
--
Justin Spahr-Summers
The category itself isn't loaded indeed. I have tried adding following
method to my category and I get no output whatsoever:
---
+ (void)load
{
NSLog(@"loaded %@", self);
}
---
Adding -all_load did not effect the build. I still get the same error.
My linker flags are these:
-framework Cocoa -framework SenTestingKit -all_load
My target structure is snapshot here:
http://walkingsmarts.com/wp-content/uploads/WSEnumerable.png