Skip to content

Commit 3ccde63

Browse files
authored
Updated interface (#762)
* Updated interface Let's introduce a more streamlined version of `assertSnapshot` that takes an `of` instead of a `matching` parameter: ```diff -assertSnapshot(matching: value, as: .json) +assertSnapshot(of: value, as: .json) ``` While `matching` read OK, it is also a little confusing, since it sounds like the value itself is a snapshot, but the helper is really taking a snapshot _of_ the value to be compared. We'll keep the old version around for a long time as a soft deprecation, but whenever we get close to realizing a 2.0 we can make a harder break. * wip
1 parent dc46eeb commit 3ccde63

File tree

7 files changed

+408
-300
lines changed

7 files changed

+408
-300
lines changed

Documentation/Available-Snapshot-Strategies.md

+53-53
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ A snapshot strategy that captures a value's textual description from `String`'s
6666
#### Example:
6767

6868
``` swift
69-
assertSnapshot(matching: user, as: .description)
69+
assertSnapshot(of: user, as: .description)
7070
```
7171

7272
Records:
@@ -90,7 +90,7 @@ You can hook into how an instance of a type is rendered in this strategy by conf
9090
#### Example:
9191

9292
``` swift
93-
assertSnapshot(matching: user, as: .dump)
93+
assertSnapshot(of: user, as: .dump)
9494
```
9595

9696
Records:
@@ -124,10 +124,10 @@ A snapshot strategy for comparing layers based on pixel equality.
124124

125125
``` swift
126126
// Match reference perfectly.
127-
assertSnapshot(matching: layer, as: .image)
127+
assertSnapshot(of: layer, as: .image)
128128

129129
// Allow for a 1% pixel difference.
130-
assertSnapshot(matching: layer, as: .image(precision: 0.99))
130+
assertSnapshot(of: layer, as: .image(precision: 0.99))
131131
```
132132

133133
## CaseIterable
@@ -160,7 +160,7 @@ enum Direction: String, CaseIterable {
160160
}
161161

162162
assertSnapshot(
163-
matching: { $0.rotatedLeft },
163+
of: { $0.rotatedLeft },
164164
as: Snapshotting<Direction, String>.func(into: .description)
165165
)
166166
```
@@ -194,10 +194,10 @@ A snapshot strategy for comparing paths based on pixel equality.
194194

195195
``` swift
196196
// Match reference perfectly.
197-
assertSnapshot(matching: path, as: .image)
197+
assertSnapshot(of: path, as: .image)
198198

199199
// Allow for a 1% pixel difference.
200-
assertSnapshot(matching: path, as: .image(precision: 0.99))
200+
assertSnapshot(of: path, as: .image(precision: 0.99))
201201
```
202202

203203
### `.elementsDescription`
@@ -216,10 +216,10 @@ A snapshot strategy for comparing paths based on a description of their elements
216216

217217
``` swift
218218
// Match reference perfectly.
219-
assertSnapshot(matching: path, as: .elementsDescription)
219+
assertSnapshot(of: path, as: .elementsDescription)
220220

221221
// Match reference as formatted by formatter.
222-
assertSnapshot(matching: path, as: .elementsDescription(numberFormatter: NumberFormatter()))
222+
assertSnapshot(of: path, as: .elementsDescription(numberFormatter: NumberFormatter()))
223223
```
224224

225225
## Data
@@ -233,7 +233,7 @@ A snapshot strategy for comparing bare binary data.
233233
#### Example:
234234

235235
``` swift
236-
assertSnapshot(matching: data, as: .data)
236+
assertSnapshot(of: data, as: .data)
237237
```
238238

239239
## Encodable
@@ -253,7 +253,7 @@ A snapshot strategy for comparing encodable structures based on their JSON repre
253253
#### Example:
254254

255255
``` swift
256-
assertSnapshot(matching: user, as: .json)
256+
assertSnapshot(of: user, as: .json)
257257
```
258258

259259
Records:
@@ -279,7 +279,7 @@ A snapshot strategy for comparing encodable structures based on their property l
279279
#### Example:
280280

281281
``` swift
282-
assertSnapshot(matching: user, as: .plist)
282+
assertSnapshot(of: user, as: .plist)
283283
```
284284

285285
Records:
@@ -319,10 +319,10 @@ A snapshot strategy for comparing paths based on pixel equality.
319319

320320
``` swift
321321
// Match reference perfectly.
322-
assertSnapshot(matching: path, as: .image)
322+
assertSnapshot(of: path, as: .image)
323323

324324
// Allow for a 1% pixel difference.
325-
assertSnapshot(matching: path, as: .image(precision: 0.99))
325+
assertSnapshot(of: path, as: .image(precision: 0.99))
326326
```
327327

328328
### `.elementsDescription`
@@ -341,10 +341,10 @@ A snapshot strategy for comparing paths based on a description of their elements
341341

342342
``` swift
343343
// Match reference perfectly.
344-
assertSnapshot(matching: path, as: .elementsDescription)
344+
assertSnapshot(of: path, as: .elementsDescription)
345345

346346
// Match reference as formatted by formatter.
347-
assertSnapshot(matching: path, as: .elementsDescription(numberFormatter: NumberFormatter()))
347+
assertSnapshot(of: path, as: .elementsDescription(numberFormatter: NumberFormatter()))
348348
```
349349

350350
## NSImage
@@ -367,10 +367,10 @@ A snapshot strategy for comparing images based on pixel equality.
367367

368368
``` swift
369369
// Match reference as-is.
370-
assertSnapshot(matching: image, as: .image)
370+
assertSnapshot(of: image, as: .image)
371371

372372
// Allow for a 1% pixel difference.
373-
assertSnapshot(matching: image, as: .image(precision: 0.99))
373+
assertSnapshot(of: image, as: .image(precision: 0.99))
374374
```
375375

376376
## NSView
@@ -401,14 +401,14 @@ A snapshot strategy for comparing layers based on pixel equality.
401401

402402
``` swift
403403
// Match reference as-is.
404-
assertSnapshot(matching: view, as: .image)
404+
assertSnapshot(of: view, as: .image)
405405

406406
// Allow for a 1% pixel difference.
407-
assertSnapshot(matching: view, as: .image(precision: 0.99))
407+
assertSnapshot(of: view, as: .image(precision: 0.99))
408408

409409
// Render at a certain size.
410410
assertSnapshot(
411-
matching: view,
411+
of: view,
412412
as: .image(size: .init(width: 44, height: 44))
413413
)
414414
```
@@ -422,7 +422,7 @@ A snapshot strategy for comparing views based on a recursive description of thei
422422
#### Example
423423

424424
``` swift
425-
assertSnapshot(matching: view, as: .recursiveDescription)
425+
assertSnapshot(of: view, as: .recursiveDescription)
426426
```
427427

428428
Records:
@@ -458,14 +458,14 @@ A snapshot strategy for comparing layers based on pixel equality.
458458

459459
``` swift
460460
// Match reference as-is.
461-
assertSnapshot(matching: vc, as: .image)
461+
assertSnapshot(of: vc, as: .image)
462462

463463
// Allow for a 1% pixel difference.
464-
assertSnapshot(matching: vc, as: .image(precision: 0.99))
464+
assertSnapshot(of: vc, as: .image(precision: 0.99))
465465

466466
// Render at a certain size.
467467
assertSnapshot(
468-
matching: vc,
468+
of: vc,
469469
as: .image(size: .init(width: 640, height: 480))
470470
)
471471
```
@@ -481,7 +481,7 @@ A snapshot strategy for comparing view controller views based on a recursive des
481481
#### Example
482482

483483
``` swift
484-
assertSnapshot(matching: vc, as: .recursiveDescription)
484+
assertSnapshot(of: vc, as: .recursiveDescription)
485485
```
486486

487487
Records:
@@ -515,7 +515,7 @@ A snapshot strategy for comparing SceneKit scenes based on pixel equality.
515515

516516
``` swift
517517
assertSnapshot(
518-
matching: scene,
518+
of: scene,
519519
as: .image(size: .init(width: 640, height: 480))
520520
)
521521
```
@@ -544,7 +544,7 @@ A snapshot strategy for comparing SpriteKit scenes based on pixel equality.
544544

545545
``` swift
546546
assertSnapshot(
547-
matching: scene,
547+
of: scene,
548548
as: .image(size: .init(width: 640, height: 480))
549549
)
550550
```
@@ -564,7 +564,7 @@ A snapshot strategy for comparing strings based on equality.
564564
#### Example:
565565

566566
``` swift
567-
assertSnapshot(matching: htmlString, as: .lines)
567+
assertSnapshot(of: htmlString, as: .lines)
568568
```
569569

570570
## UIBezierPath
@@ -587,10 +587,10 @@ A snapshot strategy for comparing paths based on pixel equality.
587587

588588
``` swift
589589
// Match reference perfectly.
590-
assertSnapshot(matching: path, as: .image)
590+
assertSnapshot(of: path, as: .image)
591591

592592
// Allow for a 1% pixel difference.
593-
assertSnapshot(matching: path, as: .image(precision: 0.99))
593+
assertSnapshot(of: path, as: .image(precision: 0.99))
594594
```
595595

596596
### `.elementsDescription`
@@ -609,10 +609,10 @@ A snapshot strategy for comparing paths based on a description of their elements
609609

610610
``` swift
611611
// Match reference perfectly.
612-
assertSnapshot(matching: path, as: .elementsDescription)
612+
assertSnapshot(of: path, as: .elementsDescription)
613613

614614
// Match reference as formatted by formatter.
615-
assertSnapshot(matching: path, as: .elementsDescription(numberFormatter: NumberFormatter()))
615+
assertSnapshot(of: path, as: .elementsDescription(numberFormatter: NumberFormatter()))
616616
```
617617

618618
## UIImage
@@ -635,10 +635,10 @@ A snapshot strategy for comparing images based on pixel equality.
635635

636636
``` swift
637637
// Match reference as-is.
638-
assertSnapshot(matching: image, as: .image)
638+
assertSnapshot(of: image, as: .image)
639639

640640
// Allow for a 1% pixel difference.
641-
assertSnapshot(matching: image, as: .image(precision: 0.99))
641+
assertSnapshot(of: image, as: .image(precision: 0.99))
642642
```
643643

644644
## UIView
@@ -677,20 +677,20 @@ A snapshot strategy for comparing layers based on pixel equality.
677677

678678
``` swift
679679
// Match reference as-is.
680-
assertSnapshot(matching: view, as: .image)
680+
assertSnapshot(of: view, as: .image)
681681

682682
// Allow for a 1% pixel difference.
683-
assertSnapshot(matching: view, as: .image(precision: 0.99))
683+
assertSnapshot(of: view, as: .image(precision: 0.99))
684684

685685
// Render at a certain size.
686686
assertSnapshot(
687-
matching: view,
687+
of: view,
688688
as: .image(size: .init(width: 44, height: 44))
689689
)
690690

691691
// Render with a horizontally-compact size class.
692692
assertSnapshot(
693-
matching: view,
693+
of: view,
694694
as: .image(traits: .init(horizontalSizeClass: .regular))
695695
)
696696
```
@@ -715,13 +715,13 @@ A snapshot strategy for comparing views based on a recursive description of thei
715715

716716
``` swift
717717
// Layout on the current device.
718-
assertSnapshot(matching: view, as: .recursiveDescription)
718+
assertSnapshot(of: view, as: .recursiveDescription)
719719

720720
// Layout with a certain size.
721-
assertSnapshot(matching: view, as: .recursiveDescription(size: .init(width: 22, height: 22)))
721+
assertSnapshot(of: view, as: .recursiveDescription(size: .init(width: 22, height: 22)))
722722

723723
// Layout with a certain trait collection.
724-
assertSnapshot(matching: view, as: .recursiveDescription(traits: .init(horizontalSizeClass: .regular)))
724+
assertSnapshot(of: view, as: .recursiveDescription(traits: .init(horizontalSizeClass: .regular)))
725725
```
726726

727727
Records:
@@ -744,7 +744,7 @@ A snapshot strategy for comparing view controllers based on their embedded contr
744744
#### Example
745745

746746
``` swift
747-
assertSnapshot(matching: vc, as: .hierarchy)
747+
assertSnapshot(of: vc, as: .hierarchy)
748748
```
749749

750750
Records:
@@ -802,28 +802,28 @@ A snapshot strategy for comparing layers based on pixel equality.
802802

803803
``` swift
804804
// Match reference as-is.
805-
assertSnapshot(matching: vc, as: .image)
805+
assertSnapshot(of: vc, as: .image)
806806

807807
// Allow for a 1% pixel difference.
808-
assertSnapshot(matching: vc, as: .image(precision: 0.99))
808+
assertSnapshot(of: vc, as: .image(precision: 0.99))
809809

810810
// Render as if on a certain device.
811-
assertSnapshot(matching: vc, as: .image(on: .iPhoneX(.portrait)))
811+
assertSnapshot(of: vc, as: .image(on: .iPhoneX(.portrait)))
812812

813813
// Render at a certain size.
814814
assertSnapshot(
815-
matching: vc,
815+
of: vc,
816816
as: .image(size: .init(width: 375, height: 667))
817817
)
818818

819819
// Render with a horizontally-compact size class.
820820
assertSnapshot(
821-
matching: vc,
821+
of: vc,
822822
as: .image(traits: .init(horizontalSizeClass: .compact))
823823
)
824824

825825
// Match reference as-is.
826-
assertSnapshot(matching: vc, as: .image)
826+
assertSnapshot(of: vc, as: .image)
827827
```
828828

829829
**See also**: [`UIView`](#uiview).
@@ -852,10 +852,10 @@ A snapshot strategy for comparing view controller views based on a recursive des
852852

853853
``` swift
854854
// Layout on the current device.
855-
assertSnapshot(matching: vc, as: .recursiveDescription)
855+
assertSnapshot(of: vc, as: .recursiveDescription)
856856

857857
// Layout as if on a certain device.
858-
assertSnapshot(matching: vc, as: .recursiveDescription(on: .iPhoneSe(.portrait)))
858+
assertSnapshot(of: vc, as: .recursiveDescription(on: .iPhoneSe(.portrait)))
859859
```
860860

861861
Records:
@@ -878,7 +878,7 @@ A snapshot strategy for comparing requests based on a cURL representation.
878878
#### Example:
879879

880880
``` swift
881-
assertSnapshot(matching: request, as: .curl)
881+
assertSnapshot(of: request, as: .curl)
882882
```
883883

884884
Records:
@@ -900,7 +900,7 @@ A snapshot strategy for comparing requests based on raw equality.
900900
#### Example:
901901

902902
``` swift
903-
assertSnapshot(matching: request, as: .raw)
903+
assertSnapshot(of: request, as: .raw)
904904
```
905905

906906
Records:

0 commit comments

Comments
 (0)