RKMappingTest Class Reference
Inherits from | NSObject |
Declared in | RKMappingTest.h RKMappingTest.m |
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:object:
Creates and returns a new test for a given object mapping and source object.
-
+ 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.
Setting Expectations
-
– 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.
-
– 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.
-
– 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.
-
– addExpectation:
Adds an expectation to the receiver to be evaluated during verification.
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.
Test Configuration
-
mapping
The object mapping under test.
property -
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 -
sourceObject
The source object being mapped from.
property -
destinationObject
The destionation object being mapped to.
property -
verifiesOnExpect
A Boolean value that determines if expectations should be verified immediately when added to the receiver.
property
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.mapping mappableObjectForData:self.sourceObject]
and set the
new object as the value for the destinationObject property.
Declared In
RKMappingTest.h
mapping
The object mapping under test.
@property (nonatomic, strong, readonly) RKObjectMapping *mapping
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:object:
Creates and returns a new test for a given object mapping and source object.
+ (RKMappingTest *)testForMapping:(RKObjectMapping *)mapping object:(id)sourceObject
Return Value
A new mapping test object for a mapping and sourceObject.
Declared In
RKMappingTest.h
testForMapping:sourceObject:destinationObject:
Creates and returns a new test for a given object mapping, source object and destination object.
+ (RKMappingTest *)testForMapping:(RKObjectMapping *)mapping sourceObject:(id)sourceObject destinationObject:(id)destinationObject
Parameters
- mapping
The object mapping being tested.
- sourceObject
The source object being mapped from.
- destinationObject
The destionation object being to.
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.
See Also
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:(BOOL ( ^ ) ( RKObjectAttributeMapping *mapping , id value ))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: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:(RKObjectMapping *)mapping sourceObject:(id)sourceObject destinationObject:(id)destinationObject
Parameters
- mapping
The object 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
- NSInternalInconsistencyException
Raises an NSInternalInconsistencyException if mapping fails or any expectation is not satisfied.
Declared In
RKMappingTest.h