Permalink
Browse files

Test that an error is returned when the parse class is nil

  • Loading branch information...
1 parent ba02934 commit 166ca42ca4fa1bd57949261479f17b91871f291d @jspahrsummers jspahrsummers committed Feb 20, 2013
Showing with 15 additions and 1 deletion.
  1. +10 −0 MantleTests/MTLJSONAdapterSpec.m
  2. +5 −1 MantleTests/MTLTestModel.m
@@ -130,4 +130,14 @@
expect([MTLJSONAdapter JSONDictionaryFromModel:model]).to.equal(values);
});
+it(@"should return an error when no suitable model class is found", ^{
+ NSError *error = nil;
+ MTLTestModel *model = [MTLJSONAdapter modelOfClass:MTLSubstitutingTestModel.class fromJSONDictionary:@{} error:&error];
+ expect(model).to.beNil();
+
+ expect(error).notTo.beNil();
+ expect(error.domain).to.equal(MTLJSONAdapterErrorDomain);
+ expect(error.code).to.equal(MTLJSONAdapterErrorNoClassFound);
+});
+
SpecEnd
@@ -128,7 +128,11 @@ + (NSDictionary *)JSONKeyPathsByPropertyKey {
+ (Class)classForParsingJSONDictionary:(NSDictionary *)JSONDictionary {
NSParameterAssert(JSONDictionary != nil);
- return MTLTestModel.class;
+ if (JSONDictionary[@"username"] == nil) {
+ return nil;
+ } else {
+ return MTLTestModel.class;
+ }
}
@end

0 comments on commit 166ca42

Please sign in to comment.