• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 10 years ago
  • Updated almost 9 years ago

Reviews

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

Repository Details

Upload failing iOS snapshot tests cases to S3

Second Curtain

Build Status

If you're using the cool FBSnapshotTestCase to test your iOS view logic, awesome! Even better if you have continuous integration, like on Travis, to automate running those tests!

Purpose

Isn't it frustrating that you can't see the results of your tests? At best, you'll get this kind of error output:

ASHViewControllerSpec
  a_view_controller_with_a_loaded_view_should_have_a_valid_snapshot, expected a matching snapshot in a_view_controller_with_a_loaded_view_should_have_a_valid_snapshot
  /Users/travis/build/AshFurrow/upload-ios-snapshot-test-case/Demo/DemoTests/DemoTests.m:31

        it(@"should have a valid snapshot", ^{
            expect(viewController).to.haveValidSnapshot();
        });

    Executed 1 test, with 1 failure (1 unexpected) in 0.952 (0.954) seconds
** TEST FAILED **

Wouldn't it be awesome if we could upload the failing test snapshots somewhere, so we can see exactly what's wrong? That's what we aim to do here.

Usage

Usage is pretty simple. Have an S3 bucket that is world-readable (that is, include the following bucket policy).

{
  "Version": "2008-10-17",
  "Statement": [
    {
      "Sid": "AllowPublicRead",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::bucket-name/*"
    }
  ]
}

(Replace "bucket-name" with your bucket name.)

It's also a good idea not to use a general-purpose S3 user for your CI, so create a new one with the following policy that will let them list buckets, but only read from or write to the bucket you're using.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:ListAllMyBuckets"],
      "Resource": "arn:aws:s3:::*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:*"
      ],
      "Resource": "arn:aws:s3:::bucket-name"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:*"
      ],
      "Resource": "arn:aws:s3:::bucket-name/*"
    }
  ]
}

OK, so the hard part is mostly done. Now that we have a place to upload our images, let's configure our build.

I use a Makefile to build and run tests on my iOS project, so my .travis.yml file looks something like this:

language: objective-c
cache: bundler

env:
  - UPLOAD_IOS_SNAPSHOT_BUCKET_NAME=bucket-name
  - UPLOAD_IOS_SNAPSHOT_BUCKET_PREFIX=an/optional/prefix
  - AWS_ACCESS_KEY_ID=ACCESS_KEY
  - AWS_SECRET_ACCESS_KEY=SECRET_KEY
  - AWS_REGION=OPTIONAL_REGION_DEFINITION

before_install:
  - bundle install

before_script:
  - export LANG=en_US.UTF-8
  - make ci

script:
  - make test

(You can take a look at how to encrypt information in your config file, but this has limitations due to how ecrypted variables are accessed via PRs on forks.)

My Makefile looks like this:

WORKSPACE = Demo/Demo.xcworkspace
SCHEME = Demo

all: ci

build:
	set -o pipefail && xcodebuild -workspace $(WORKSPACE) -scheme $(SCHEME) -sdk iphonesimulator build | xcpretty -c

clean:
	xcodebuild -workspace $(WORKSPACE) -scheme $(SCHEME) clean

test:
	set -o pipefail && xcodebuild -workspace $(WORKSPACE) -scheme $(SCHEME) -configuration Debug test -sdk iphonesimulator | second_curtain | xcpretty -c --test

ci:	build

Notice that we're piping the output from xcodebuild into second_curtain.

Note also that we're using xcpretty, as you should, too. The xcpretty invocation must come after the second_curtain invocation, since Second Curtain relies on parsing the output from xcodebuild directly.

And finally, our Gemfile:

source 'https://rubygems.org'

gem 'cocoapods'
gem 'xcpretty'
gem 'second_curtain', '~> 0.2'

And when any snapshot tests fail, they'll be uploaded to S3 and an HTML page will be generated with links to the images so you can download them. Huzzah!

Sample diff

Note that when the S3 directory is created, it needs to be unique. You can provide a custom folder name with the UPLOAD_IOS_SNAPSHOT_FOLDER_NAME environment variable. If one is not provided, Second Curtain will fall back to TRAVIS_JOB_ID or CIRCLE_BUILD_NUM, and then onto one generated by the current date and time.

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

Nimble-Snapshots

Nimble matchers for FBSnapshotTestCase.
Swift
317
star
8

danger-ruby-swiftlint

A Danger plugin for SwiftLint.
Ruby
203
star
9

UICollectionViewFlowLayoutExample

UICollectionViewFlowLayout Example
Objective-C
198
star
10

ARCollectionViewMasonryLayout

Objective-C
184
star
11

danger-swiftlint

Automated Swift linting on pull requests
Swift
149
star
12

ASHSpringyCollectionView

Objective-C
140
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