launch simple HTTPServer on testcodes.
Objective-C Ruby
Pull request Compare This branch is 52 commits behind yaakaito:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
NLTHTTPStubServer.xcodeproj
NLTHTTPStubServer.xcworkspace
NLTHTTPStubServer
NLTHTTPStubServerTests
.gitignore
CHANGELOG.md
LICENSE
NLTHTTPStubServer.podspec
Podfile
README.md

README.md

NLTHTTPStubServer

NLTHTTPStubServer is mocking server. launch simple HTTPServer on testcodes.

How to install

CocoaPods

Usage

GHUnit and AFNetworking example

@implementation NLTHTTPStubServerWithAFNetwrokingTest

- (void)setUpClass {
    [NLTHTTPStubServer globalSettings].port = 12345;
    server = [[NLTHTTPStubServer stubServer] retain];
    [server startServer];
}

- (void)tearDownClass {
    
    [server stopServer];
    [server release];
}

- (void)setUp {
    [server clear];
}

- (void)tearDown {
    if(![server isStubEmpty]) {
        GHFail(@"stubs not empty");
    }
}

- (void)testJSONResponse {
    
    [[[server stub] forPath:@"/index.json"] andJSONResponseResource:@"test" ofType:@"json"]; // create stub response
    
    [self prepare];
    NSURL *url = [NSURL URLWithString:@"http://localhost:12345/index.json"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        GHAssertEqualStrings(@"ok", [JSON objectForKey:@"status"], @"status = ok");
        GHAssertEqualStrings(@"json", [JSON objectForKey:@"format"], @"format = json");
        [self notify:kGHUnitWaitStatusSuccess];
    } failure:nil];
    [operation start];
    [self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0f];
    
}
@end

setup server

[NLTHTTPStubServer globalSettings].port = 12345;
server = [[NLTHTTPStubServer stubServer] retain];
[server startServer];

stop server

[server stopServer];
[server release];

create simple response

[[[server stub] forPath:@"/api.json"] andJSONResponse:json];

support content-types

  • JSON
  • HTML
  • XML
  • Plain Text
  • Binary
    • application/octet-stream

set status code

[[[server stub] forPath:@"/api.json"] andStatusCode:200];

simulate timeout

[[[server stub] forPath:@"/api.json"] andTimeout];

check query

[[[server stub] forPath:@"api.json"] andCheckURI:^(NSURL *URI) {
    // check URI
}];