Skip to content

Instantly share code, notes, and snippets.

@yas375
Created January 26, 2012 13:37
Show Gist options
  • Select an option

  • Save yas375/1682807 to your computer and use it in GitHub Desktop.

Select an option

Save yas375/1682807 to your computer and use it in GitHub Desktop.
Добавление метода "renameKey:to:" к NSMutableDisctionary и тесты для него при помощи kiwi
#import <Foundation/Foundation.h>
@interface NSMutableDictionary (Utils)
- (void)renameKey:(NSString *)oldKeyName to:(NSString *)newKeyName;
@end
#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
#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