Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Update to new Quick spec format
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Nov 21, 2014
1 parent 614ceeb commit eff2c04
Showing 1 changed file with 43 additions and 41 deletions.
84 changes: 43 additions & 41 deletions OctoKitTests/OCTObjectSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,62 +18,64 @@
NSString * const OCTObjectKey = @"object";
NSString * const OCTObjectExternalRepresentationKey = @"externalRepresentation";

QuickSharedExampleGroupsBegin(OCTObjectSharedExamples)
QuickConfigurationBegin(OCTObjectSharedExamples)

sharedExamples(OCTObjectArchivingSharedExamplesName, ^(QCKDSLSharedExampleContext data) {
__block OCTObject *obj;
+ (void)configure:(Configuration *)configuration {
sharedExamples(OCTObjectArchivingSharedExamplesName, ^(QCKDSLSharedExampleContext data) {
__block OCTObject *obj;

beforeEach(^{
obj = data()[OCTObjectKey];
expect(obj).notTo(beNil());
});
beforeEach(^{
obj = data()[OCTObjectKey];
expect(obj).notTo(beNil());
});

it(@"should implement <NSCoding>", ^{
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:obj];
expect(data).notTo(beNil());
it(@"should implement <NSCoding>", ^{
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:obj];
expect(data).notTo(beNil());

OCTObject *unarchivedObj = [NSKeyedUnarchiver unarchiveObjectWithData:data];
expect(unarchivedObj).to(equal(obj));
OCTObject *unarchivedObj = [NSKeyedUnarchiver unarchiveObjectWithData:data];
expect(unarchivedObj).to(equal(obj));
});
});
});

sharedExamples(OCTObjectExternalRepresentationSharedExamplesName, ^(QCKDSLSharedExampleContext data) {
__block OCTObject *obj;
__block NSDictionary *representation;
sharedExamples(OCTObjectExternalRepresentationSharedExamplesName, ^(QCKDSLSharedExampleContext data) {
__block OCTObject *obj;
__block NSDictionary *representation;

__block void (^expectRepresentationsToMatch)(NSDictionary *, NSDictionary *);
__block void (^expectRepresentationsToMatch)(NSDictionary *, NSDictionary *);

beforeEach(^{
obj = data()[OCTObjectKey];
expect(obj).notTo(beNil());
beforeEach(^{
obj = data()[OCTObjectKey];
expect(obj).notTo(beNil());

representation = data()[OCTObjectExternalRepresentationKey];
expect(representation).notTo(beNil());
representation = data()[OCTObjectExternalRepresentationKey];
expect(representation).notTo(beNil());

__block void (^expectRepresentationsToMatchRecur)(NSDictionary *, NSDictionary *);
expectRepresentationsToMatch = ^(NSDictionary *representation, NSDictionary *JSONDictionary) {
[representation enumerateKeysAndObjectsUsingBlock:^(NSString *key, id expectedValue, BOOL *stop) {
id value = JSONDictionary[key];
if (value == nil) return;
__block void (^expectRepresentationsToMatchRecur)(NSDictionary *, NSDictionary *);
expectRepresentationsToMatch = ^(NSDictionary *representation, NSDictionary *JSONDictionary) {
[representation enumerateKeysAndObjectsUsingBlock:^(NSString *key, id expectedValue, BOOL *stop) {
id value = JSONDictionary[key];
if (value == nil) return;

if ([value isKindOfClass:NSDictionary.class]) {
expectRepresentationsToMatchRecur(value, expectedValue);
} else {
expect(value).to(equal(expectedValue));
}
}];
};
if ([value isKindOfClass:NSDictionary.class]) {
expectRepresentationsToMatchRecur(value, expectedValue);
} else {
expect(value).to(equal(expectedValue));
}
}];
};

expectRepresentationsToMatchRecur = expectRepresentationsToMatch;
});
expectRepresentationsToMatchRecur = expectRepresentationsToMatch;
});

it(@"should be equal in all values that exist in both external representations", ^{
NSDictionary *JSONDictionary = [MTLJSONAdapter JSONDictionaryFromModel:obj];
expectRepresentationsToMatch(representation, JSONDictionary);
it(@"should be equal in all values that exist in both external representations", ^{
NSDictionary *JSONDictionary = [MTLJSONAdapter JSONDictionaryFromModel:obj];
expectRepresentationsToMatch(representation, JSONDictionary);
});
});
});
}

QuickSharedExampleGroupsEnd
QuickConfigurationEnd

QuickSpecBegin(OCTObjectSpec)

Expand Down

0 comments on commit eff2c04

Please sign in to comment.