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

Setting 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.

  • – evaluateExpectation:error:

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

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

verifiesOnExpect

A Boolean value that determines if expectations should be verified immediately when added to the receiver.

@property (nonatomic, assign) BOOL verifiesOnExpect

Discussion

Default: NO

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.

+ (RKMappingTest *)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:(RKMappingTestExpectation *)expectation

Parameters

expectation

An expectation object to evaluate during test verification.

Discussion

If the receiver has been configured with verifiesOnExpect = YES, the mapping operation is performed immediately and the expectation is evaluated.

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:(RKMappingTestExpectation *)expectation error:(NSError **)error

Parameters

expectation

The expectation to evaluate against the receiver.

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

expectMappingFromKeyPath:toKeyPath:

Creates and adds an expectation that a key path on the source object will be mapped to a new key path on the destination object.

- (void)expectMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath

Parameters

sourceKeyPath

A key path on the sourceObject that should be mapped from.

destinationKeyPath

A key path on the destinationObject that should be mapped to.

Declared In

RKMappingTest.h

expectMappingFromKeyPath:toKeyPath:passingTest:

Creates and adds an expectation that a key path on the source object will be mapped to a new key path on the destination object with a value that passes a given test block.

- (void)expectMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath passingTest:(RKMappingTestExpectationEvaluationBlock)evaluationBlock

Parameters

sourceKeyPath

A key path on the sourceObject that should be mapped from.

destinationKeyPath

A key path on the destinationObject that should be mapped to.

evaluationBlock

A block with which to evaluate the success of the mapping.

Declared In

RKMappingTest.h

expectMappingFromKeyPath:toKeyPath:usingMapping:

Creates and adds an expectation that a key path on the source object will be mapped to a new key path on the destination object using the given object mapping.

- (void)expectMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath usingMapping:(RKMapping *)mapping

Parameters

sourceKeyPath

A key path on the sourceObject that should be mapped from.

destinationKeyPath

A key path on the destinationObject that should be mapped to.

mapping

An object mapping that should be used for mapping the source key path.

Declared In

RKMappingTest.h

expectMappingFromKeyPath:toKeyPath:withValue:

Creates and adds an expectation that a key path on the source object will be mapped to a new key path on the destination object with a given value.

- (void)expectMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath withValue:(id)value

Parameters

sourceKeyPath

A key path on the sourceObject that should be mapped from.

destinationKeyPath

A key path on the destinationObject that should be mapped from.

value

A value that is expected to be assigned to destinationKeyPath on the destinationObject.

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