• Stars
    star
    317
  • Rank 132,216 (Top 3 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 10 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Nimble matchers for FBSnapshotTestCase.

GitHub Actions CI Cocoapods compatible SPM compatible Carthage compatible License

Nimble matchers for iOSSnapshotTestCase. Originally derived from Expecta Matchers for FBSnapshotTestCase.

Installing

CocoaPods

You need to be using CocoaPods 0.36 Beta 1 or higher. Your Podfile should look something like the following.

platform :ios, '10.0'

source 'https://github.com/CocoaPods/Specs.git'

# Whichever pods you need for your app go here.

target 'YOUR_APP_NAME_HERE_Tests', :exclusive => true do
  pod 'Nimble-Snapshots'
  pod 'Quick' # if you want to use it with Quick
end

Then run:

$ pod install

Carthage

You need to be using Carthage 0.18 or higher. Your Cartfile (or Cartfile.private) should look something like the following.

github "Quick/Quick" ~> 4.0
github "Quick/Nimble" ~> 9.2
github "uber/ios-snapshot-test-case" "8.0.0"
github "ashfurrow/Nimble-Snapshots"

Then run:

$ carthage bootstrap --use-xcframeworks --platform iOS

Swift Package Manager

To add Nimble-Snapshots as a dependency, you have to add it to the dependencies of your Package.swift file and refer to that dependency in your target.

import PackageDescription
let package = Package(
    name: "<Your Product Name>",
    dependencies: [
       .package(url: "https://github.com/ashfurrow/Nimble-Snapshots", .upToNextMajor(from: "9.0.0"))
    ],
    targets: [
        .target(
            name: "<Your Target Name>",
            dependencies: ["Nimble-Snapshots"]),
    ]
)

Use

Your tests will look something like the following.

import Quick
import Nimble
import Nimble_Snapshots
import UIKit

class MySpec: QuickSpec {
    override func spec() {
        describe("in some context") {
            it("has valid snapshot") {
                let view = ... // some view you want to test
                expect(view).to( haveValidSnapshot() )
            }
        }
    }
}

There are some options for testing the validity of snapshots. Snapshots can be given a name:

expect(view).to( haveValidSnapshot(named: "some custom name") )

We also have a prettier syntax for custom-named snapshots:

expect(view) == snapshot("some custom name")

To record snapshots, just replace haveValidSnapshot() with recordSnapshot() and haveValidSnapshot(named:) with recordSnapshot(named:). We also have a handy emoji operator.

📷(view)
📷(view, "some custom name")

By default, this pod will put the reference images inside a ReferenceImages directory; we try to put this in a place that makes sense (inside your unit tests directory). If we can't figure it out, or if you want to use your own directory instead, call setNimbleTestFolder() with the name of the directory in your unit test's path that we should use. For example, if the tests are in App/AppTesting/, you can call it with AppTesting.

If you have any questions or run into any trouble, feel free to open an issue on this repo.

Dynamic Type

Testing Dynamic Type manually is boring and no one seems to remember doing it when implementing a view/screen, so you can have snapshot tests according to content size categories.

In order to use Dynamic Type testing, make sure to provide a valid Host Application in your testing target.

Then you can use the haveValidDynamicTypeSnapshot and recordDynamicTypeSnapshot matchers:

// expect(view).to(recordDynamicTypeSnapshot()
expect(view).to(haveValidDynamicTypeSnapshot())

// You can also just test some sizes:
expect(view).to(haveValidDynamicTypeSnapshot(sizes: [UIContentSizeCategoryExtraLarge]))

// If you prefer the == syntax, we got you covered too:
expect(view) == dynamicTypeSnapshot()
expect(view) == dynamicTypeSnapshot(sizes: [UIContentSizeCategoryExtraLarge])

Note that this will post an UIContentSizeCategoryDidChangeNotification, so your views/view controllers need to observe that and update themselves.

For more info on usage, check out the dynamic type tests.

Dynamic Size

Testing the same view with many sizes is easy but error prone. It easy to fix one test on change and forget the others. For this we create a easy way to tests all sizes at same time.

You can use the new haveValidDynamicSizeSnapshot and recordDynamicSizeSnapshot matchers to test multiple sizes at once:

let sizes = ["SmallSize": CGSize(width: 44, height: 44),
"MediumSize": CGSize(width: 88, height: 88),
"LargeSize": CGSize(width: 132, height: 132)]

// expect(view).to(recordDynamicSizeSnapshot(sizes: sizes))
expect(view).to(haveValidDynamicSizeSnapshot(sizes: sizes))

// You can also just test some sizes:
expect(view).to(haveValidDynamicSizeSnapshot(sizes: sizes))

// If you prefer the == syntax, we got you covered too:
expect(view) == snapshot(sizes: sizes)
expect(view) == snapshot(sizes: sizes)

By default, the size will be set on the view using the frame property. To change this behavior you can use the ResizeMode enum:

public enum ResizeMode {
  case frame
  case constrains
  case block(resizeBlock: (UIView, CGSize) -> Void)
  case custom(viewResizer: ViewResizer)
}

To use the enum you can expect(view) == dynamicSizeSnapshot(sizes: sizes, resizeMode: newResizeMode). For custom behavior you can use ResizeMode.block. The block will be call on every resize. Or you can implement the ViewResizer protocol and resize yourself. The custom behavior can be used to record the views too.

For more info on usage, check the dynamic sizes tests.

More Repositories

1

C-41

C-41 is an application to help people develop film at home by providing a series of "recipes" for photographers to use.
Objective-C
2,059
star
2

xcode-hardware-performance

Results from running Xcode on a non-trivial open source project using various Macs
1,134
star
3

FunctionalReactivePixels

A demonstration of how to use FRP with ReactiveCocoa in an iOS context using the 500px API.
Objective-C
702
star
4

AFTabledCollectionView

How to display a UICollectionView within a UITableViewCell
Objective-C
549
star
5

UICollectionView-NSFetchedResultsController

How to use UICollectionView with NSFetchedResultsController
439
star
6

Collection-View-in-a-Table-View-Cell

Sample code for my tutorial
Swift
393
star
7

danger-ruby-swiftlint

A Danger plugin for SwiftLint.
Ruby
203
star
8

UICollectionViewFlowLayoutExample

UICollectionViewFlowLayout Example
Objective-C
198
star
9

ARCollectionViewMasonryLayout

Objective-C
184
star
10

danger-swiftlint

Automated Swift linting on pull requests
Swift
149
star
11

ASHSpringyCollectionView

Objective-C
140
star
12

second_curtain

Upload failing iOS snapshot tests cases to S3
Objective-C
130
star
13

blog

This is my website, a static site generated with Gatsby.
MDX
112
star
14

UICollectionViewExample

Objective-C
100
star
15

LongPlay

Long Play
Objective-C
93
star
16

AFImageDownloader

Downloads JPEG images asynchronously and decompresses them on a background thread.
Objective-C
88
star
17

Forgeries

Helper methods for testing iOS code
Objective-C
83
star
18

yourfirstswiftapp

Swift
66
star
19

FunctionalReactiveAwesome

Sample Code for AltConf 2015 talk on FRP 🎉
Swift
57
star
20

NSFetchedResultsController-MVVM

NSFetchedResultsController using MVVM
Objective-C
55
star
21

Swift-RAC-Macros

(Temporary) Replacements for the RAC and RACObserve macros in Swift
Swift
54
star
22

UIView-BooleanAnimations

Perform changes to UI with or without animations, depending on a variable.
Objective-C
47
star
23

danger-rubocop

Danger plugin for Rubocop
Ruby
43
star
24

peerlab.community

Worldwide directory of peer labs, instructions on starting your own.
HTML
43
star
25

DOOM-CPU-Monitor

CPU monitor that displays how much load your CPU is under via the dying face from the video game DOOM.
Objective-C
42
star
26

Newtonian-UICollectionView

Objective-C
40
star
27

pragma-2015-rx-workshop

Materials for my Pragma 2015 workshop on reactive programming
Swift
37
star
28

Your-First-iOS-App

Sample code for "Your First iOS App", the book
Objective-C
35
star
29

Angular

Making an Othello/Reversi clone
Objective-C
34
star
30

NSSpain2014

Annotated playground for my presentation at NSSpain 2014
Swift
32
star
31

MBLTDev

Sample code for MBLTDev
Swift
31
star
32

Bleach

iOS 9 app extension to block ads
27
star
33

Swift-Course

A small demo of Swift for newcomers
Swift
26
star
34

AFActivityIndicatorView

A ground-up, home-made implementation of UIActivityIndicatorView
Objective-C
24
star
35

PXSaver

Super hacky screen saver for OS X I wrote in a few hours while drinking
Objective-C
23
star
36

FunctionalReactiveDemo

A small demonstration of how to use ReactiveCocoa in iOS applications
Objective-C
23
star
37

ReactiveMoya

Swift
22
star
38

UIAlertController-Example

A demonstration of how to use Apple's hot new UIAlertController class
Swift
20
star
39

500px-API-Test

500px recently opened their API to the public. I want to try it out.
19
star
40

Haste

NSTimer Extension for Swift
Swift
18
star
41

twelease

🗣 A small Express server for automatically tweeting about new git tags
TypeScript
18
star
42

cocoapods-superdeintegrate

💣
Ruby
16
star
43

WhiskeyList

Objective-C
15
star
44

cocoapods-chillax-swift

CocoaPods plugin for disabling compiler optimizations for specific pods
Ruby
13
star
45

RACAlertAction

UIAlertAction subclass with support for ReactiveCocoa
Objective-C
13
star
46

hasValue

Reimplementing hasValue in Swift.
Ruby
11
star
47

UIView-ShinkTo

Shrinks any UIView instance to a point in a view similar to the iOS Mail app
Objective-C
11
star
48

FoundationOperators

Operators overloading for the Foundation (so we can finally just nsnumber + nsnumber)
Swift
10
star
49

canadian-measurements

Since moving to Europe, I get asked a lot about Canada's adoption of the metric system. Here it is.
9
star
50

production-swift-code

Sample code for my upcoming book
8
star
51

stylesheet

My custom user stylesheet for making the web less shitty.
CSS
7
star
52

EuroTrip-2015

We'll be in Europe for most of May. This repo is used to organize our travel plans.
7
star
53

cornell-rx-materials

Swift
6
star
54

category-theory-exercises

Swift
6
star
55

buggy

A Slackbot that makes it easy to organize bug bashes
Ruby
6
star
56

UIApplication-Keychain-Access

This is a library to abstract access to the keychain on iOS devices.
5
star
57

graphql-depth-limit

Limit the complexity of your GraphQL queries based on depth.
JavaScript
5
star
58

trumpsoundboard

HTML
4
star
59

Simple-OAuth

Simple Objective-C OAuth
Objective-C
4
star
60

FunctionalDemo

A short demo of functional programming on iOS using RXCollections
Objective-C
4
star
61

tsnyc-tslint-rules

Materials for my October 30th talk at TypeScript NYC
TypeScript
3
star
62

task-list-checker

JavaScript
3
star
63

pride.watch

I'm going to make a gallery of Apple Watch watch faces that are pride flags ¯\_(ツ)_/¯
HTML
3
star
64

peril-settings

Settings for my personal Peril server
TypeScript
2
star
65

static-keys-test

Objective-C
2
star
66

screensaver

JavaScript
2
star
67

FITC-SCREENS

Demo repo for FITC SCREENS
2
star
68

test-repo

test repo for twelease
2
star
69

500px-Behind-The-Scenes

Source Materials for the 500px Behind The Scenes FITC Screens Presentation
2
star
70

ashfurrow

This is the readme repo for my GitHub profile.
2
star
71

ScienceDog

A simple Haskell web app written using the Happstack-lite web framework
1
star
72

mastodon-technology

Ruby
1
star
73

hfm-exercises

My solutions to the Haskell-for-Mac Exercises
Haskell
1
star
74

TumblrSharing

Simple sharing to Tumblr's v2 OAuth API
Objective-C
1
star
75

colourschemes

Some Xcode 4+ colour schemes I like
1
star
76

minsk

Code from Mobile Developer & Business Day
Swift
1
star
77

tslint-playground

A playground repo for me to experiment with writing custom TSLint rules
TypeScript
1
star
78

AnyoneCanLearn

Core beliefs, resources, and planning for the organization.
1
star
79

empty-podspec

Repo for an empty, modifiable podspec. Pay this repo no attention.
Ruby
1
star
80

ios-13-uiimage-crash

Objective-C
1
star