Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created February 3, 2012 02:52
Show Gist options
  • Save burtlo/1727335 to your computer and use it in GitHub Desktop.
Save burtlo/1727335 to your computer and use it in GitHub Desktop.

Xcode Code Snippets

Installation

cd ~/Library/Developer/Xcode/UserData/CodeSnippets/
git init
git remote add burtlo [email protected]:burtlo/xcode-snippets.git
git pull burtlo master

###Expecta

Subject + Partial Mock Subject

subwithpartial
__block <#class#> *subject;
__block id partialSubject;

beforeEach(^{
    subject = [[<#class#> alloc] init];
    partialSubject = [OCMockObject partialMockForObject:subject];
    
    });

Stub and Return

stubandreturn
[[[<#instance#> stub] andReturn:<#data#>] <#method#>:[OCMArg any]];

Stub for Void

stub
[[<#instance#> stub] <#method#>];

Expect With Block

expectwithblock
[[<#subject#> expect] <#method#>:[OCMArg checkWithBlock:^BOOL(id value) {
    <#code#>
                return NO;
            }]];

Block Variable

block-var
__block <#class#> <#name#>;

###Cedar

Describe + It

descit
describe(@"<#subject#>", ^{
    it(@"should <#behavior#>", ^{
        expect(YES).toBeFalsy(); 
    });
});

It

itshould
it(@"should <#behavior#>", ^{
    expect(YES).toBeTruthy();
});

After Each

after
afterEach(^{
    <#code#> 
});

Before Each

before
beforeEach(^{
    <#code#>
});

###OCMock

Mock for Protocol

mockforprot
<#subject#> = [OCMockObject mockForProtocol:@protocol(<#protocol#>)];

Mock for Class

mockforclass
<#subject#> = [OCMockObject mockForClass:[<#class#> class]];

Expect for Void

expectvoid
[[[<#instance#> expect] <#method#>];

Expect and Return

expectandreturn
[[[<#instance#> expect] andReturn:<#data#>] <#method#>:[OCMArg any]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment