RKMappingTest Class Reference
| 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
-
+ testForMapping:sourceObject:destinationObject:Creates and returns a new test for a given object mapping, source object and destination object.
-
– initWithMapping:sourceObject:destinationObject:Initializes the receiver with a given object mapping, source object, and destination object.
Managing Expectations
-
– addExpectation:Adds an expectation to the receiver to be evaluated during verification.
-
– evaluateExpectation:error:Evaluates the given expectation against the mapping test and returns a Boolean value indicating if the expectation is met by the receiver.
Verifying Results
-
– performMappingPerforms 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.
-
– verifyVerifies that the mapping is configured correctly by performing an object mapping operation and ensuring that all expectations are met.
-
– evaluateEvaluates the expectations and returns a Boolean value indicating if all expectations are satisfied.
Test Configuration
-
mappingThe mapping under test. Can be either an
propertyRKObjectMappingorRKDynamicMappingobject. -
mappingOperationDataSourceA data source for the mapping operation.
property -
rootKeyPathA 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 -
sourceObjectThe source object being mapped from.
property -
destinationObjectThe destionation object being mapped to.
property
Core Data Integration
-
managedObjectContextThe managed object context within which to perform the mapping test. Required if testing an
propertyRKEntityMappingobject and an appropriatemappingOperationDataSourcehas not been configured. -
managedObjectCacheThe managed object cache to use when performing a mapping test.
property
Properties
destinationObject
The destionation object being mapped to.
@property (nonatomic, strong, readonly) id destinationObjectDiscussion
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.hmanagedObjectCache
The managed object cache to use when performing a mapping test.
@property (nonatomic, strong) id<RKManagedObjectCaching> managedObjectCacheDiscussion
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.hmanagedObjectContext
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 *managedObjectContextDiscussion
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.hmapping
The mapping under test. Can be either an RKObjectMapping or RKDynamicMapping object.
@property (nonatomic, strong, readonly) RKMapping *mappingDeclared In
RKMappingTest.hmappingOperationDataSource
A data source for the mapping operation.
@property (nonatomic, strong) id<RKMappingOperationDataSource> mappingOperationDataSourceDiscussion
If nil, an appropriate data source will be constructed for you using the available configuration of the receiver.
Declared In
RKMappingTest.hClass 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)destinationObjectParameters
- mapping
The mapping being tested.
- sourceObject
The source object being mapped from.
- destinationObject
The destionation object being to.
Declared In
RKMappingTest.hInstance Methods
addExpectation:
Adds an expectation to the receiver to be evaluated during verification.
- (void)addExpectation:(id)expectationParameters
- expectation
An expectation object to evaluate during test verification. Must be an instance of
RKPropertyMappingTestExpectationorRKConnectionTestExpectation.
Declared In
RKMappingTest.hevaluate
Evaluates the expectations and returns a Boolean value indicating if all expectations are satisfied.
- (BOOL)evaluateReturn 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.hevaluateExpectation: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 **)errorParameters
- expectation
The expectation to evaluate against the receiver. Must be an intance of either
RKPropertyMappingTestExpectationorRKConnectionTestExpectation.
- error
A pointer to an
NSErrorobject 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.hinitWithMapping:sourceObject:destinationObject:
Initializes the receiver with a given object mapping, source object, and destination object.
- (id)initWithMapping:(RKMapping *)mapping sourceObject:(id)sourceObject destinationObject:(id)destinationObjectParameters
- 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.hperformMapping
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)performMappingExceptions
- NSInternalInconsistencyException
Raises an
NSInternalInconsistencyExceptionif mapping fails.
Declared In
RKMappingTest.hverify
Verifies that the mapping is configured correctly by performing an object mapping operation and ensuring that all expectations are met.
- (void)verifyExceptions
- RKMappingTestVerificationFailureException
Raises an
RKMappingTestVerificationFailureExceptionexception if mapping fails or any expectation is not satisfied.
Declared In
RKMappingTest.h