Skip to content

Commit

Permalink
Add specs for adding and cancelling blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
kattrali committed Nov 8, 2016
1 parent 9d0d869 commit 9795e5d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Tests/BugsnagSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ @implementation BugsnagTestError
};

beforeEach(^{
request = nil;
BugsnagSink *sink = [[KSCrash sharedInstance] valueForKeyPath:@"sink"];
NSURLSession *session = [sink valueForKeyPath:@"session"];
[session stub:@selector(uploadTaskWithRequest:fromData:completionHandler:) withBlock:^id(NSArray *params) {
Expand All @@ -56,6 +57,7 @@ @implementation BugsnagTestError
afterEach(^{
request = nil;
httpBody = nil;
[[Bugsnag configuration] clearBeforeSendBlocks];
});

describe(@"notify:", ^{
Expand Down Expand Up @@ -87,6 +89,46 @@ @implementation BugsnagTestError
});
});

describe(@"updating a report via notify: with beforeSend block", ^{
__block NSException *exception;
__block BOOL called;
beforeEach(^{
called = NO;
exception = [NSException exceptionWithName:@"failure to launch"
reason:@"no fuel" userInfo:nil];
[[Bugsnag configuration] addBeforeSendBlock:^bool(NSDictionary * _Nonnull rawEventData, BugsnagCrashReport * _Nonnull report) {
report.errorClass = @"FatalException";
called = YES;
return YES;
}];
[Bugsnag notify:exception];
});

it(@"invokes the block", ^{
[[expectFutureValue(@(called)) shouldSoon] equal:@YES];
});

it(@"updates report data", ^{
[[expectFutureValue(requestExceptionValue(@"errorClass")) shouldSoon] equal:@"FatalException"];
});
});

describe(@"cancelling a report via notify: with beforeSend block", ^{
__block NSException *exception;
beforeEach(^{
exception = [NSException exceptionWithName:@"failure to launch"
reason:@"no fuel" userInfo:nil];
[[Bugsnag configuration] addBeforeSendBlock:^bool(NSDictionary * _Nonnull rawEventData, BugsnagCrashReport * _Nonnull report) {
return NO;
}];
[Bugsnag notify:exception];
});

it(@"cancels the report", ^{
[[expectFutureValue(request) shouldAfterWait] beNil];
});
});

describe(@"notify:block:", ^{

__block NSException *exception;
Expand Down

0 comments on commit 9795e5d

Please sign in to comment.