Inherits from NSObject
Declared in RKMappingTest.h

Overview

An RKMappingTest object provides support for unit testing a RestKit object mapping operation by evaluation expectations against events recorded during an object mapping operation.

Tasks

Creating Tests

Managing Expectations

Verifying Results

  • – performMapping

    Performs the object mapping operation and records any mapping events that occur. The mapping events can be verified against expectation through a subsequent call to verify.

  • – verify

    Verifies that the mapping is configured correctly by performing an object mapping operation and ensuring that all expectations are met.

  • – evaluate

    Evaluates the expectations and returns a Boolean value indicating if all expectations are satisfied.

Test Configuration

Core Data Integration

Properties

destinationObject

The destionation object being mapped to.

@property (nonatomic, strong, readonly) id destinationObject

Discussion

If nil, the mapping test will instantiate a destination object to perform the mapping by invoking [self.mappingOperationDataSource objectForMappableContent:self.sourceObject mapping:self.mapping] to obtain a new object from the data source and then assign the object as the value for the destinationObject property.

Declared In

RKMappingTest.h

managedObjectCache

The managed object cache to use when performing a mapping test.

@property (nonatomic, strong) id<RKManagedObjectCaching> managedObjectCache

Discussion

If the value of this property is nil and the test targets an entity mapping, an instance of RKFetchRequestManagedObjectCache will be constructed and used as the cache for the purposes of testing.

Declared In

RKMappingTest.h

managedObjectContext

The managed object context within which to perform the mapping test. Required if testing an RKEntityMapping object and an appropriate mappingOperationDataSource has not been configured.

@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext

Discussion

When the mappingOperationDataSource property is nil and the test targets an entity mapping, this context is used to configure an RKManagedObjectMappingOperationDataSource object for the purpose of executing the test.

Declared In

RKMappingTest.h

mapping

The mapping under test. Can be either an RKObjectMapping or RKDynamicMapping object.

@property (nonatomic, strong, readonly) RKMapping *mapping

Declared In

RKMappingTest.h

mappingOperationDataSource

A data source for the mapping operation.

@property (nonatomic, strong) id<RKMappingOperationDataSource> mappingOperationDataSource

Discussion

If nil, an appropriate data source will be constructed for you using the available configuration of the receiver.

Declared In

RKMappingTest.h

rootKeyPath

A key path to apply to the source object to specify the location of the root of the data under test. Useful when testing subsets of a larger payload or object graph.

@property (nonatomic, copy) NSString *rootKeyPath

Discussion

Default: nil

Declared In

RKMappingTest.h

sourceObject

The source object being mapped from.

@property (nonatomic, strong, readonly) id sourceObject

Declared In

RKMappingTest.h

Class Methods

testForMapping:sourceObject:destinationObject:

Creates and returns a new test for a given object mapping, source object and destination object.

+ (instancetype)testForMapping:(RKMapping *)mapping sourceObject:(id)sourceObject destinationObject:(id)destinationObject

Parameters

mapping

The mapping being tested.

sourceObject

The source object being mapped from.

destinationObject

The destionation object being to.

Return Value

A new mapping test object for a mapping, a source object and a destination object.

Declared In

RKMappingTest.h

Instance Methods

addExpectation:

Adds an expectation to the receiver to be evaluated during verification.

- (void)addExpectation:(id)expectation

Parameters

expectation

An expectation object to evaluate during test verification. Must be an instance of RKPropertyMappingTestExpectation or RKConnectionTestExpectation.

Declared In

RKMappingTest.h

evaluate

Evaluates the expectations and returns a Boolean value indicating if all expectations are satisfied.

- (BOOL)evaluate

Return Value

YES if all expectations were met, else NO.

Discussion

Invocation of this method will implicitly invoke performMapping if the mapping has not yet been performed.

Declared In

RKMappingTest.h

evaluateExpectation:error:

Evaluates the given expectation against the mapping test and returns a Boolean value indicating if the expectation is met by the receiver.

- (BOOL)evaluateExpectation:(id)expectation error:(NSError **)error

Parameters

expectation

The expectation to evaluate against the receiver. Must be an intance of either RKPropertyMappingTestExpectation or RKConnectionTestExpectation.

error

A pointer to an NSError object to be set describing the failure in the event that the expectation is not met.

Return Value

YES if the expectation is met, else NO.

Discussion

Invocation of this method will implicitly invoke performMapping if the mapping has not yet been performed.

Declared In

RKMappingTest.h

initWithMapping:sourceObject:destinationObject:

Initializes the receiver with a given object mapping, source object, and destination object.

- (id)initWithMapping:(RKMapping *)mapping sourceObject:(id)sourceObject destinationObject:(id)destinationObject

Parameters

mapping

The mapping being tested.

sourceObject

The source object being mapped from.

destinationObject

The destionation object being to.

Return Value

The receiver, initialized with mapping, sourceObject and destinationObject.

Declared In

RKMappingTest.h

performMapping

Performs the object mapping operation and records any mapping events that occur. The mapping events can be verified against expectation through a subsequent call to verify.

- (void)performMapping

Exceptions

NSInternalInconsistencyException

Raises an NSInternalInconsistencyException if mapping fails.

Declared In

RKMappingTest.h

verify

Verifies that the mapping is configured correctly by performing an object mapping operation and ensuring that all expectations are met.

- (void)verify

Exceptions

RKMappingTestVerificationFailureException

Raises an RKMappingTestVerificationFailureException exception if mapping fails or any expectation is not satisfied.

Declared In

RKMappingTest.h