Skip to content

Commit

Permalink
Generate snapshots before testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken committed Jan 29, 2018
1 parent 8823a67 commit eb71fda
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
9 changes: 8 additions & 1 deletion Concorde.xcodeproj/xcshareddata/xcschemes/Concorde.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "NO">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -63,6 +63,13 @@
ReferencedContainer = "container:Concorde.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "GENERATE_SNAPSHOTS"
value = "$(GENERATE_SNAPSHOTS)"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ setup:
bundle exec pod install

test:
bundle exec xcodebuild clean test \
-workspace Concorde.xcworkspace \
-scheme Concorde \
-destination "platform=iOS Simulator,name=iPhone 8 Plus" \
GENERATE_SNAPSHOTS=YES \
| xcpretty -c
bundle exec xcodebuild test \
-workspace Concorde.xcworkspace \
-scheme Concorde \
-destination 'platform=iOS Simulator,name=iPhone 8 Plus' \
| xcpretty -c
| xcpretty; exit ${PIPESTATUS[0]}
23 changes: 19 additions & 4 deletions Tests/ConcordeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,23 @@ import Concorde
import Nimble
import Nimble_Snapshots
import Quick
import Foundation

class ConcordeTests: QuickSpec {

private func snapshotAction() -> Predicate<Snapshotable> {
guard let generateSnapshots = ProcessInfo.processInfo.environment["GENERATE_SNAPSHOTS"]?.lowercased() else {
return haveValidSnapshot()
}

switch generateSnapshots {
case "yes", "true", "1":
return recordSnapshot()
default:
return haveValidSnapshot()
}
}

override func spec() {
var crashData = Data()
var nonProgressiveData = Data()
Expand Down Expand Up @@ -40,15 +55,15 @@ class ConcordeTests: QuickSpec {
decoder?.decompress()

let view = UIImageView(image: decoder?.toImage())
expect(view).to(haveValidSnapshot())
expect(view).to(self.snapshotAction())
}

it("can decode progressive JPEGs") {
let decoder = CCBufferedImageDecoder(data: progressiveData)
decoder?.decompress()

let view = UIImageView(image: decoder?.toImage())
expect(view).to(haveValidSnapshot())
expect(view).to(self.snapshotAction())
}

it("can decode partial progressive JPEGs") {
Expand All @@ -57,7 +72,7 @@ class ConcordeTests: QuickSpec {
decoder?.decompress()

let view = UIImageView(image: decoder?.toImage())
expect(view).to(haveValidSnapshot())
expect(view).to(self.snapshotAction())
}

it("is resilient against errors in the data to decode") {
Expand All @@ -74,7 +89,7 @@ class ConcordeTests: QuickSpec {
}

let view = UIImageView(image: decoder?.toImage())
expect(view).to(haveValidSnapshot())
expect(view).to(self.snapshotAction())
}

it("is resilient against not calling decode() at all") {
Expand Down

0 comments on commit eb71fda

Please sign in to comment.