Up and Running with Kiwi for Mac

shepting edited this page Jan 8, 2013 · 6 revisions

Using Kiwi for Mac OS X Development

To use Kiwi for the Mac, follow these basic steps.

Short Version

  1. Make a new project using Unit Tests & ARC
  2. Create/Add Kiwi to existing Podfile
  3. Run (in the terminal): pod install
  4. Edit test target (MacAppTests) build setting FRAMEWORK_SEARCH_PATHS to $(inherited)
  5. Remove tests, add spec, run tests (cmd + U)

Sample working project file: https://github.com/shepting/kiwi-mac-demo

Long Version

1. Create a New Project

First, create a new project in Xcode. In the sidebar on the left choose "Application" under the "Mac OS X" section.

There will be an action sheet drop-down with options. Ensure that you have the "Use Automatic Reference Counting" and "Include Unit Tests" boxes checked. You can see the options I chose in the screenshot.

2. Add Podfile

Create a file named Podfile. Update the target names to match those in your app (MacApp and MacAppTests will become something like RidgeRacer and RidgeRacerTests). Add whatever other pods you'd like to either target. If you don't yet have CocoaPods, follow the directions here: https://github.com/CocoaPods/CocoaPods

# Test podfile for Mac

platform :osx

target 'MacApp', :exclusive => true do
  pod 'JSONKit'
end

target 'MacAppTests', :exclusive => true do
	pod 'Kiwi'
	pod 'JSONKit'
end

In the terminal run:

$> pod install

3. Change FRAMEWORK_SEARCH_PATHS

Open the workspace file (MacApp.xcworkspace in this case), select the MacApp project (not Pods), select the MacAppTests target, then enter the FRAMEWORK_SEARCH_PATHS in the search field to narrow the options down to one. Lastly, double-click the field and change the value to $(inherited).

4. Remove Default Tests, Add Spec File

There will be two files (MacAppTests.h and MacAppTests.m) in the tests group (MacAppTests). You can delete these.

Add a new spec file (SHAppDelegateSpec.m) to this group.

#import "SHAppDelegate.h"
#import "Kiwi.h"

SPEC_BEGIN(SHAppDelegateSpec)

describe(@"SHAppDelegateSpec", ^{
    __block SHAppDelegate *dm;
    
    beforeEach(^{
        dm = [[SHAppDelegate alloc] init];
    });
    
    context(@"application:DidFinishLaunching:", ^{
        
        it(@"should call call", ^{
            [[dm should] receive:@selector(firstCall)];
            
            [dm applicationDidFinishLaunching:nil];
        });
        
        it(@"should call otherCall", ^{
            [[dm should] receive:@selector(otherCall)];
            
            [dm applicationDidFinishLaunching:nil];
        });
    });
});

SPEC_END

5. Test (cmd + U)

Press CMD + U to run the tests. They should both fail. Update your app delegate file with two dummy methods and have applicationDidFinishLaunching: call them and the tests should pass. Done!