Updates to make parsedBody: implementation ready for merge. Migrated all remaining specs to RKSpec so failures don't cause crashes when you use the Hamcrest helpers. closes #153

This commit is contained in:
Blake Watters
2011-06-15 10:47:45 -04:00
parent d5e3fc33a1
commit e65ea71b20
16 changed files with 36 additions and 24 deletions

View File

@@ -92,7 +92,7 @@
/**
* Return the response body parsed as JSON into an object
*/
- (id)parsedBody:(NSError*)error;
- (id)parsedBody:(NSError**)error;
/**
* Will determine if there is an error object and use it's localized message

View File

@@ -149,11 +149,11 @@ extern NSString* cacheURLKey;
return nil;
}
- (id)parsedBody:(NSError*)error {
- (id)parsedBody:(NSError**)error {
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:[self contentType]];
id object = [parser objectFromString:[self bodyAsString] error:&error];
if (error == nil) {
RKLogError(@"Unable to parse response body: %@", [error localizedDescription]);
id object = [parser objectFromString:[self bodyAsString] error:error];
if (object == nil) {
RKLogError(@"Unable to parse response body: %@", [*error localizedDescription]);
return nil;
}
return object;

View File

@@ -62,7 +62,7 @@
<EnvironmentVariables>
<EnvironmentVariable
key = "UISPEC_SPEC"
value = "RKRequestSpec"
value = "RKResponseSpec"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
@@ -72,7 +72,7 @@
</EnvironmentVariable>
<EnvironmentVariable
key = "UISPEC_EXAMPLE"
value = "itShouldCacheTheRequestHeadersAndBodyIncludingOurOwnCustomTimestampHeader"
value = "itShouldPostSimpleKeyValuesViaRKParams"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
@@ -87,7 +87,7 @@
</EnvironmentVariable>
<EnvironmentVariable
key = "UISPEC_SPEC"
value = "RKManagedObjectFactorySpec"
value = "RKRequestSpec"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable

View File

@@ -9,7 +9,7 @@
#import "RKSpecEnvironment.h"
#import "RKHuman.h"
@interface RKManagedObjectSpec : NSObject <UISpec> {
@interface RKManagedObjectSpec : RKSpec {
}

View File

@@ -13,7 +13,7 @@
static NSString* const RKAuthenticationSpecUsername = @"restkit";
static NSString* const RKAuthenticationSpecPassword = @"authentication";
@interface RKAuthenticationSpec : NSObject <UISpec> {
@interface RKAuthenticationSpec : RKSpec {
}

View File

@@ -8,7 +8,7 @@
#import "RKSpecEnvironment.h"
@interface RKClientSpec : NSObject <UISpec> {
@interface RKClientSpec : RKSpec {
}
@end

View File

@@ -9,7 +9,7 @@
#import "RKSpecEnvironment.h"
#import "RKParamsAttachment.h"
@interface RKParamsAttachmentSpec : NSObject <UISpec> {
@interface RKParamsAttachmentSpec : RKSpec {
}
@end

View File

@@ -8,7 +8,7 @@
#import "RKSpecEnvironment.h"
@interface RKRequestQueueSpec : NSObject <UISpec> {
@interface RKRequestQueueSpec : RKSpec {
}

View File

@@ -16,7 +16,7 @@
- (void)shouldDispatchRequest;
@end
@interface RKRequestSpec : NSObject <UISpec> {
@interface RKRequestSpec : RKSpec {
}
@end

View File

@@ -9,7 +9,7 @@
#import "RKSpecEnvironment.h"
#import "RKResponse.h"
@interface RKResponseSpec : NSObject <UISpec> {
@interface RKResponseSpec : RKSpec {
RKResponse* _response;
}
@@ -191,4 +191,16 @@
[expectThat([mock isJSON]) should:be(YES)];
}
- (void)itShouldReturnParseErrorsWhenParsedBodyFails {
RKResponse* response = [[[RKResponse alloc] init] autorelease];
id mock = [OCMockObject partialMockForObject:response];
[[[mock stub] andReturn:@"sad;sdvjnk;"] bodyAsString];
[[[mock stub] andReturn:@"application/json"] contentType];
NSError* error = nil;
id object = [mock parsedBody:&error];
assertThat(object, is(nilValue()));
assertThat(error, isNot(nilValue()));
assertThat([error localizedDescription], is(equalTo(@"Unexpected token, wanted '{', '}', '[', ']', ',', ':', 'true', 'false', 'null', '\"STRING\"', 'NUMBER'.")));
}
@end

View File

@@ -56,7 +56,7 @@
// TODO: These specs need to be executed against the RKManagedObjectLoader and RKObjectLoader
// until we can collapse the functionality somehow...
@interface RKObjectLoaderSpec : NSObject <UISpec> {
@interface RKObjectLoaderSpec : RKSpec {
}
@@ -278,7 +278,7 @@
@end
// Works with Michael Deung's RailsUser.json
@interface RKUserRailsJSONMappingSpec : NSObject <UISpec> {
@interface RKUserRailsJSONMappingSpec : RKSpec {
}
@end

View File

@@ -63,7 +63,7 @@
@end
@interface RKObjectMapperSpec : NSObject <UISpec>
@interface RKObjectMapperSpec : RKSpec
- (NSString*)jsonString;
- (NSString*)jsonCollectionString;
@@ -559,7 +559,7 @@
@end
@interface RKObjectMapperRegisteredClassWithArraySpec : NSObject <UISpec> {
@interface RKObjectMapperRegisteredClassWithArraySpec : RKSpec {
@private
}
@end
@@ -696,7 +696,7 @@
@end
@interface RKObjectMapperPayloadItemsWithDuplicateKeysSpec : NSObject <UISpec> {
@interface RKObjectMapperPayloadItemsWithDuplicateKeysSpec : RKSpec {
}
@end

View File

@@ -12,7 +12,7 @@
#import "RKHuman.h"
#import "RKCat.h"
@interface RKObjectRouterSpec : NSObject <UISpec> {
@interface RKObjectRouterSpec : RKSpec {
}
@end

View File

@@ -13,7 +13,7 @@
#import "RKHuman.h"
#import "RKCat.h"
@interface RKRailsRouterSpec : NSObject <UISpec> {
@interface RKRailsRouterSpec : RKSpec {
}
@end

View File

@@ -10,7 +10,7 @@
#import "NSDictionary+RKRequestSerialization.h"
#import "NSDictionary+RKAdditions.h"
@interface NSDictionary_RKRequestSerializationSpec : NSObject <UISpec> {
@interface NSDictionary_RKRequestSerializationSpec : RKSpec {
}

View File

@@ -9,7 +9,7 @@
#import "RKSpecEnvironment.h"
#import "RKXMLParserLibXML.h"
@interface RKXMLParserLibXMLSpec : NSObject <UISpec> {
@interface RKXMLParserLibXMLSpec : RKSpec {
}