martincik / ios-snapshot-test-case-expecta

Expecta matchers for ios-snapshot-test-case.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expecta Matchers for FBSnapshotTestCase

Expecta matchers for ios-snapshot-test-case.

Build Status

Usage

Add EXPMatchers+FBSnapshotTest to your Podfile, the latest FBSnapshotTestCase will come in as a dependency.

pod 'Expecta+Snapshots', '~> 1.0'

App setup

Use expect(view).to.recordSnapshotNamed(@"unique snapshot name") to record a snapshot and expect(view).to.haveValidSnapshotNamed(@"unique snapshot name") to check it.

If you project was compiled with Specta included, you have two extra methods that use the spec hierarchy to generate the snapshot name for you: recordSnapshot() and haveValidSnapshot(). You should only call these once per it() block.

#define EXP_SHORTHAND
#include <Specta/Specta.h>
#include <Expecta/Expecta.h>
#include <Expecta+Snapshots/EXPMatchers+FBSnapshotTest.h>
#include "FBExampleView.h"

SpecBegin(FBExampleView)

describe(@"manual matching", ^{

    it(@"matches view", ^{
        FBExampleView *view = [[FBExampleView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
        expect(view).to.recordSnapshotNamed(@"FBExampleView");
        expect(view).to.haveValidSnapshotNamed(@"FBExampleView");
    });

    it(@"doesn't match a view", ^{
        FBExampleView *view = [[FBExampleView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
        expect(view).toNot.haveValidSnapshotNamed(@"FBExampleViewDoesNotExist");
    });

});

describe(@"test name derived matching", ^{

    it(@"matches view", ^{
        FBExampleView *view = [[FBExampleView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
        expect(view).to.recordSnapshot();
        expect(view).to.haveValidSnapshot();
    });

    it(@"doesn't match a view", ^{
        FBExampleView *view = [[FBExampleView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
        expect(view).toNot.haveValidSnapshot();
    });

});

SpecEnd

Sane defaults

EXPMatchers+FBSnapshotTest will automatically figure out the tests folder, and add a reference image directory, if you'd like to override this, you should include a beforeAll block setting the setGlobalReferenceImageDir in each file containing tests.

beforeAll(^{
    setGlobalReferenceImageDir(FB_REFERENCE_IMAGE_DIR);
});

Example

A complete project can be found in FBSnapshotTestCaseDemo.

Notably, take a look at FBSnapshotTestCaseDemoSpecs.m for a complete example, which is an expanded Specta version version of FBSnapshotTestCaseDemoTests.m.

Finally you can consult the tests for ARTiledImageView or NAMapKit.

License

MIT, see LICENSE

About

Expecta matchers for ios-snapshot-test-case.

License:MIT License


Languages

Language:Objective-C 92.5%Language:Ruby 4.6%Language:Shell 2.9%