Inherits from NSObject
Conforms to RKOAuthClientDelegate
RKObjectLoaderDelegate
Declared in RKTestResponseLoader.h
RKTestResponseLoader.m

Overview

An RKTestResponseLoader object provides testing support for asynchronously loading an RKRequest or RKObjectLoader object while blocking the execution of the current thread by spinning the run loop. This enables a straight-forward unit testing workflow for asynchronous network operations.

RKTestResponseLoader instances are designed to act as as the delegate for an RKObjectLoader or RKRequest object under test. Once assigned as the delegate to a request and the request has been sent, waitForResponse: is invoked to block execution until the response is loaded.

Tasks

Other Methods

Successful responses

Properties

cancelled

A Boolean value that indicates whether the RKRequest or RKObjectLoader the receiver is acting as the delegate for was cancelled.

@property (nonatomic, readonly, getter=wasCancelled) BOOL cancelled

Return Value

YES if the request was cancelled

Declared In

RKTestResponseLoader.h

error

An NSError value that was loaded from the RKRequest or RKObjectLoader the receiver is acting as the delegate for.

@property (nonatomic, copy, readonly) NSError *error

Declared In

RKTestResponseLoader.h

objects

The collection of objects loaded from the RKObjectLoader the receiver is acting as the delegate for.

@property (nonatomic, retain, readonly) NSArray *objects

Declared In

RKTestResponseLoader.h

response

The RKResponse object loaded from the RKRequest or RKObjectLoader the receiver is acting as the delegate for. *

@property (nonatomic, retain, readonly) RKResponse *response

Declared In

RKTestResponseLoader.h

successful

A Boolean value that indicates whether a response was loaded successfully.

@property (nonatomic, readonly, getter=wasSuccessful) BOOL successful

Return Value

YES if a response was loaded successfully.

Declared In

RKTestResponseLoader.h

timeout

The timeout interval, in seconds, to wait for a response to load.

@property (nonatomic, assign) NSTimeInterval timeout

Discussion

The default value is 4 seconds.

Declared In

RKTestResponseLoader.h

unexpectedResponse

A Boolean value that indicates if an unexpected response was loaded.

@property (nonatomic, readonly, getter=loadedUnexpectedResponse) BOOL unexpectedResponse

Return Value

YES if the request loaded an unknown response.

Declared In

RKTestResponseLoader.h

Class Methods

responseLoader

Creates and returns a test response loader object.

+ (id)responseLoader

Return Value

A new response loader object.

Declared In

RKTestResponseLoader.h

Instance Methods

OAuthClient:didAcquireAccessToken:

Sent when a new access token has been acquired

- (void)OAuthClient:(RKOAuthClient *)client didAcquireAccessToken:(NSString *)token

Parameters

client

A reference to the RKOAuthClient that triggered the callback

token

A string of the access token acquired from the authentication server.

Declared In

RKOAuthClient.h

OAuthClient:didFailWithInvalidGrantError:

Sent when an access token request has failed due an invalid authorization code

- (void)OAuthClient:(RKOAuthClient *)client didFailWithInvalidGrantError:(NSError *)error

Parameters

client

A reference to the RKOAuthClient that triggered the callback

error

An NSError object containing the RKOAuthClientError that triggered the callback

Declared In

RKOAuthClient.h

errorMessage

Returns the localized description error message for the error.

- (NSString *)errorMessage

Return Value

The localized description of the error or nil.

Discussion

TODO: Why not just move this to NSError+RKAdditions?

Declared In

RKTestResponseLoader.h

objectLoader:didFailWithError:

Sent when an object loaded failed to load the collection due to an error

- (void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)theError

Declared In

RKObjectLoader.h

objectLoader:didLoadObjects:

When implemented, sent to the delegate when the object laoder has completed successfully and loaded a collection of objects. All objects mapped from the remote payload will be returned as a single array.

- (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)theObjects

Declared In

RKObjectLoader.h

objectLoaderDidLoadUnexpectedResponse:

Sent when an object loader encounters a response status code or MIME Type that RestKit does not know how to handle.

- (void)objectLoaderDidLoadUnexpectedResponse:(RKObjectLoader *)objectLoader

Discussion

Response codes in the 2xx, 4xx, and 5xx range are all handled as you would expect. 2xx (successful) response codes are considered a successful content load and object mapping will be attempted. 4xx and 5xx are interpretted as errors and RestKit will attempt to object map an error out of the payload (provided the MIME Type is mappable) and will invoke objectLoader:didFailWithError: after constructing an NSError. Any other status code is considered unexpected and will cause objectLoaderDidLoadUnexpectedResponse: to be invoked provided that you have provided an implementation in your delegate class.

RestKit will also invoke objectLoaderDidLoadUnexpectedResponse: in the event that content is loaded, but there is not a parser registered to handle the MIME Type of the payload. This often happens when the remote backend system RestKit is talking to generates an HTML error page on failure. If your remote system returns content in a MIME Type other than application/json or application/xml, you must register the MIME Type and an appropriate parser with the [RKParserRegistry sharedParser] instance.

Also note that in the event RestKit encounters an unexpected status code or MIME Type response an error will be constructed and sent to the delegate via objectLoader:didFailsWithError: unless your delegate provides an implementation of objectLoaderDidLoadUnexpectedResponse:. It is recommended that you provide an implementation and attempt to handle common unexpected MIME types (particularly text/html and text/plain).

@optional

Declared In

RKObjectLoader.h

waitForResponse

Waits for an asynchronous RKRequest or RKObjectLoader network operation to load a response by spinning the current run loop to block the current thread of execution.

- (void)waitForResponse

Discussion

The wait operation is guarded by a timeout

Declared In

RKTestResponseLoader.h