/Nimble-Snapshots

Nimble matchers for FBSnapshotTestCase

Primary LanguageSwiftMIT LicenseMIT

Build Status

Nimble-Snapshots

Nimble matchers for FBSnapshotTestCase. Highly derivative of Expecta Matchers for FBSnapshotTestCase.

Installing

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

platform :ios, '8.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'
end

Then run pod install.

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", { () -> () in
            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")

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