Inherits from NSObject
Conforms to UMKMockURLRequest
Declared in UMKPatternMatchingMockRequest.h

Overview

UMKPatternMatchingMockRequest are mock requests that match URL requests based on a URL pattern. Each pattern-matching mock request has an associated URL pattern and a responder generation block. The URL pattern is a SOCKit pattern, e.g., http://hostname.com/:directory/:subdirectory/:resource. When a URL request matches the receiver’s URL pattern, the receiver calls its responder generation block with the request and the URL pattern parameters parsed from the request’s URL. You can use this block to generate an appropriate responder based on the contents of the URL request.

In addition to the URL pattern, you can optionally provide a set of HTTP methods and a request-matching block to perform further tests on a request before matching it. See the documentation below for more details.

Note that due to the fact that a single pattern-matching mock request can match many actual requests, pattern-matching mock requests are not removed from UMKMockURLProtocol’s set of expected mock requests after they service a request. To remove a pattern-matching mock request, you can either remove the request manually using [UMKMockURLProtocol removeExpectedMockRequest:] or reset UMKMockURLProtocol entirely using [UMKMockURLProtocol reset].

Tasks

Properties

HTTPMethods

@property (nonatomic, copy) NSSet *HTTPMethods
Discussion

If nil, the instance does not check a request’s HTTP method when matching.

Declared In

UMKPatternMatchingMockRequest.h

URLPattern

@property (nonatomic, copy, readonly) NSString *URLPattern
Discussion

This pattern should be a valid SOCKit pattern. See the SOCKit documentation for more information.

 Note that only the part of the URL up to the query string is used to match the pattern. This simplifies issues
 related to query parameter ordering. If you need to examine the query parameters to determine whether to match a
 request, you can do so using a request-matching block.

Declared In

UMKPatternMatchingMockRequest.h

requestMatchingBlock

@property (nonatomic, copy) UMKParameterizedRequestMatchingBlock requestMatchingBlock
Discussion

By default, the instance will only determine whether a request matches using its URL pattern and HTTP methods. If you provide a request-matching block, it will be called afterwards so that you can perform additional tests on the URL request being matched. The return value of the block will determine if the instance matches the request or not.

 If a request has a non-nil HTTPBodyStream, your request matching block should not attempt to read it under any
 circumstances, even by using -umk_HTTPBodyData. Doing so will make the body unreadable on subsequent attempts,
 most notably by other potential mock requests or in the body of your responder generation block. This is due to
 the nature of data streams. If the request has a non-nil HTTPBody, you may freely read the body in your block.

Declared In

UMKPatternMatchingMockRequest.h

responderGenerationBlock

@property (nonatomic, copy) UMKParameterizedResponderGenerationBlock responderGenerationBlock
Discussion

This block generates a mock responder for a given URL request and URL pattern parameters. It may not return nil. The return value of this block is what is returned by -responderForURLRequest:.

Declared In

UMKPatternMatchingMockRequest.h

Instance Methods

initWithURLPattern:

- (instancetype)initWithURLPattern:(NSString *)URLPattern
Discussion

This is the class’s designated initializer.

Parameters

URLPattern

The URL pattern for the new instance. May not be nil.

Return Value

An initialized pattern-matching mock request instance.

Declared In

UMKPatternMatchingMockRequest.h