Defactory 0.1

Defactory 0.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新版本2014年12月

Luis Solano 维护。



  • 作者:
  • Luis Solano

Objective-C 对象工厂,用于测试。

特性

  • 一次定义,到处构建。
  • 命名工厂。
  • 序列。
  • 关联。
  • 处理原始数据。
  • 工厂继承。
  • 已测试。

安装

作为一个 CocoaPod,只需将以下内容添加到您的 Podfile 中:

pod 'Defactory'

其他方法

  • 您应该能够将 Defactory 添加到您的源代码树中。如果您正在使用 git,考虑使用 git submodule

使用

考虑到以下 User 类:

LSUser

@interface LSUser : NSObject
@property (nonatomic, strong) NSString *username;
@property (nonatomic, strong) NSString *password;
@property (nonatomic, strong) NSString *state;
@property (nonatomic, assign) NSUInteger loginCount;
@property (nonatomic, assign) BOOL somethingBool;
@property (nonatomic, strong) NSString *email;
@property (nonatomic, strong) LSUser *dad;
@end
@implementation LSUser
@end

定义一个或多个工厂

FACTORIES(^{
    // Default factory
    [LSUser defineFactory:^(LSFactory *f) {
        f[@"username"] = @"foo"; // Set values.
        f[@"password"] = @"hunter2";

        // Define sequences.
        f[@"email"] = sequence(^(NSUInteger i) { return [NSString stringWithFormat:@"foo%d@example.com", i]; });
    }];

    // Other named factories with inheritance.
    [LSUser define:@"suspended" parent:@"LSUser" factory:^(LSFactory *f) {
        f[@"state"] = @"suspended";

        // User boxed primitives, Defactory will take care of the rest.
        f[@"loginCount"] = @2;
        f[@"somethingBool"] = @YES;
    }];

    [LSUser define:@"son" parent:@"LSUser" factory:^(LSFactory *f) {

        // Associations.
        f[@"dad"] = association([LSUser class]);
    }];
});

构建内容

// Build an object with the default factory and params
LSUser *user = [LSUser build];

// Build an object with the default factory overriding some params.
user = [LSUser buildWithParams:@{@"password": @"secret", @"state": @"active"}];

// Build an object with a named factory.
user = [LSUser build:@"suspended"];

// Build an object with a named factory overriding some params.
user = [LSUser build:@"suspended" params:@{@"loginCount": @4}];

贡献

  1. 分支
  2. 创建您的功能分支
  3. 提交您的更改
  4. 推送到分支
  5. 创建新的拉取请求