Coder Social home page Coder Social logo

steven-miles / ios-snapshot-test-case-expecta Goto Github PK

View Code? Open in Web Editor NEW

This project forked from foulkesjohn/ios-snapshot-test-case-expecta

0.0 0.0 0.0 111 KB

Expecta matchers for ios-snapshot-test-case.

License: MIT License

Objective-C 96.33% Ruby 3.67%

ios-snapshot-test-case-expecta's Introduction

Expecta Matchers for FBSnapshotTestCase

Expecta matchers for ios-snapshot-test-case.

Build Status

Usage

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

pod 'Expecta+Snapshots'

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.

If you need the usesDrawViewHierarchyInRect property in order to correctly render UIVisualEffect, UIAppearance and Size Classes, call [Expecta setUsesDrawViewHierarchyInRect:NO]; inside beforeAll.

#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

Approximation support

If for some reason you want to specify a tolerance for your test, you can use either named or unnamed matchers, where the tolerance parameter is a CGFloat in the interval [0, 1] and it represents the minimum ratio of unmatched points by the total number of points in your snapshot. In the example below, a tolerance of 0.01 means our view could be up to 1% different from the reference image.

expect(view).to.haveValidSnapshotWithTolerance(0.01);
expect(view).to.haveValidSnapshotNamedWithTolerance(@"unique snapshot name", 0.01);

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

ios-snapshot-test-case-expecta's People

Contributors

orta avatar dblock avatar martincik avatar leoformaggio avatar dragvs avatar ealeksandrov avatar johnboiles avatar marcelofabri avatar imaks avatar andreamazz avatar dasmer avatar krausefx avatar ruslanskorb avatar steven-miles avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.