Browse files

Kinda weird improvement of the reporting of unexpected requests. Retu…

…rn a 500 :S I'll think about this
  • Loading branch information...
1 parent 48123e2 commit 0864f96e3f49aab8b59fe6db385cb84e86aec2f9 @luisobo committed Aug 31, 2012
Showing with 7,602 additions and 1,485 deletions.
  1. +1 −10 Nocilla.xcworkspace/contents.xcworkspacedata
  2. +10 −7 Nocilla/Hooks/NSURLRequest/LSHTTPStubURLProtocol.m
  3. +2 −2 Podfile
  4. +7,571 −1,466 Pods/Pods.xcodeproj/project.pbxproj
  5. +12 −0 README.md
  6. +6 −0 TODO
View
11 Nocilla.xcworkspace/contents.xcworkspacedata
@@ -1,10 +1 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<Workspace
- version = "1.0">
- <FileRef
- location = "group:Pods/Pods.xcodeproj">
- </FileRef>
- <FileRef
- location = "group:Nocilla.xcodeproj">
- </FileRef>
-</Workspace>
+<?xml version='1.0' encoding='UTF-8'?><Workspace version='1.0'><FileRef location='group:Pods/Pods.xcodeproj'/><FileRef location='group:Nocilla.xcodeproj'/></Workspace>
View
17 Nocilla/Hooks/NSURLRequest/LSHTTPStubURLProtocol.m
@@ -37,18 +37,21 @@ - (void)startLoading {
}
}
- if (!stubbedRequest) {
- [NSException raise:LSUnexpectedRequest format:@"An unexcepted HTTP request was fired.\n\nUse this snippet to stub the request:\n%@\n", [request toNocillaDSL]];
- }
-
- NSHTTPURLResponse* urlResponse = [[NSHTTPURLResponse alloc] initWithURL:request.URL
+ NSHTTPURLResponse* urlResponse = nil;
+ NSData *body = nil;
+ if (stubbedRequest) {
+ urlResponse = [[NSHTTPURLResponse alloc] initWithURL:request.URL
statusCode:stubbedResponse.statusCode
headerFields:stubbedResponse.headers
requestTime:0];
-
+ body = stubbedResponse.body;
+ } else {
+ urlResponse = [[NSHTTPURLResponse alloc] initWithURL:request.URL statusCode:500 headerFields:@{ @"X-Nocilla" : @"Unexpected Request" } requestTime:0];
+ body = [[NSString stringWithFormat:@"An unexcepted HTTP request was fired.\n\nUse this snippet to stub the request:\n%@\n", [request toNocillaDSL]] dataUsingEncoding:NSUTF8StringEncoding];
+ }
[client URLProtocol:self didReceiveResponse:urlResponse
cacheStoragePolicy:NSURLCacheStorageNotAllowed];
- [client URLProtocol:self didLoadData:stubbedResponse.body];
+ [client URLProtocol:self didLoadData:body];
[client URLProtocolDidFinishLoading:self];
}
View
4 Podfile
@@ -1,8 +1,8 @@
platform :ios
-
+
pod 'MKNetworkKit', '~> 0.83'
target :NocillaTests, :exclusive => true do
- pod 'Kiwi', '~> 1.1.0'
pod 'AFNetworking', '~> 1.0RC1'
pod 'CocoaHTTPServer', '~> 2.2.1'
+ pod 'Kiwi', '~> 1.1.0'
end
View
9,037 Pods/Pods.xcodeproj/project.pbxproj
7,571 additions, 1,466 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
12 README.md
@@ -0,0 +1,12 @@
+# Nocilla
+## HTTP stubbing for iOS and OS X
+
+### Features
+* Stub HTTP and HTTPS requests in your unit tests.
+* Awesome DSL that will improve the readability and maintainability of your tests.
+* Tested.
+* Fast.
+
+### How to use it
+
+Let's say you are developing a HTTP-intensive app or framework for iOS or OS X. Let's also imaging that, as a good software developer, you are writing unit testing your code and you are using [Kiwi](http://github.com/allending/Kiwi)
View
6 TODO
@@ -0,0 +1,6 @@
+Unit tests for LSStubRequest#matchesRequest
+Better reporting upon unexpected request
+Add option to enable real HTTP requests
+Test with vanilla NSURLConnection
+Integration tests for MKNetworkKit (agains real HTTP and comparing)
+Unit tests the DSL

0 comments on commit 0864f96

Please sign in to comment.