Skip to content

Instantly share code, notes, and snippets.

@revelation
Created February 24, 2010 23:48
Show Gist options
  • Save revelation/314039 to your computer and use it in GitHub Desktop.
Save revelation/314039 to your computer and use it in GitHub Desktop.
- (void)testSetUserAsSuperuser
{
// set shared mock:
[GHTestCase setSharedMock:[OCMockObject niceMockForClass:[NSUserDefaults class]]];
// set expectations on shared mock:
[[[GHTestCase sharedMock] expect]
setBool:YES
forKey:[OCMArg checkWithSelector:@selector(isEqualToString:) onObject:@"superuser"]]];
// Swizzle in the mock
[self swizzle:[NSUserDefaults class] selector:@selector(standardUserDefaults)];
// run implementation
[viewController setUserAsSuperuser];
// verify shared mock
GHAssertNoThrow([[GHTestCase sharedMock] verify], @"ViewController did not set user as superuser.");
// DeSwizzle
[self deswizzle];
}
#pragma mark -
#pragma mark Swizzleable Methods
- (NSUserDefaults *)standardUserDefaults
{
return [GHTestCase sharedMock];
}
-(void) setUserAsSuperuser
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"superuser"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment