Inherits from NSObject
Declared in RKTestHelpers.h

Overview

The RKTestHelpers class provides a number of helpful utility methods for use in unit or integration tests for RestKit applications.

Tasks

Stubbing Routes

Working with the Cache

  • + disableCaching

    Disables caching by setting a new [NSURLCache sharedURLCache] instance in which the memory and disk limits have been set to zero.

  • + cacheResponseForRequest:withResponseData:

    Creates, stores, and returns a NSCachedURLResponse object containing an NSHTTPURLResponse for the given request with a 200 (OK) status code.

  • + cacheResponseForURL:HTTPMethod:headers:withData:

    Creates, stores, and returns a NSCachedURLResponse object containing an NSHTTPURLResponse for the given URL and HTTP method with the given response data and a 200 (OK) status code.

Class Methods

cacheResponseForRequest:withResponseData:

+ (NSCachedURLResponse *)cacheResponseForRequest:(NSURLRequest *)request withResponseData:(NSData *)responseData
Discussion

Creates, stores, and returns a NSCachedURLResponse object containing an NSHTTPURLResponse for the given request with a 200 (OK) status code.

Parameters

request

The request to cache the response for.

responseData

The response data to be stored in the cache.

Return Value

The cached URL response that was stored to the cache.

Declared In

RKTestHelpers.h

cacheResponseForURL:HTTPMethod:headers:withData:

+ (NSCachedURLResponse *)cacheResponseForURL:(NSURL *)URL HTTPMethod:(NSString *)HTTPMethod headers:(NSDictionary *)requestHeaders withData:(NSData *)responseData
Discussion

Creates, stores, and returns a NSCachedURLResponse object containing an NSHTTPURLResponse for the given URL and HTTP method with the given response data and a 200 (OK) status code.

Parameters

URL

The URL to cache the response for.

HTTPMethod

The HTTP method of the request (i.e. ‘GET’, ‘POST’, ‘PUT’, ‘PATCH’, or ‘DELETE’).

responseData

The response data to be stored in the cache.

Return Value

The cached URL response that was stored to the cache.

Declared In

RKTestHelpers.h

copyFetchRequestBlocksMatchingPathPattern:toBlocksMatchingRelativeString:onObjectManager:

+ (void)copyFetchRequestBlocksMatchingPathPattern:(NSString *)pathPattern toBlocksMatchingRelativeString:(NSString *)relativeString onObjectManager:(RKObjectManager *)nilOrObjectManager
Discussion

Finds all registered fetch request blocks matching the given path pattern and adds a new fetch request block that returns the same value as the origin block that matches the given relative string portion of a URL object.

Parameters

pathPattern

The path pattern that matches the fetch request blocks to be copied.

relativeString

The relative string portion of the NSURL objects that the new blocks will match exactly.

nilOrObjectManager

The object manager to stub the route on. If nil, the shared object manager be be used.

Declared In

RKTestHelpers.h

disableCaching

+ (void)disableCaching
Discussion

Disables caching by setting a new [NSURLCache sharedURLCache] instance in which the memory and disk limits have been set to zero.

Declared In

RKTestHelpers.h

stubRouteForClass:method:withPathPattern:onObjectManager:

+ (RKRoute *)stubRouteForClass:(Class)objectClass method:(RKRequestMethod)method withPathPattern:(NSString *)pathPattern onObjectManager:(RKObjectManager *)nilOrObjectManager
Discussion

Stubs the route with the given class and method with a given path pattern.

Parameters

objectClass

The class of the route to stub.

method

The method of the route to stub.

pathPattern

The path pattern to return instead in place of the current route’s value.

nilOrObjectManager

The object manager to stub the route on. If nil, the shared object manager be be used.

Return Value

The new stubbed route object that was added to the route set of the target object manager.

Declared In

RKTestHelpers.h

stubRouteForRelationship:ofClass:method:pathPattern:onObjectManager:

+ (RKRoute *)stubRouteForRelationship:(NSString *)relationshipName ofClass:(Class)objectClass method:(RKRequestMethod)method pathPattern:(NSString *)pathPattern onObjectManager:(RKObjectManager *)nilOrObjectManager
Discussion

Stubs the relationship route for a given class with a given path pattern.

Parameters

relationshipName

The name of the relationship to stub the route of.

objectClass

The class of the route to stub.

pathPattern

The path pattern to return instead in place of the current route’s value.

nilOrObjectManager

The object manager to stub the route on. If nil, the shared object manager be be used.

Return Value

The new stubbed route object that was added to the route set of the target object manager.

Declared In

RKTestHelpers.h

stubRouteNamed:withPathPattern:onObjectManager:

+ (RKRoute *)stubRouteNamed:(NSString *)routeName withPathPattern:(NSString *)pathPattern onObjectManager:(RKObjectManager *)nilOrObjectManager
Discussion

Stubs the route with the given name with a given path pattern.

Parameters

routeName

The name of the route to stub.

pathPattern

The path pattern to return instead in place of the current route’s value.

nilOrObjectManager

The object manager to stub the route on. If nil, the shared object manager be be used.

Return Value

The new stubbed route object that was added to the route set of the target object manager.

Declared In

RKTestHelpers.h