forked from ashfurrow/Nimble-Snapshots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrettySyntax.swift
48 lines (38 loc) · 1.22 KB
/
PrettySyntax.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import Nimble
// MARK: - Nicer syntax using == operator
public struct Snapshot {
let name: String?
let record: Bool
init(name: String?, record: Bool) {
self.name = name
self.record = record
}
}
public func snapshot(_ name: String? = nil) -> Snapshot {
return Snapshot(name: name, record: false)
}
public func recordSnapshot(_ name: String? = nil) -> Snapshot {
return Snapshot(name: name, record: true)
}
public func ==(lhs: Expectation<Snapshotable>, rhs: Snapshot) {
if let name = rhs.name {
if rhs.record {
lhs.to(recordSnapshot(named: name))
} else {
lhs.to(haveValidSnapshot(named: name))
}
} else {
if rhs.record {
lhs.to(recordSnapshot())
} else {
lhs.to(haveValidSnapshot())
}
}
}
// MARK: - Nicer syntax using emoji
public func 📷(_ snapshottable: Snapshotable, file: FileString = #file, line: UInt = #line) {
expect(snapshottable, file: file, line: line).to(recordSnapshot())
}
public func 📷(_ snapshottable: Snapshotable, named name: String, file: FileString = #file, line: UInt = #line) {
expect(snapshottable, file: file, line: line).to(recordSnapshot(named: name))
}