Skip to content

Commit

Permalink
Merge pull request #194 from jwutke/improve-pixel-tolerance
Browse files Browse the repository at this point in the history
Improve pixel tolerance support
  • Loading branch information
ashfurrow authored Jan 13, 2020
2 parents 6d3a874 + 5f45e90 commit 2ad7e0c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Nimble_Snapshots/DynamicSize/DynamicSizeSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public func haveValidDynamicSizeSnapshot(named name: String? = nil,
sizes: [String: CGSize],
isDeviceAgnostic: Bool = false,
usesDrawRect: Bool = false,
pixelTolerance: CGFloat? = nil,
tolerance: CGFloat? = nil,
resizeMode: ResizeMode = .frame) -> Predicate<Snapshotable> {
return Predicate.fromDeprecatedClosure { actualExpression, failureMessage in
Expand All @@ -161,6 +162,7 @@ public func haveValidDynamicSizeSnapshot(named name: String? = nil,
actualExpression: actualExpression,
failureMessage: failureMessage,
tolerance: tolerance,
pixelTolerance: pixelTolerance,
isRecord: false,
resizeMode: resizeMode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func combinePredicates<T>(_ predicates: [Predicate<T>],
public func haveValidDynamicTypeSnapshot(named name: String? = nil,
identifier: String? = nil,
usesDrawRect: Bool = false,
pixelTolerance: CGFloat? = nil,
tolerance: CGFloat? = nil,
sizes: [UIContentSizeCategory] = allContentSizeCategories(),
isDeviceAgnostic: Bool = false) -> Predicate<Snapshotable> {
Expand All @@ -53,11 +54,13 @@ public func haveValidDynamicTypeSnapshot(named name: String? = nil,
let predicate: Predicate<Snapshotable>
if isDeviceAgnostic {
predicate = haveValidDeviceAgnosticSnapshot(named: nameWithCategory, identifier: identifier,
usesDrawRect: usesDrawRect, tolerance: tolerance)
usesDrawRect: usesDrawRect, pixelTolerance: pixelTolerance,
tolerance: tolerance)
} else {
predicate = haveValidSnapshot(named: nameWithCategory,
identifier: identifier,
usesDrawRect: usesDrawRect,
pixelTolerance: pixelTolerance,
tolerance: tolerance)
}

Expand Down
9 changes: 7 additions & 2 deletions Nimble_Snapshots/HaveValidSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public func setNimbleTolerance(_ tolerance: CGFloat) {
FBSnapshotTest.sharedInstance.tolerance = tolerance
}

public func setNimblePixelTolerance(_ pixelTolerance: CGFloat) {
FBSnapshotTest.sharedInstance.pixelTolerance = pixelTolerance
}

func getDefaultReferenceDirectory(_ sourceFileName: String) -> String {
if let globalReference = FBSnapshotTest.sharedInstance.referenceImagesDirectory {
return globalReference
Expand Down Expand Up @@ -297,6 +301,7 @@ public func haveValidSnapshot(named name: String? = nil,
public func haveValidDeviceAgnosticSnapshot(named name: String? = nil,
identifier: String? = nil,
usesDrawRect: Bool = false,
pixelTolerance: CGFloat? = nil,
tolerance: CGFloat? = nil) -> Predicate<Snapshotable> {

return Predicate.fromDeprecatedClosure { actualExpression, failureMessage in
Expand All @@ -306,8 +311,8 @@ public func haveValidDeviceAgnosticSnapshot(named name: String? = nil,
}

return performSnapshotTest(name, identifier: identifier, isDeviceAgnostic: true, usesDrawRect: usesDrawRect,
actualExpression: actualExpression,
failureMessage: failureMessage, tolerance: tolerance)
actualExpression: actualExpression, failureMessage: failureMessage,
pixelTolerance: pixelTolerance, tolerance: tolerance)
}
}

Expand Down

0 comments on commit 2ad7e0c

Please sign in to comment.