RKKiwiMatchers 0.20.0

RKKiwiMatchers 0.20.0

测试已测试
Lang语言 Obj-CObjective C
许可证 自定义
发布最后发布2014年12月

Blake Watters 维护。



  • Blake Watters

本项目提供了一组用于通过 Kiwi 行为驱动开发库测试 RestKit 框架的匹配器。

示例应用

示例目录中有可用的示例应用,可以帮助您参考配置和使用。

安装

推荐通过 Cocoapods 安装

# Link RestKit and testing support into Application Target
pod 'RestKit', '~> 0.20.0'
pod 'RestKit/Testing', '~> 0.20.0'

# Link Kiwi and the matchers into the Unit Test Bundle Target
target :test, :exclusive => true do
  pod 'RKKiwiMatchers'
  pod 'Kiwi', '~> 2.0.0'
end

否则,将 Code 目录中的所有文件添加到您的单元测试包目标中。

使用

#import <RestKit/RestKit.h>
#import <RestKit/CoreData.h>
#import <RestKit/Testing.h>
#import <RKKiwiMatchers/RKKiwiMatchers.h>

SPEC_BEGIN(GGMappingsSpec)

registerMatchers(@"RK");

context(@"when object mapping a GGAirline", ^{
    __block NSData *fixtureData;
    __block RKMappingTest *mappingTest;

    beforeEach(^{
        RKManagedObjectStore *managedObjectStore = [RKManagedObjectStore defaultStore];
        fixtureData = [RKTestFixture parsedObjectWithContentsOfFixture:@"Fixtures/airlines/1.json"];
        mappingTest = [RKMappingTest testForMapping:[mappings airlineResponseMapping] sourceObject:fixtureData destinationObject:nil];
        mappingTest.mappingOperationDataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext cache:nil];
        mappingTest.rootKeyPath = @"airline";
    });

    // Attributes
    specify(^{ [[mappingTest should] mapKeyPath:@"id" toKeyPath:@"airlineID" withValue:@1234]; });
    specify(^{ [[mappingTest should] mapKeyPath:@"code" toKeyPath:@"code" withValue:@"DL"]; });
    specify(^{ [[mappingTest should] mapKeyPath:@"name" toKeyPath:@"name" withValue:@"Delta Air Lines"]; });
    specify(^{ [[mappingTest should] mapKeyPath:@"favorite" toKeyPath:@"favorite" withValue:@NO]; });
    specify(^{ [[mappingTest should] mapKeyPath:@"created_at" toKeyPath:@"createdAt" withValue:RKDateFromString(@"2012-01-07T12:00:00Z")]; });

    // Relationships
    specify(^{ [[mappingTest should] mapKeyPath:@"terminals" toKeyPath:@"terminals" usingMapping:[mappings terminalResponseMapping]]; });

    // Connect to the Airports this Airline operates out of
    specify(^{
        NSManagedObject *managedObject = [RKTestFactory insertManagedObjectForEntityForName:@"Airport" inManagedObjectContext:nil withProperties:@{@"airportID" : @12345}];
        [managedObject.managedObjectContext saveToPersistentStore:nil];
        [[mappingTest should] connectRelationship:@"airports" usingAttributes:@{ @"airportIDs": @"airportID" } withValue:managedObject];
    });
});

许可证

RKKiwiMatchers 在 Apache2 许可证条款下提供。有关更多信息,请参阅 LICENSE 文件。

致谢

Blake Watters
@blakewatters