Created
January 26, 2012 13:37
-
-
Save yas375/1682807 to your computer and use it in GitHub Desktop.
Добавление метода "renameKey:to:" к NSMutableDisctionary и тесты для него при помощи kiwi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| @interface NSMutableDictionary (Utils) | |
| - (void)renameKey:(NSString *)oldKeyName to:(NSString *)newKeyName; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "NSMutableDictionary+Utils.h" | |
| @implementation NSMutableDictionary (Utils) | |
| - (void)renameKey:(NSString *)oldKeyName to:(NSString *)newKeyName { | |
| [self setValue:[self valueForKey:oldKeyName] forKey:newKeyName]; | |
| [self removeObjectForKey:oldKeyName]; | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "Kiwi.h" | |
| #import "NSMutableDictionary+Utils.h" | |
| SPEC_BEGIN(NSMutableDictionaryUtilsSpec) | |
| describe(@"NSMutableDictionary", ^{ | |
| __block NSMutableDictionary *subject = nil; | |
| static NSString *oldKey = @"oldKey"; | |
| static NSString *newKey = @"newKey"; | |
| __block id valueForOldKey = nil; | |
| beforeEach(^{ | |
| subject = [NSMutableDictionary dictionaryWithObject:@"my object" forKey:oldKey]; | |
| valueForOldKey = [subject valueForKey:oldKey]; | |
| }); | |
| context(@"before rename", ^{ | |
| it(@"should have value for old key", ^{ | |
| [[[subject valueForKey:oldKey] should] beIdenticalTo:valueForOldKey]; | |
| }); | |
| it(@"should not have newKey", ^{ | |
| [[subject valueForKey:newKey] shouldBeNil]; | |
| }); | |
| }); | |
| context(@"after rename", ^{ | |
| beforeEach(^{ | |
| [subject renameKey:oldKey to:newKey]; | |
| }); | |
| it(@"should have appropriate value for new key", ^{ | |
| [[[subject valueForKey:newKey] should] beIdenticalTo:valueForOldKey]; | |
| }); | |
| it(@"should not have any value for old key", ^{ | |
| [[subject valueForKey:oldKey] shouldBeNil]; | |
| }); | |
| }); | |
| }); | |
| SPEC_END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment