mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
Updated mapping test API for 0.20
* Reimplemented connection tests to work with `RKConnectionDescription`. Introduced new `RKConnectionTestExpectation` class * Slimmed down API by removing proxy methods on `RKMappingTest` * Eliminated `verifiesOnExpect` behavior in favor of using `evaluateExpectation:` * Ensured compatibility with RKKiwiMatchers
This commit is contained in:
94
Code/Testing/RKPropertyMappingTestExpectation.m
Normal file
94
Code/Testing/RKPropertyMappingTestExpectation.m
Normal file
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// RKMappingTestExpectation.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 2/17/12.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKPropertyMappingTestExpectation.h"
|
||||
#import "RKPropertyMapping.h"
|
||||
|
||||
@interface RKPropertyMappingTestExpectation ()
|
||||
@property (nonatomic, copy, readwrite) NSString *sourceKeyPath;
|
||||
@property (nonatomic, copy, readwrite) NSString *destinationKeyPath;
|
||||
@property (nonatomic, strong, readwrite) id value;
|
||||
@property (nonatomic, copy, readwrite) RKMappingTestExpectationEvaluationBlock evaluationBlock;
|
||||
@property (nonatomic, strong, readwrite) RKMapping *mapping;
|
||||
@end
|
||||
|
||||
@implementation RKPropertyMappingTestExpectation
|
||||
|
||||
+ (RKPropertyMappingTestExpectation *)expectationWithSourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath
|
||||
{
|
||||
RKPropertyMappingTestExpectation *expectation = [self new];
|
||||
expectation.sourceKeyPath = sourceKeyPath;
|
||||
expectation.destinationKeyPath = destinationKeyPath;
|
||||
|
||||
return expectation;
|
||||
}
|
||||
|
||||
+ (RKPropertyMappingTestExpectation *)expectationWithSourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath value:(id)value
|
||||
{
|
||||
RKPropertyMappingTestExpectation *expectation = [self new];
|
||||
expectation.sourceKeyPath = sourceKeyPath;
|
||||
expectation.destinationKeyPath = destinationKeyPath;
|
||||
expectation.value = value;
|
||||
|
||||
return expectation;
|
||||
}
|
||||
|
||||
+ (RKPropertyMappingTestExpectation *)expectationWithSourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath evaluationBlock:(RKMappingTestExpectationEvaluationBlock)evaluationBlock
|
||||
{
|
||||
RKPropertyMappingTestExpectation *expectation = [self new];
|
||||
expectation.sourceKeyPath = sourceKeyPath;
|
||||
expectation.destinationKeyPath = destinationKeyPath;
|
||||
expectation.evaluationBlock = evaluationBlock;
|
||||
|
||||
return expectation;
|
||||
}
|
||||
|
||||
+ (RKPropertyMappingTestExpectation *)expectationWithSourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath mapping:(RKMapping *)mapping
|
||||
{
|
||||
RKPropertyMappingTestExpectation *expectation = [self new];
|
||||
expectation.sourceKeyPath = sourceKeyPath;
|
||||
expectation.destinationKeyPath = destinationKeyPath;
|
||||
expectation.mapping = mapping;
|
||||
|
||||
return expectation;
|
||||
}
|
||||
|
||||
- (NSString *)summary
|
||||
{
|
||||
return [NSString stringWithFormat:@"map '%@' to '%@'", self.sourceKeyPath, self.destinationKeyPath];
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
if (self.value) {
|
||||
return [NSString stringWithFormat:@"map '%@' to '%@' with %@ value '%@'",
|
||||
self.sourceKeyPath, self.destinationKeyPath, [self.value class], self.value];
|
||||
} else if (self.evaluationBlock) {
|
||||
return [NSString stringWithFormat:@"map '%@' to '%@' satisfying evaluation block",
|
||||
self.sourceKeyPath, self.destinationKeyPath];
|
||||
} else if (self.mapping) {
|
||||
return [NSString stringWithFormat:@"map '%@' to '%@' using mapping: %@",
|
||||
self.sourceKeyPath, self.destinationKeyPath, self.mapping];
|
||||
}
|
||||
|
||||
return [self summary];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user