forked from intentkit/IntentKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINKDefaultsManagerSpec.m
87 lines (70 loc) · 2.9 KB
/
INKDefaultsManagerSpec.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// INKDefaultsManagerSpec
// INKOpenInKitDemo
//
// Created by Michael Walker on 12/18/13.
// Copyright (c) 2013 Mike Walker. All rights reserved.
//
#define EXP_SHORTHAND
#define HC_SHORTHAND
#define MOCKITO_SHORTHAND
#import "Specta.h"
#import "Expecta.h"
#import <OCHamcrest/OCHamcrest.h>
#import <OCMockito/OCMockito.h>
#import "INKDefaultsManager.h"
#import "INKHandler.h"
#import "INKBrowserHandler.h"
SpecBegin(INKDefaultsManager)
describe(@"INKDefaultsManager", ^{
__block INKDefaultsManager *manager;
beforeEach(^{
manager = [[INKDefaultsManager alloc] init];
NSString *domainName = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:domainName];
});
describe(@"when nothing has been set", ^{
it(@"should return a handler's default application", ^{
expect([manager defaultApplicationForHandler:INKBrowserHandler.class allowSystemDefault:YES]).to.equal(@"Safari");
});
});
describe(@"setting defaults", ^{
context(@"when there is no default for an application", ^{
beforeEach(^{
[manager addDefault:@"FooBar" forHandler:[INKHandler class]];
});
it(@"should be able to retrieve it", ^{
expect([manager defaultApplicationForHandler:INKHandler.class allowSystemDefault:YES]).to.equal(@"FooBar");
});
it(@"should not affect other classes", ^{
expect([manager defaultApplicationForHandler:INKBrowserHandler.class allowSystemDefault:YES]).toNot.equal(@"FooBar");
});
});
});
describe(@"clearing out a single default", ^{
beforeEach(^{
[manager addDefault:@"Foo" forHandler:[INKHandler class]];
[manager addDefault:@"Bar" forHandler:[INKBrowserHandler class]];
});
it(@"should remove it", ^{
[manager removeDefaultForHandler:[INKHandler class]];
expect([manager defaultApplicationForHandler:INKHandler.class allowSystemDefault:NO]).to.beNil();
});
it(@"should not remove others", ^{
[manager removeDefaultForHandler:[INKHandler class]];
expect([manager defaultApplicationForHandler:INKBrowserHandler.class allowSystemDefault:NO]).to.equal(@"Bar");
});
});
describe(@"removing all defaults", ^{
beforeEach(^{
[manager addDefault:@"Foo" forHandler:[INKHandler class]];
[manager addDefault:@"Bar" forHandler:[INKBrowserHandler class]];
});
it(@"should remove all of them", ^{
[manager removeAllDefaults];
expect([manager defaultApplicationForHandler:INKHandler.class allowSystemDefault:NO]).to.beNil();
expect([manager defaultApplicationForHandler:INKBrowserHandler.class allowSystemDefault:YES]).to.equal(@"Safari");
});
});
});
SpecEnd