Skip to content

Instantly share code, notes, and snippets.

@subdigital
Created February 21, 2012 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save subdigital/1876932 to your computer and use it in GitHub Desktop.
Save subdigital/1876932 to your computer and use it in GitHub Desktop.
A test object factory potential implementation
// Given class Customer
//defining factories
[MFFactory defineFactoryForClass:[Customer class] withBlock:^(MFFactory *customer) {
[customer sequenceFor:@"name" do:^(int i) {
return @"Test Customer %d";
}];
customer.status = @"active";
[customer sequenceFor:@"email" do:^(int i) {
return @"customer-%d@example.com"
];
}];
//give me a customer
Customer *testCustomer = [MFFactory buildObjectOfClass:[Customer class]];
// or perhaps this, though you'd have to define it as a category method to suppress the warnings
Customer *testCustomer = [MFFactory customer];
//give me a customer with suspended status
Customer *suspendedCustomer = [MFFactory buioldObjectOfClass:[Customer class] withParams:@{@"status":@"suspended"}];
// Given Customers have orders
//defining factories
[MFFactory defineFactoryForClass:[Customer class] withBlock:^(MFFactory *customer) {
[customer sequenceFor:@"name" do:^(int i) {
return @"Test Customer %d";
}];
customer.status = @"active";
[customer associatedObjectsFor:@"orders" do:^{
return @[[MFFactory order], [MFFactory order]];
];
[customer sequenceFor:@"email" do:^(int i) {
return @"customer-%d@example.com"
];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment