Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FBSnapshotTestCaseSwiftTest: FBSnapshotTestCase {
recordMode = false
}

func testExample() {
func testExample() throws {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
view.backgroundColor = UIColor.blue
FBSnapshotVerifyView(view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class iOSSnapshotTestCaseCarthageDemoSwiftTests: FBSnapshotTestCase {
recordMode = false
}

func testExample() {
func testExample() throws {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
view.backgroundColor = UIColor.blue
FBSnapshotVerifyView(view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class iOSSnapshotTestCaseSwiftPMDemoSwiftTests: FBSnapshotTestCase {
recordMode = false
}

func testExample() {
func testExample() throws {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
view.backgroundColor = UIColor.blue
FBSnapshotVerifyView(view)
Expand Down
19 changes: 17 additions & 2 deletions src/iOSSnapshotTestCaseCore/FBSnapshotTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ - (void)setUp
{
[super setUp];
_snapshotController = [[FBSnapshotTestController alloc] initWithTestClass:[self class]];
_removesErrorSuffix = YES;
}

- (void)tearDown
Expand Down Expand Up @@ -236,7 +237,7 @@ - (BOOL)referenceImageRecordedInDirectory:(NSString *)referenceImagesDirectory
{
NSAssert1(_snapshotController, @"%s cannot be called before [super setUp]", __FUNCTION__);
_snapshotController.referenceImagesDirectory = referenceImagesDirectory;
UIImage *referenceImage = [_snapshotController referenceImageForSelector:self.invocation.selector
UIImage *referenceImage = [_snapshotController referenceImageForSelector:[self adjustedCurrentTestSelector]
identifier:identifier
error:errorPtr];

Expand Down Expand Up @@ -286,11 +287,25 @@ - (BOOL)_compareSnapshotOfViewOrLayer:(id)viewOrLayer
_snapshotController.referenceImagesDirectory = referenceImagesDirectory;
_snapshotController.imageDiffDirectory = imageDiffDirectory;
return [_snapshotController compareSnapshotOfViewOrLayer:viewOrLayer
selector:self.invocation.selector
selector:[self adjustedCurrentTestSelector]
identifier:identifier
perPixelTolerance:perPixelTolerance
overallTolerance:overallTolerance
error:errorPtr];
}

- (SEL)adjustedCurrentTestSelector {
SEL selector = self.invocation.selector;
if (!self.removesErrorSuffix || self.invocation.methodSignature.numberOfArguments != 3) {
return selector;
}

NSString *name = NSStringFromSelector(selector);
if ([name hasSuffix:@"AndReturnError:"]) {
return NSSelectorFromString([name stringByReplacingOccurrencesOfString:@"AndReturnError:" withString:@""]);
}

return selector;
}

@end
5 changes: 5 additions & 0 deletions src/iOSSnapshotTestCaseCore/Public/FBSnapshotTestCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (readwrite, nonatomic, assign) BOOL usesDrawViewHierarchyInRect;

/// Whether to remove the "AndReturnError" suffix used when a test `throws` in Swift.
/// This allows to change a test between throwing and not throwing without recording snapshots again.
/// The default is YES.
@property (readwrite, nonatomic, assign) BOOL removesErrorSuffix;

- (void)setUp NS_REQUIRES_SUPER;
- (void)tearDown NS_REQUIRES_SUPER;

Expand Down