Files
RestKit/Tests/Logic/Network/RKRequestDescriptorTest.m
Blake Watters 5c21e52829 Update Dynamic Mapping API's to match the rest of the 0.20.x style. Introduce support for predicate based dynamic matching.
* Rename RKDynamicMappingMatcher to RKObjectMappingMatcher since it is not strictly coupled to dynamic mapping and works with object mappings.
* Rework matchers into using a class cluster style to enable flexible subclassing to introduce additional matchers.
2012-12-27 22:16:40 -05:00

71 lines
2.7 KiB
Objective-C

//
// RKRequestDescriptorTest.m
// RestKit
//
// Created by Blake Watters on 10/14/12.
// Copyright (c) 2012 RestKit. All rights reserved.
//
#import "RKTestEnvironment.h"
#import "RKDynamicMapping.h"
@interface RKRequestDescriptorTest : RKTestCase
@end
@implementation RKRequestDescriptorTest
- (void)testValidArgumentsInitializeWithoutRaisingException
{
RKObjectMapping *invalidMapping = [RKObjectMapping requestMapping];
NSException *exception = nil;
@try {
[RKRequestDescriptor requestDescriptorWithMapping:invalidMapping objectClass:[RKRequestDescriptorTest class] rootKeyPath:nil];
}
@catch (NSException *caughtExpection) {
exception = caughtExpection;
}
@finally {
expect(exception).to.beNil();
}
}
- (void)testInvalidArgumentExceptionIsRaisedIfInitializedWithNonRequestMapping
{
RKObjectMapping *invalidMapping = [RKObjectMapping mappingForClass:[RKRequestDescriptorTest class]];
NSException *exception = nil;
@try {
[RKRequestDescriptor requestDescriptorWithMapping:invalidMapping objectClass:[RKRequestDescriptorTest class] rootKeyPath:nil];
}
@catch (NSException *caughtExpection) {
exception = caughtExpection;
}
@finally {
expect(exception).notTo.beNil();
expect(exception.name).to.equal(NSInvalidArgumentException);
expect(exception.reason).to.equal(@"`RKRequestDescriptor` objects must be initialized with a mapping whose target class is `NSMutableDictionary`, got 'RKRequestDescriptorTest' (see `[RKObjectMapping requestMapping]`)");
}
}
- (void)testInvalidArgumentExceptionIsRaisedInInitializedWithDynamicMappingContainingNonRequestMappings
{
RKObjectMapping *invalidMapping = [RKObjectMapping mappingForClass:[RKRequestDescriptorTest class]];
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"whatever" expectedValue:@"whatever" objectMapping:invalidMapping]];
NSException *exception = nil;
@try {
[RKRequestDescriptor requestDescriptorWithMapping:dynamicMapping objectClass:[RKRequestDescriptorTest class] rootKeyPath:nil];
}
@catch (NSException *caughtExpection) {
exception = caughtExpection;
}
@finally {
expect(exception).notTo.beNil();
expect(exception.name).to.equal(NSInvalidArgumentException);
expect(exception.reason).to.equal(@"`RKRequestDescriptor` objects may only be initialized with `RKDynamicMapping` objects containing `RKObjectMapping` objects whose target class is `NSMutableDictionary`, got 'RKRequestDescriptorTest' (see `[RKObjectMapping requestMapping]`)");
}
}
@end