Inherits from NSURLProtocol
Declared in UMKMockURLProtocol.h

Overview

UMKMockURLProtocol is the primary class in the URLMock framework. It has methods for enabling and disabling mock responses, adding and removing expected mock requests, and configuring the behavior of the framework.

Tasks

Other Methods

UMKHTTPConvenienceMethods Methods

Class Methods

canonicalURLForURL:

Returns the canonical version of the specified URL.

+ (NSURL *)canonicalURLForURL:(NSURL *)URL

Parameters

URL

The URL. May not be nil.

Return Value

The canonical version of the specified URL.

Declared In

UMKMockURLProtocol.h

disable

Disables mock responses by unregistering the mock protocol with the NSURL system.

+ (void)disable

Declared In

UMKMockURLProtocol.h

enable

Enables mock responses by registering the mock protocol with the NSURL system.

+ (void)enable

Declared In

UMKMockURLProtocol.h

expectMockHTTPGetRequestWithURL:responseError:

+ (UMKMockHTTPRequest *)expectMockHTTPGetRequestWithURL:(NSURL *)URL responseError:(NSError *)error
Discussion

There is no need to add the returned mock request to the list of expected mock requests, as this method adds it automatically.

Parameters

URL

The URL for the mock GET request. May not be nil.

error

The error that the mock responder responds with. May not be nil.

Return Value

The newly created mock HTTP GET request. Its responder is set to the new mock error responder.

Declared In

UMKMockURLProtocol+UMKHTTPConvenienceMethods.h

expectMockHTTPGetRequestWithURL:responseStatusCode:responseJSON:

+ (UMKMockHTTPRequest *)expectMockHTTPGetRequestWithURL:(NSURL *)URL responseStatusCode:(NSInteger)statusCode responseJSON:(id)responseJSON
Discussion

There is no need to add the returned mock request to the list of expected mock requests, as this method adds it automatically.

Parameters

URL

The URL for the mock GET request. May not be nil.

statusCode

The status code for the HTTP response.

responseJSON

A JSON object to use as the mock HTTP response body.

Return Value

The newly created mock HTTP GET request. Its responder is set to the new mock JSON body responder.

Declared In

UMKMockURLProtocol+UMKHTTPConvenienceMethods.h

expectMockHTTPPatchRequestWithURL:requestJSON:responseError:

+ (UMKMockHTTPRequest *)expectMockHTTPPatchRequestWithURL:(NSURL *)URL requestJSON:(id)requestJSON responseError:(NSError *)error
Discussion

There is no need to add the returned mock request to the list of expected mock requests, as this method adds it automatically.

Parameters

URL

The URL for the mock PATCH request. May not be nil.

requestJSON

A JSON object to use as the mock HTTP PATCH request body.

error

The error that the mock responder responds with. May not be nil.

Return Value

The newly created mock HTTP PATCH request. Its responder is set to the new mock error responder.

Declared In

UMKMockURLProtocol+UMKHTTPConvenienceMethods.h

expectMockHTTPPatchRequestWithURL:requestJSON:responseStatusCode:responseJSON:

+ (UMKMockHTTPRequest *)expectMockHTTPPatchRequestWithURL:(NSURL *)URL requestJSON:(id)requestJSON responseStatusCode:(NSInteger)statusCode responseJSON:(id)responseJSON
Discussion

There is no need to add the returned mock request to the list of expected mock requests, as this method adds it automatically.

Parameters

URL

The URL for the mock PATCH request. May not be nil.

requestJSON

A JSON object to use as the mock HTTP PATCH request body.

statusCode

The status code for the HTTP response.

responseJSON

A JSON object to use as the mock HTTP response body.

Return Value

The newly created mock HTTP PATCH request. Its responder is set to the new mock JSON body responder.

Declared In

UMKMockURLProtocol+UMKHTTPConvenienceMethods.h

expectMockHTTPPostRequestWithURL:requestJSON:responseError:

+ (UMKMockHTTPRequest *)expectMockHTTPPostRequestWithURL:(NSURL *)URL requestJSON:(id)requestJSON responseError:(NSError *)error
Discussion

There is no need to add the returned mock request to the list of expected mock requests, as this method adds it automatically.

Parameters

URL

The URL for the mock POST request. May not be nil.

requestJSON

A JSON object to use as the mock HTTP POST request body.

error

The error that the mock responder responds with. May not be nil.

Return Value

The newly created mock HTTP POST request. Its responder is set to the new mock error responder.

Declared In

UMKMockURLProtocol+UMKHTTPConvenienceMethods.h

expectMockHTTPPostRequestWithURL:requestJSON:responseStatusCode:responseJSON:

+ (UMKMockHTTPRequest *)expectMockHTTPPostRequestWithURL:(NSURL *)URL requestJSON:(id)requestJSON responseStatusCode:(NSInteger)statusCode responseJSON:(id)responseJSON
Discussion

There is no need to add the returned mock request to the list of expected mock requests, as this method adds it automatically.

Parameters

URL

The URL for the mock POST request. May not be nil.

requestJSON

A JSON object to use as the mock HTTP POST request body.

statusCode

The status code for the HTTP response.

responseJSON

A JSON object to use as the mock HTTP response body.

Return Value

The newly created mock HTTP POST request. Its responder is set to the new mock JSON body responder.

Declared In

UMKMockURLProtocol+UMKHTTPConvenienceMethods.h

expectMockHTTPPutRequestWithURL:requestJSON:responseError:

+ (UMKMockHTTPRequest *)expectMockHTTPPutRequestWithURL:(NSURL *)URL requestJSON:(id)requestJSON responseError:(NSError *)error
Discussion

There is no need to add the returned mock request to the list of expected mock requests, as this method adds it automatically.

Parameters

URL

The URL for the mock PUT request. May not be nil.

requestJSON

A JSON object to use as the mock HTTP PUT request body.

error

The error that the mock responder responds with. May not be nil.

Return Value

The newly created mock HTTP PUT request. Its responder is set to the new mock error responder.

Declared In

UMKMockURLProtocol+UMKHTTPConvenienceMethods.h

expectMockHTTPPutRequestWithURL:requestJSON:responseStatusCode:responseJSON:

+ (UMKMockHTTPRequest *)expectMockHTTPPutRequestWithURL:(NSURL *)URL requestJSON:(id)requestJSON responseStatusCode:(NSInteger)statusCode responseJSON:(id)responseJSON
Discussion

There is no need to add the returned mock request to the list of expected mock requests, as this method adds it automatically.

Parameters

URL

The URL for the mock PUT request. May not be nil.

requestJSON

A JSON object to use as the mock HTTP PUT request body.

statusCode

The status code for the HTTP response.

responseJSON

A JSON object to use as the mock HTTP response body.

Return Value

The newly created mock HTTP PUT request. Its responder is set to the new mock JSON body responder.

Declared In

UMKMockURLProtocol+UMKHTTPConvenienceMethods.h

expectMockHTTPRequestWithMethod:URL:requestJSON:responseError:

+ (UMKMockHTTPRequest *)expectMockHTTPRequestWithMethod:(NSString *)method URL:(NSURL *)URL requestJSON:(id)requestJSON responseError:(NSError *)error
Discussion

There is no need to add the returned mock request to the list of expected mock requests, as this method adds it automatically.

Parameters

method

The HTTP method for the mock HTTP request. May not be nil.

URL

The URL for the mock HTTP request. May not be nil.

requestJSON

A JSON object to use as the mock HTTP request body.

error

The error that the mock responder responds with. May not be nil.

Return Value

The newly created mock HTTP request. Its responder is set to the new mock error responder.

Declared In

UMKMockURLProtocol+UMKHTTPConvenienceMethods.h

expectMockHTTPRequestWithMethod:URL:requestJSON:responseStatusCode:responseJSON:

+ (UMKMockHTTPRequest *)expectMockHTTPRequestWithMethod:(NSString *)method URL:(NSURL *)URL requestJSON:(id)requestJSON responseStatusCode:(NSInteger)statusCode responseJSON:(id)responseJSON
Discussion

There is no need to add the returned mock request to the list of expected mock requests, as this method adds it automatically.

Parameters

method

The HTTP method for the mock HTTP request. May not be nil.

URL

The URL for the mock HTTP request. May not be nil.

requestJSON

A JSON object to use as the mock HTTP request body.

statusCode

The status code for the HTTP response.

responseJSON

A JSON object to use as the mock HTTP response body.

Return Value

The newly created mock HTTP request. Its responder is set to the new mock JSON body responder.

Declared In

UMKMockURLProtocol+UMKHTTPConvenienceMethods.h

expectMockRequest:

+ (void)expectMockRequest:(id<UMKMockURLRequest>)request
Discussion

This is how mock requests are registered with the mock protocol.

Parameters

request

The mock request to expect. May not be nil.

Declared In

UMKMockURLProtocol.h

expectedMockRequests

Returns all expected mock requests.

+ (NSArray *)expectedMockRequests

Return Value

An array of all mock requests that are currently expected.

Declared In

UMKMockURLProtocol.h

isVerificationEnabled

+ (BOOL)isVerificationEnabled
Discussion

Set to NO by default. See setVerificationEnabled: for more information on what enabling verification means.

Return Value

Whether verification is enabled.

Declared In

UMKMockURLProtocol.h

removeExpectedMockRequest:

+ (void)removeExpectedMockRequest:(id<UMKMockURLRequest>)request
Discussion

This is how mock requests are unregistered from the mock protocol.

Parameters

request

The mock request to expect.

Declared In

UMKMockURLProtocol.h

reset

+ (void)reset
Discussion

Due to the asynchronous nature of URL loading, care should be taken to ensure that there are no connections in progress when this method is invoked. Failure to do so could result in unexpected results, particularly if verification is enabled.

Declared In

UMKMockURLProtocol.h

servicedRequests

+ (NSDictionary *)servicedRequests
Discussion

The keys in this dictionary are the actual requests that were serviced; the keys are the mock requests that serviced them.

Return Value

A dictionary of requests serviced since the receiver last received the reset message.

Declared In

UMKMockURLProtocol.h

setVerificationEnabled:

+ (void)setVerificationEnabled:(BOOL)enabled
Discussion

By default, verification is disabled. When enabled, the behavior of UMKMockURLProtocol changes to facilitate verifying expected behavior. In particular, mock requests are automatically removed from the set of expected requests when they are serviced, and unexpected requests receive error responses detailing that they were unexpected. Unexpected requests are accessible using unexpectedRequests.

 When verification is enabled, verifyWithError: may be used to determine if things are behaving as expected.

Parameters

enabled

Whether to enable verification or not.

Declared In

UMKMockURLProtocol.h

unexpectedRequests

Returns an array of unexpected requests received since the last reset.

+ (NSArray *)unexpectedRequests

Return Value

An array of unexpected requests received since the receiver last received the reset message.

Declared In

UMKMockURLProtocol.h

verifyWithError:

+ (BOOL)verifyWithError:(NSError **)outError
Discussion

Returns YES if and only if all expected requests have been serviced and no unexpected requests have been received since the last reset. Note: this method may only be used when verification is enabled. Invoking it otherwise will raise an exception.

Parameters

outError

If an error occurs, upon return contains an NSError object that describes the problem. If verification fails because unexpected requests were received, those requests are accessible in the error object’s userInfo dictionary via the kUMKUnexpectedRequestsKey key. If there were any unserviced mock requests, they are accessible via the kUMKUnservicedMockRequestsKey key. @throws NSInternalInconsistencyException if verification is not enabled.

Return Value

Whether verification succeeded.

Declared In

UMKMockURLProtocol.h