Skip to content

Commit

Permalink
Nimble 12 changed the Expectation API
Browse files Browse the repository at this point in the history
  • Loading branch information
younata committed Apr 14, 2023
1 parent 3582818 commit 668be20
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cartfile.resolved
@@ -1,2 +1,2 @@
github "Quick/Nimble" "v11.0.0"
github "Quick/Nimble" "v12.0.0"
github "uber/ios-snapshot-test-case" "444c218adaa6a99ba0536b4ec9ad5500047d9051"
2 changes: 1 addition & 1 deletion Nimble-Snapshots.podspec
Expand Up @@ -22,7 +22,7 @@ Pod::Spec.new do |s|
"Nimble_Snapshots/DynamicType/*.{swift,m,h}",
"Nimble_Snapshots/DynamicSize/*.{swift}"
ss.dependency "iOSSnapshotTestCase", "~> 8.0"
ss.dependency "Nimble", "~> 11.0"
ss.dependency "Nimble", "~> 12.0"
end

# for compatibiliy reasons
Expand Down
16 changes: 15 additions & 1 deletion Nimble_Snapshots/DynamicSize/DynamicSizeSnapshot.swift
Expand Up @@ -264,7 +264,7 @@ public func recordDynamicSizeSnapshot<T: Snapshotable>(named name: String? = nil
}
}

public func ==<Expectation: Nimble.Expectation>(lhs: Expectation, rhs: DynamicSizeSnapshot) where Expectation.Value: Snapshotable {
public func ==(lhs: Nimble.SyncExpectation<Snapshotable>, rhs: DynamicSizeSnapshot) {
if rhs.record {
lhs.to(recordDynamicSizeSnapshot(named: rhs.name,
identifier: rhs.identifier,
Expand All @@ -277,3 +277,17 @@ public func ==<Expectation: Nimble.Expectation>(lhs: Expectation, rhs: DynamicSi
resizeMode: rhs.resizeMode))
}
}

public func ==(lhs: Nimble.AsyncExpectation<Snapshotable>, rhs: DynamicSizeSnapshot) async {
if rhs.record {
await lhs.to(recordDynamicSizeSnapshot(named: rhs.name,
identifier: rhs.identifier,
sizes: rhs.sizes,
resizeMode: rhs.resizeMode))
} else {
await lhs.to(haveValidDynamicSizeSnapshot(named: rhs.name,
identifier: rhs.identifier,
sizes: rhs.sizes,
resizeMode: rhs.resizeMode))
}
}
19 changes: 18 additions & 1 deletion Nimble_Snapshots/DynamicType/PrettyDynamicTypeSyntax.swift
Expand Up @@ -41,7 +41,7 @@ public func recordDynamicTypeSnapshot(_ name: String? = nil,
deviceAgnostic: deviceAgnostic)
}

public func ==<Expectation: Nimble.Expectation>(lhs: Expectation, rhs: DynamicTypeSnapshot) where Expectation.Value: Snapshotable {
public func ==(lhs: Nimble.SyncExpectation<Snapshotable>, rhs: DynamicTypeSnapshot) {
if let name = rhs.name {
if rhs.record {
lhs.to(recordDynamicTypeSnapshot(named: name, sizes: rhs.sizes, isDeviceAgnostic: rhs.deviceAgnostic))
Expand All @@ -57,3 +57,20 @@ public func ==<Expectation: Nimble.Expectation>(lhs: Expectation, rhs: DynamicTy
}
}
}

public func ==(lhs: Nimble.AsyncExpectation<Snapshotable>, rhs: DynamicTypeSnapshot) async {
if let name = rhs.name {
if rhs.record {
await lhs.to(recordDynamicTypeSnapshot(named: name, sizes: rhs.sizes, isDeviceAgnostic: rhs.deviceAgnostic))
} else {
await lhs.to(haveValidDynamicTypeSnapshot(named: name, sizes: rhs.sizes, isDeviceAgnostic: rhs.deviceAgnostic))
}

} else {
if rhs.record {
await lhs.to(recordDynamicTypeSnapshot(sizes: rhs.sizes, isDeviceAgnostic: rhs.deviceAgnostic))
} else {
await lhs.to(haveValidDynamicTypeSnapshot(sizes: rhs.sizes, isDeviceAgnostic: rhs.deviceAgnostic))
}
}
}
10 changes: 9 additions & 1 deletion Nimble_Snapshots/PrettySyntax.swift
Expand Up @@ -28,14 +28,22 @@ public func recordSnapshot(_ name: String? = nil,
return Snapshot(name: name, identifier: identifier, record: true, usesDrawRect: usesDrawRect)
}

public func ==<Expectation: Nimble.Expectation>(lhs: Expectation, rhs: Snapshot) where Expectation.Value: Snapshotable {
public func ==(lhs: Nimble.SyncExpectation<Snapshotable>, rhs: Snapshot) {
if rhs.record {
lhs.to(recordSnapshot(named: rhs.name, identifier: rhs.identifier, usesDrawRect: rhs.usesDrawRect))
} else {
lhs.to(haveValidSnapshot(named: rhs.name, identifier: rhs.identifier, usesDrawRect: rhs.usesDrawRect))
}
}

public func ==(lhs: Nimble.AsyncExpectation<Snapshotable>, rhs: Snapshot) async {
if rhs.record {
await lhs.to(recordSnapshot(named: rhs.name, identifier: rhs.identifier, usesDrawRect: rhs.usesDrawRect))
} else {
await lhs.to(haveValidSnapshot(named: rhs.name, identifier: rhs.identifier, usesDrawRect: rhs.usesDrawRect))
}
}

// MARK: - Nicer syntax using emoji

// swiftlint:disable:next identifier_name
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Quick/Nimble.git",
"state" : {
"revision" : "b7f6c49acdb247e3158198c5448b38c3cc595533",
"version" : "11.2.1"
"revision" : "ecade0f20e58e55ba3e5f110b701dad88fd40170",
"version" : "12.0.0"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Expand Up @@ -16,7 +16,7 @@ let package = Package(
.package(url: "https://github.com/uber/ios-snapshot-test-case.git",
.upToNextMajor(from: "8.0.0")),
.package(url: "https://github.com/Quick/Nimble.git",
.upToNextMajor(from: "11.0.0"))
.upToNextMajor(from: "12.0.0"))
],
targets: [
.target(
Expand Down

0 comments on commit 668be20

Please sign in to comment.