Created
August 30, 2012 05:44
-
-
Save syshen/3522903 to your computer and use it in GitHub Desktop.
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
| -(void)setUp { | |
| asyncWaitUntil = [NSDate dateWithTimeIntervalSinceNow:5]; | |
| SRWebSocket *webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:@"ws://localhost"]]; | |
| mockSocket = [OCMockObject partialMockForObject:webSocket]; | |
| } | |
| -(void)testOpenConnectionSuccess { | |
| __block BOOL complete = NO; | |
| __weak WARemoteInterface *wRi = remoteInterface; | |
| [[[mockSocket stub] andDo:^(NSInvocation *invocation) { | |
| [wRi performSelector:@selector(webSocketDidOpen:) withObject:nil]; | |
| }] open]; | |
| [[[mockSocket stub] andDo:^(NSInvocation *invocation) { | |
| // Do nothing for now | |
| }] send:[OCMArg any]]; | |
| [remoteInterface replaceWebSocketConnection:(SRWebSocket*)mockSocket]; | |
| [[WARemoteInterface sharedInterface] | |
| openWebSocketConnectionForUrl:mockWebSocketServer | |
| onSucces:^{ | |
| // success | |
| complete = YES; | |
| } | |
| onFailure:^(NSError *error) { | |
| complete = YES; | |
| STFail(@"Websocket connection should be opened successfully."); | |
| }]; | |
| while (complete == NO && [asyncWaitUntil timeIntervalSinceNow] > 0) { | |
| [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:asyncWaitUntil]; | |
| } | |
| if (complete == NO) { | |
| STFail(@"Websocket connection should be opened on time."); | |
| } | |
| [mockSocket verify]; // All expected method should be called | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment