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].
The instance’s URL pattern.property
The HTTP methods that the instance matches.property
The instance’s responder generation block.property
The instance’s request-matching block.property
Initializes a newly allocated instance with the specified URL pattern and responder generation block.
@property (nonatomic, copy) NSSet *HTTPMethods
If nil, the instance does not check a request’s HTTP method when matching.
@property (nonatomic, copy, readonly) NSString *URLPattern
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.
@property (nonatomic, copy) UMKParameterizedRequestMatchingBlock requestMatchingBlock
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.
@property (nonatomic, copy) UMKParameterizedResponderGenerationBlock responderGenerationBlock
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:.
- (instancetype)initWithURLPattern:(NSString *)URLPattern
This is the class’s designated initializer.
The URL pattern for the new instance. May not be nil.
An initialized pattern-matching mock request instance.