diff --git a/OHHTTPStubs/OHHTTPStubs.h b/OHHTTPStubs/OHHTTPStubs.h index fd327447..eea05c0c 100644 --- a/OHHTTPStubs/OHHTTPStubs.h +++ b/OHHTTPStubs/OHHTTPStubs.h @@ -39,6 +39,9 @@ typedef id OHHTTPStubsRequestHandlerID; //////////////////////////////////////////////////////////////////////////////// #pragma mark - Interface +/*! @header OHHTTPStubs + Stubs Manager. Use this class to add and remove stubs and stub your network requests. + */ @interface OHHTTPStubs : NSObject //////////////////////////////////////////////////////////////////////////////// @@ -54,8 +57,8 @@ typedef id OHHTTPStubsRequestHandlerID; /*! Add a request handler to the stubs list @param handler The request handler block to add to the stubs list. This block takes as parameters: - * a NSURLRequest for which the stub is called, to determine the appropriate response to return - * a boolean as a parameter to tell if this block is only called for checking we want to stub or not (in this case, you should return quickly) + - a NSURLRequest for which the stub is called, to determine the appropriate response to return + - a boolean as a parameter to tell if this block is only called for checking we want to stub or not (in this case, you should return quickly) or for the actual stubbing (in this case you should return the actual OHHTTPStubsResponse to use) @return an opaque object that uniquely identifies the handler and can be later used to remove it with removeRequestHandler: @note This method is deprecated: use `shouldStubRequestsPassingTest:withStubResponse:` instead diff --git a/OHHTTPStubs/OHHTTPStubs.m b/OHHTTPStubs/OHHTTPStubs.m index e6cd1ef8..36dadc12 100644 --- a/OHHTTPStubs/OHHTTPStubs.m +++ b/OHHTTPStubs/OHHTTPStubs.m @@ -101,7 +101,7 @@ +(id)shouldStubRequestsPassingTest:(OHHTTPStubsTestBlock)shouldReturnStubForRequ BOOL shouldStub = shouldReturnStubForRequest ? shouldReturnStubForRequest(request) : YES; if (onlyCheck) { - return shouldStub ? OHHTTPStubsResponseUseStub : OHHTTPStubsResponseDontUseStub; + return shouldStub ? (OHHTTPStubsResponse*)@"DummyStub" : (OHHTTPStubsResponse*)nil; } else { diff --git a/OHHTTPStubs/OHHTTPStubsResponse.h b/OHHTTPStubs/OHHTTPStubsResponse.h index cf8c9ab9..7869b3a1 100644 --- a/OHHTTPStubs/OHHTTPStubsResponse.h +++ b/OHHTTPStubs/OHHTTPStubsResponse.h @@ -31,9 +31,6 @@ //////////////////////////////////////////////////////////////////////////////// #pragma mark - Defines & Constants -#define OHHTTPStubsResponseUseStub (OHHTTPStubsResponse*)@"DummyStub" -#define OHHTTPStubsResponseDontUseStub (OHHTTPStubsResponse*)nil - // Standard download speeds. extern const double OHHTTPStubsDownloadSpeedGPRS, @@ -46,6 +43,10 @@ OHHTTPStubsDownloadSpeedWifi; //////////////////////////////////////////////////////////////////////////////// #pragma mark - Interface +/*! @header + Stubs Response. This describes a stubbed response to be returned by the URL Loading System, including its + HTTP headers, body, statusCode and response time. + */ @interface OHHTTPStubsResponse : NSObject //////////////////////////////////////////////////////////////////////////////// @@ -67,7 +68,7 @@ OHHTTPStubsDownloadSpeedWifi; @param data The raw data to return in the response @param statusCode the HTTP Status Code to use in the response @param responseTime the time to wait before the response is sent (to simulate slow networks for example) - @param headers The HTTP Headers to return in the response + @param httpHeaders The HTTP Headers to return in the response @return an OHHTTPStubsResponse describing the corresponding response to return by the stub */ +(instancetype)responseWithData:(NSData*)data @@ -79,7 +80,7 @@ OHHTTPStubsDownloadSpeedWifi; @param fileName The file name and extension that contains the response body to return. The file must be in the application bundle @param statusCode the HTTP Status Code to use in the response @param responseTime the time to wait before the response is sent (to simulate slow networks for example) - @param headers The HTTP Headers to return in the response + @param httpHeaders The HTTP Headers to return in the response @return an OHHTTPStubsResponse describing the corresponding response to return by the stub */ +(instancetype)responseWithFile:(NSString*)fileName @@ -98,7 +99,7 @@ OHHTTPStubsDownloadSpeedWifi; contentType:(NSString*)contentType responseTime:(NSTimeInterval)responseTime; -/*! Builds a response given a message data as returned by `curl -is `, that is containing both the headers and the body. +/*! Builds a response given a message data as returned by `curl -is [url]`, that is containing both the headers and the body. This method will split the headers and the body and build a OHHTTPStubsReponse accordingly @param responseData the NSData containing the whole HTTP response, including the headers and the body @param responseTime the time to wait before the response is sent (to simulate slow networks for example) @@ -133,7 +134,7 @@ OHHTTPStubsDownloadSpeedWifi; @param data The raw data to return in the response @param statusCode the HTTP Status Code to use in the response @param responseTime the time to wait before the response is sent (to simulate slow networks for example) - @param headers The HTTP Headers to return in the response + @param httpHeaders The HTTP Headers to return in the response @return an OHHTTPStubsResponse describing the corresponding response to return by the stub */ -(instancetype)initWithData:(NSData*)data