I'm digging myself into TDD and startet using SenTestingKit along with OCMock. I'm using FMDB as a wrapper for my SQLite Database.
I can't get my head around how to mock the DatabaseQueue
class, so it correctly invokes the invocation block with an FMDatabase
object.
Any ideas?
CustomerFactory.h
@interface CustomerFactory
// DatabaseQueue inherits from FMDatabaseQueue
@property (nonatomic, retain) DatabaseQueue *queue;
- (id)initWithDatabaseQueue:(DatabaseQueue *)queue;
@end
CustomerFactory.m
@implement CustomerFactory
- (id)initWithDatabaseQueue:(DatabaseQueue *)queue
{
if ((self = [super init]))
{
[self setQueue:queue];
}
}
- (NSArray *)customersByCategory:(NSUInteger)categoryId
{
__block NSMutableArray *temp = [[NSMutableArray alloc] init];
[self.queue inDatabase:^(FMDatabase *db)
{
FMResultSet *result = [db executeQuery:@"SELECT * FROM customers WHERE category_id = ?", categoryId];
while ([result next])
{
Customer *customer = [[Customer alloc] initWithDictionary:[result resultDictionary]];
[temp addObject:customer;
}
}];
return temp;
}
@end