Skip to content

Instantly share code, notes, and snippets.

@orta orta/Mocta.md
Last active Aug 29, 2015

Embed
What would you like to do?
Mocks & Stubs in a Specta / Expecta world

Getting a Mocta object

NSUserDefaults<Mocta> *defaults = [Mocta objectWithClass:[NSUserDefaults class]];
id< UITableViewDelegate, MoctaStub> delegate = [Mocta objectWithProtocol:@protocol(UITableViewDelegate)];

Expectations

Expectations are ran on dealloc, or at the end of the test case, so I don't have to do it manually.

object.expect( @selector(method:) )
object.expect( @selector(method:) ).matching(BOOL ^(id self, id argument) { return [argument isEqualToNumber:@YES]; } )

object.reject( @selector(method:) )

Stubbing

object.stub(@selector(method:)).with( ^(id self, id argument) { return @YES } );
object.stub(@selector(method:)).with( ^(id self, id argument) { return @"string" } );
object.stub(@selector(method:)).returning(@YES);

object.stub(@selector(method:)).callOriginal().replaceWith( ^{ return @(YES)} );

Class stubbing

MyClass.class.stub(@selector(method:))
MyClass.class.anyInstance().stubs(@selector(foo:)).return(@YES);
@premedios

This comment has been minimized.

Copy link

commented Oct 6, 2014

What's mocta?

@orta

This comment has been minimized.

Copy link
Owner Author

commented Feb 10, 2015

an imaginary Mocking library that's meant to feel like Specta/Expecta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.