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.

    property

Test Configuration

Core Data Integration

Properties

destinationObject

@property (nonatomic, strong, readonly) id destinationObject
Discussion

The destionation object being mapped to.

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

evaluate

@property (nonatomic, readonly) BOOL evaluate
Discussion

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

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

Return Value

YES if all expectations were met, else NO.

Declared In

RKMappingTest.h

managedObjectCache

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

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

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

@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext
Discussion

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.

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

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

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

Declared In

RKMappingTest.h

mappingOperationDataSource

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

A data source for the mapping operation.

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

Declared In

RKMappingTest.h

rootKeyPath

@property (nonatomic, copy) NSString *rootKeyPath
Discussion

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.

Default: nil

Declared In

RKMappingTest.h

sourceObject

@property (nonatomic, strong, readonly) id sourceObject
Discussion

The source object being mapped from.

Declared In

RKMappingTest.h

Class Methods

testForMapping:sourceObject:destinationObject:

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

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

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:

- (void)addExpectation:(id)expectation
Discussion

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

Parameters

expectation

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

Declared In

RKMappingTest.h

evaluateExpectation:error:

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

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

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

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.

Declared In

RKMappingTest.h

initWithMapping:sourceObject:destinationObject:

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

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

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

- (void)performMapping
Discussion

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.

Exceptions

NSInternalInconsistencyException

Raises an NSInternalInconsistencyException if mapping fails.

Declared In

RKMappingTest.h

verify

- (void)verify
Discussion

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

Exceptions

RKMappingTestVerificationFailureException

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

Declared In

RKMappingTest.h