cmf

CMFactory

Fixture loader and FactoryGirl clone for iOS

Showing:

Popularity

Downloads/wk

0

GitHub Stars

44

Maintenance

Last Commit

6yrs ago

Contributors

3

Package

Dependencies

1

License

MIT

Categories

Readme

CMFactory

This project brings the idea of FactoryGirl to iOS projects, and it loads fixtures and unmarshall them into a Mantle class or NSDictionary class.

##Contact:

Developed by Lucas Medeiros at Codeminer42 in Fortaleza

Follow us on twitter: @Codeminer42

Development requirements

Install cocoapods

To install cocoapods you will need ruby.

gem install cocoapods

More information about cocoapods:

CocoaPods

Add the dependency to your Podfile:

platform :ios

...

target :WhateverExampleTests, :exclusive => true do
  pod 'CMFactory'
  ...
end

Run pod install to install the dependencies.

Usage

  • Loading fixtures
#import "CMFixture.h"
#import "Kiwi.h"

SPEC_BEGIN(YourSpec)
    
    //If you use github's Mantle library                    
    beforeEach(^{
         YourClass *yourInstance = [CMFactory buildUsingMantleClass:[YourClass class] fromFixture:@"YourClass"];
         //Or
         NSArray *aColletion = [CMFactory buildUsingMantleClass:[YourClass class] fromFixture:@"People"];
    });
    
    //If you don't use github's Mantle library
    beforeEach(^{
         NSDictionary *dictionary = [CMFactory buildUsingFixture:@"YourClass"];
         //Or
         NSArray *aColletion = [CMFactory buildUsingFixture:@"People"];
    });

SPEC_END

After that, in your test project, you need to create a file with your factory name in .json or .plist format (Ex: if your factory name is 'People' and you have a file people.json and other people.plist it will unmarshall the .json file)

  • Creating instances dynamically
#import "CMFactory.h"
#import "Kiwi.h"

SPEC_BEGIN(YourSpec)
    
    specify(^{

        CMFactory *factory = [CMFactory forClass:[YourClass class]];

        [factory addToField:@"aFieldName" value:^{
             return @"www.codeminer42.com";
        }];
    
        YourClass *instance = [factory build];
        [[instance.aFieldName should] equal: @"www.codeminer42.com"];

    });
    
    context(@"when using sequence method", ^{

         __block CMFactory *factory;
         __block NSArray *images;

         beforeEach(^{
              factory = [CMFactory forClass:[CMImage class]];
              [factory addToField:@"url" sequenceValue:^(NSUInteger sequence) {
                  return [NSString stringWithFormat:@"www.github.com%d", sequence];
              }];
              images = [factory buildWithCapacity:3];
         });

         specify(^{
              [[images should] haveCountOf:3];
         });

         specify(^{

             for(NSUInteger i = 0; i < 3; i++) {
                 CMImage *image = [images objectAtIndex:i];
                  [[image.url should] equal:[NSString stringWithFormat:@"www.github.com%d", i]];
             }

         });

    });

SPEC_END

  • See the example code

Requirements

CMFactory requires iOS 5.x or greater.

Next version

Integration with core data to use 'create' like methods

License

Usage is provided under the MIT License. See LICENSE for the full details.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100