I want to test is method called with specific parameters. But it's always fail, even if I see in the debugger, that method is called.
SPEC_BEGIN(ShareWithFriendsViewControllerSpec)
describe(@"ShareWithFriendsViewController", ^{
context(@"Test Analytics Share with friends", ^{
id googleMetricsMock = [GoogleMetrics nullMock];
beforeAll(^{
[GoogleMetrics stub:@selector(sharedInstance)
andReturn:googleMetricsMock];
});
it(@"Should report pressing share button", ^{
ShareWithFriendsViewController *vc = [ShareWithFriendsViewController new];
[vc handleButtonCellButtonPressedNotification:nil];
[[googleMetricsMock should] receive:@selector(pushEventMetrics:)];
[[googleMetricsMock should] receive:@selector(pushEventMetrics:)
withArguments:[@{ kMetricsEventCategoryKey : kMetricsEventCategorySocialInteractions,
kMetricsEventActionKey : kMetricsEventActionClick,
kMetricsEventLabelKey : kMetricsEventRecommendLabel } mutableCopy]];
});
});
});
SPEC_END
My implementation of handleButtonCellButtonPressedNotification:
- (void)handleButtonCellButtonPressedNotification:(NSNotification *)aNotification
{
[self reportGoogleAnalyticsLabel:kMetricsEventRecommendLabel
action:kMetricsEventActionClick
context:nil];
}
- (void)reportGoogleAnalyticsLabel:(NSString *)label
action:(NSString *)action
context:(NSString *)context
{
NSMutableDictionary *dataDictionary = [@{ kMetricsEventCategoryKey : kMetricsEventCategorySocialInteractions,
kMetricsEventActionKey : action,
kMetricsEventLabelKey : label
} mutableCopy];
if (context) {
dataDictionary[kMetricsEventContextKey] = context;
}
[[GoogleMetrics sharedInstance] pushEventMetrics:dataDictionary];
}
Aucun commentaire:
Enregistrer un commentaire