Skip to content
This repository has been archived by the owner on Jan 2, 2020. It is now read-only.

Commit

Permalink
Use OCHamcrest's throwsException matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
jonreid committed Dec 24, 2015
1 parent 9f7d763 commit 848f226
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
2 changes: 2 additions & 0 deletions Sample/MockUIAlertControllerSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
);
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = "org.qualitycoding.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = MockUIAlertControllerSampleTests;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MockUIAlertControllerSample.app/MockUIAlertControllerSample";
Expand All @@ -421,6 +422,7 @@
);
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = "org.qualitycoding.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = MockUIAlertControllerSampleTests;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MockUIAlertControllerSample.app/MockUIAlertControllerSample";
Expand Down
38 changes: 10 additions & 28 deletions Sample/Tests/QCOMockAlertVerifierTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

#import "ViewController.h"

@import XCTest;

#define HC_SHORTHAND
#import <OCHamcrestIOS/OCHamcrestIOS.h>
@import XCTest;


@interface QCOMockAlertVerifierTests : XCTestCase
Expand All @@ -28,26 +26,18 @@ - (void)testShowAlert_TryingToGetStyleForNonexistentButton_ShouldThrowInternalIn
{
QCOMockAlertVerifier *alertVerifier = [[QCOMockAlertVerifier alloc] init];
[sut showAlert:nil];

XCTAssertThrowsSpecificNamed(
[alertVerifier styleForButtonWithTitle:@"NO SUCH BUTTON"],
NSException,
NSInternalInconsistencyException);

assertThat(^{ [alertVerifier styleForButtonWithTitle:@"NO SUCH BUTTON"]; },
throwsException(hasProperty(@"name", NSInternalInconsistencyException)));
}

- (void)testShowAlert_TryingToGetStyleForNonexistentButton_ShouldThrowExceptionWithReason
{
QCOMockAlertVerifier *alertVerifier = [[QCOMockAlertVerifier alloc] init];
[sut showAlert:nil];

@try
{
[alertVerifier styleForButtonWithTitle:@"NO SUCH BUTTON"];
}
@catch (NSException *exception)
{
assertThat(exception.reason, is(@"Button not found"));
}
assertThat(^{ [alertVerifier styleForButtonWithTitle:@"NO SUCH BUTTON"]; },
throwsException(hasProperty(@"reason", @"Button not found")));
}

- (void)testShowAlert_TryingToExecuteActionForNonexistentButton_ShouldThrowInternalInconsistency
Expand All @@ -56,25 +46,17 @@ - (void)testShowAlert_TryingToExecuteActionForNonexistentButton_ShouldThrowInter

[sut showAlert:nil];

XCTAssertThrowsSpecificNamed(
[alertVerifier executeActionForButtonWithTitle:@"NO SUCH BUTTON"],
NSException,
NSInternalInconsistencyException);
assertThat(^{ [alertVerifier executeActionForButtonWithTitle:@"NO SUCH BUTTON"]; },
throwsException(hasProperty(@"name", NSInternalInconsistencyException)));
}

- (void)testShowAlert_TryingToExecuteActionForNonexistentButton_ShouldThrowExceptionWithReason
{
QCOMockAlertVerifier *alertVerifier = [[QCOMockAlertVerifier alloc] init];
[sut showAlert:nil];

@try
{
[alertVerifier executeActionForButtonWithTitle:@"NO SUCH BUTTON"];
}
@catch (NSException *exception)
{
assertThat(exception.reason, is(@"Button not found"));
}
assertThat(^{ [alertVerifier executeActionForButtonWithTitle:@"NO SUCH BUTTON"]; },
throwsException(hasProperty(@"reason", @"Button not found")));
}

@end

0 comments on commit 848f226

Please sign in to comment.