Skip to content

Instantly share code, notes, and snippets.

@tibr
Created March 8, 2012 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tibr/2001574 to your computer and use it in GitHub Desktop.
Save tibr/2001574 to your computer and use it in GitHub Desktop.
Stubbing alloc to return mocked object
it(@"should start the processing with the ids from the network response", ^{
// mock network request
[KWSpec canResponseJSON:@"ids"];
// execute code under test
[client syncMyStuff];
// create mock
id process = [ProcessingOperation mock];
// return mock by stubbing alloc
[[ProcessingOperation shouldEventually] receive:@selector(alloc) andReturn:process];
// setup expected arguments
NSArray *ids = [NSArray arrayWithObjects:
[NSNumber numberWithInteger:2],
[NSNumber numberWithInteger:3],
nil];
// verify initializer
[[process shouldEventually] receive:@selector(initWithIDs:) andReturn:nil withArguments:ids];
});
@tibr
Copy link
Author

tibr commented Mar 8, 2012

Testing Framework is Kiwi: https://github.com/allending/Kiwi
Network request mocking realized with ILCannedURLProtocol.h: https://github.com/InfiniteLoopDK/ILTesting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment