Created
July 20, 2011 09:37
-
-
Save whalec/1094667 to your computer and use it in GitHub Desktop.
Thoughts on how the API for class mocking in ObjectiveC should look
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I'd think that if NSString doesn't get sent stringWithFormat here before the end of this test, it should raise an error? It's mocking after all, not stubbing. | |
- (void)testClassMethodMocking { | |
[NSString mock:@selector(stringWithFormat:) andReturn:@"someString"]; | |
NSString *string = [NSString stringWithFormat@"abc123"]; | |
GHAssertEqual(string, @"someString", "NSString hasn't been mocked") | |
} | |
// This guy wouldn't raise. | |
- (void)testClassMethodStubbing { | |
[NSString stub:@selector(stringWithFormat:) andReturn:@"someString"]; | |
NSString *string = [NSString stringWithFormat@"abc123"]; | |
GHAssertEqual(string, @"someString", "NSString hasn't been mocked") | |
} | |
// Not too sure how to pass argument assertions though | |
- (void)testClassMethodMockingWithArguments { | |
NSDate *date = [NSDate date]; | |
[NSString mock:@selector(stringWithFormat) withArgs:date, nil andReturn:@"11-06-2011"]; | |
NSString *string = [NSString stringWithFormat:@"%@", date]; | |
GHAssertEqual(string, @"11-06-2011", "NSString hasn't been mocked"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment