|
1 | | -#import <Specta/Specta.h> |
2 | | -#define EXP_SHORTHAND |
3 | | -#import <Expecta/Expecta.h> |
| 1 | +#import <Quick/Quick.h> |
4 | 2 | #import <OCMock/OCMock.h> |
5 | 3 | #import "TestAnalyticsTracker.h" |
6 | 4 |
|
7 | 5 | // Rather than duplicate these tests for each method, we abstracted them into a set of |
8 | 6 | // shared examples and use an NSInvocation object to tell us what to call. |
9 | | -SharedExampleGroupsBegin(WPAnalyticsMethodBehavior) |
10 | | - |
11 | | -sharedExamplesFor(@"a WPAnalyticsTracker method", ^(NSDictionary *data) { |
12 | | - NSInvocation *invocation = data[@"invocation"]; |
13 | | - it(@"should not be called if tracker isn't registered", ^{ |
14 | | - id trackerMock = OCMStrictClassMock([TestAnalyticsTracker class]); |
15 | | - id expectation = [trackerMock reject]; |
16 | | - [invocation invokeWithTarget:expectation]; |
17 | | - [trackerMock verify]; |
| 7 | +QuickConfigurationBegin(WPAnalyticsMethodBehavior) |
| 8 | + |
| 9 | ++ (void)configure:(QCKConfiguration *)configuration |
| 10 | +{ |
| 11 | + sharedExamples(@"a WPAnalyticsTracker method", ^(QCKDSLSharedExampleContext context) { |
| 12 | + NSInvocation *invocation = context()[@"invocation"]; |
| 13 | + it(@"should not be called if tracker isn't registered", ^{ |
| 14 | + id trackerMock = OCMStrictClassMock([TestAnalyticsTracker class]); |
| 15 | + id expectation = [trackerMock reject]; |
| 16 | + [invocation invokeWithTarget:expectation]; |
| 17 | + [trackerMock verify]; |
| 18 | + }); |
| 19 | + |
| 20 | + it(@"should be called if tracker is registered", ^{ |
| 21 | + id trackerMock = OCMStrictClassMock([TestAnalyticsTracker class]); |
| 22 | + id expectation = [trackerMock expect]; |
| 23 | + [invocation invokeWithTarget:expectation]; |
| 24 | + [invocation invokeWithTarget:trackerMock]; |
| 25 | + [trackerMock verify]; |
| 26 | + }); |
| 27 | + |
| 28 | + it(@"should be called on multiple trackers if registered", ^{ |
| 29 | + id trackerMock = OCMStrictClassMock([TestAnalyticsTracker class]); |
| 30 | + id trackerMock2 = OCMStrictClassMock([TestAnalyticsTracker class]); |
| 31 | + id expectation = [trackerMock expect]; |
| 32 | + id expectation2 = [trackerMock2 expect]; |
| 33 | + [invocation invokeWithTarget:expectation]; |
| 34 | + [invocation invokeWithTarget:expectation2]; |
| 35 | + [invocation invokeWithTarget:trackerMock]; |
| 36 | + [invocation invokeWithTarget:trackerMock2]; |
| 37 | + [trackerMock verify]; |
| 38 | + [trackerMock2 verify]; |
| 39 | + }); |
18 | 40 | }); |
19 | | - |
20 | | - it(@"should be called if tracker is registered", ^{ |
21 | | - id trackerMock = OCMStrictClassMock([TestAnalyticsTracker class]); |
22 | | - id expectation = [trackerMock expect]; |
23 | | - [invocation invokeWithTarget:expectation]; |
24 | | - [invocation invokeWithTarget:trackerMock]; |
25 | | - [trackerMock verify]; |
26 | | - }); |
27 | | - |
28 | | - it(@"should be called on multiple trackers if registered", ^{ |
29 | | - id trackerMock = OCMStrictClassMock([TestAnalyticsTracker class]); |
30 | | - id trackerMock2 = OCMStrictClassMock([TestAnalyticsTracker class]); |
31 | | - id expectation = [trackerMock expect]; |
32 | | - id expectation2 = [trackerMock2 expect]; |
33 | | - [invocation invokeWithTarget:expectation]; |
34 | | - [invocation invokeWithTarget:expectation2]; |
35 | | - [invocation invokeWithTarget:trackerMock]; |
36 | | - [invocation invokeWithTarget:trackerMock2]; |
37 | | - [trackerMock verify]; |
38 | | - [trackerMock2 verify]; |
39 | | - }); |
40 | | -}); |
| 41 | +} |
41 | 42 |
|
42 | | -SharedExampleGroupsEnd |
| 43 | +QuickConfigurationEnd |
43 | 44 |
|
44 | | -SpecBegin(WPAnalyticsSpecs) |
| 45 | +QuickSpecBegin(WPAnalyticsSpecs) |
45 | 46 |
|
46 | 47 | beforeEach(^{ |
47 | 48 | [WPAnalytics clearTrackers]; |
|
51 | 52 | NSMethodSignature *signature = [TestAnalyticsTracker instanceMethodSignatureForSelector:@selector(beginSession)]; |
52 | 53 | NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; |
53 | 54 | [invocation setSelector:@selector(beginSession)]; |
54 | | - |
55 | | - itShouldBehaveLike(@"a WPAnalyticsTracker method", @{@"invocation": invocation}); |
| 55 | + |
| 56 | + itBehavesLike(@"a WPAnalyticsTracker method", ^{ return @{@"invocation": invocation}; }); |
56 | 57 | }); |
57 | 58 |
|
58 | 59 | describe(@"endSession", ^{ |
59 | 60 | NSMethodSignature *signature = [TestAnalyticsTracker instanceMethodSignatureForSelector:@selector(endSession)]; |
60 | 61 | NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; |
61 | 62 | [invocation setSelector:@selector(endSession)]; |
62 | 63 |
|
63 | | - itShouldBehaveLike(@"a WPAnalyticsTracker method", @{@"invocation": invocation}); |
| 64 | + itBehavesLike(@"a WPAnalyticsTracker method", ^{ return @{@"invocation": invocation}; }); |
64 | 65 | }); |
65 | 66 |
|
66 | 67 | describe(@"refreshMetadata", ^{ |
67 | 68 | NSMethodSignature *signature = [TestAnalyticsTracker instanceMethodSignatureForSelector:@selector(refreshMetadata)]; |
68 | 69 | NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; |
69 | 70 | [invocation setSelector:@selector(refreshMetadata)]; |
70 | 71 |
|
71 | | - itShouldBehaveLike(@"a WPAnalyticsTracker method", @{@"invocation": invocation}); |
| 72 | + itBehavesLike(@"a WPAnalyticsTracker method", ^{ return @{@"invocation": invocation}; }); |
72 | 73 | }); |
73 | 74 |
|
74 | 75 | describe(@"beginTimerForStat:", ^{ |
|
78 | 79 | WPAnalyticsStat stat = WPAnalyticsStatApplicationOpened; |
79 | 80 | [invocation setArgument:&stat atIndex:2]; |
80 | 81 |
|
81 | | - itShouldBehaveLike(@"a WPAnalyticsTracker method", @{@"invocation": invocation}); |
| 82 | + itBehavesLike(@"a WPAnalyticsTracker method", ^{ return @{@"invocation": invocation}; }); |
82 | 83 | }); |
83 | 84 |
|
84 | 85 | describe(@"endTimerForStat:withProperties", ^{ |
|
91 | 92 | [invocation setArgument:&stat atIndex:2]; |
92 | 93 | [invocation setArgument:&dict atIndex:3]; |
93 | 94 |
|
94 | | - itShouldBehaveLike(@"a WPAnalyticsTracker method", @{@"invocation": invocation}); |
| 95 | + itBehavesLike(@"a WPAnalyticsTracker method", ^{ return @{@"invocation": invocation}; }); |
95 | 96 | }); |
96 | 97 |
|
97 | 98 | describe(@"track:", ^{ |
|
101 | 102 | WPAnalyticsStat stat = WPAnalyticsStatApplicationOpened; |
102 | 103 | [invocation setArgument:&stat atIndex:2]; |
103 | 104 |
|
104 | | - itShouldBehaveLike(@"a WPAnalyticsTracker method", @{@"invocation": invocation}); |
| 105 | + itBehavesLike(@"a WPAnalyticsTracker method", ^{ return @{@"invocation": invocation}; }); |
105 | 106 | }); |
106 | 107 |
|
107 | 108 | describe(@"track:withProperties:", ^{ |
|
114 | 115 | [invocation setArgument:&stat atIndex:2]; |
115 | 116 | [invocation setArgument:&dict atIndex:3]; |
116 | 117 |
|
117 | | - itShouldBehaveLike(@"a WPAnalyticsTracker method", @{@"invocation": invocation}); |
| 118 | + itBehavesLike(@"a WPAnalyticsTracker method", ^{ return @{@"invocation": invocation}; }); |
118 | 119 | }); |
119 | 120 |
|
120 | 121 | describe(@"trackString:", ^{ |
|
124 | 125 | NSString *event = @"my_event"; |
125 | 126 | [invocation setArgument:&event atIndex:2]; |
126 | 127 |
|
127 | | - itShouldBehaveLike(@"a WPAnalyticsTracker method", @{@"invocation": invocation}); |
| 128 | + itBehavesLike(@"a WPAnalyticsTracker method", ^{ return @{@"invocation": invocation}; }); |
128 | 129 | }); |
129 | 130 |
|
130 | 131 | describe(@"trackString:withProperties:", ^{ |
|
137 | 138 | [invocation setArgument:&event atIndex:2]; |
138 | 139 | [invocation setArgument:&dict atIndex:3]; |
139 | 140 |
|
140 | | - itShouldBehaveLike(@"a WPAnalyticsTracker method", @{@"invocation": invocation}); |
| 141 | + itBehavesLike(@"a WPAnalyticsTracker method", ^{ return @{@"invocation": invocation}; }); |
141 | 142 | }); |
142 | 143 |
|
143 | | -SpecEnd |
| 144 | +QuickSpecEnd |
0 commit comments