-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from skyweb07/feature/fix_image_generation_for…
…_directory_with_spaces Fix failed tests for project with spaces in path
- Loading branch information
Showing
18 changed files
with
412 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/Pods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ disabled_rules: | |
|
||
excluded: | ||
- SnapTests | ||
- Pods | ||
|
||
file_length: | ||
warning: 200 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
language: objective-c | ||
cache: cocoapods | ||
osx_image: xcode9.2 | ||
|
||
sudo: required | ||
install: | ||
- ./.scripts/install-swiftlint.sh | ||
- pod install | ||
|
||
script: | ||
- swiftlint | ||
- xcodebuild -scheme Snap -project ./Snap.xcodeproj -destination 'platform=iOS Simulator,name=iPhone 7' test | ||
- xcodebuild -scheme Snap -workspace ./Snap.xcworkspace -destination 'platform=iOS Simulator,name=iPhone 7' test | xcpretty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
platform :ios, '9.0' | ||
|
||
target 'Snap' do | ||
use_frameworks! | ||
|
||
# Pods for Snap | ||
|
||
target 'SnapTests' do | ||
inherit! :search_paths | ||
pod 'CwlPreconditionTesting', :git => 'https://github.com/mattgallagher/CwlPreconditionTesting.git' | ||
pod 'CwlCatchException', :git => 'https://github.com/mattgallagher/CwlCatchException.git' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
PODS: | ||
- CwlCatchException (1.0.2) | ||
- CwlPreconditionTesting (1.1.0): | ||
- CwlCatchException | ||
|
||
DEPENDENCIES: | ||
- CwlCatchException (from `https://github.com/mattgallagher/CwlCatchException.git`) | ||
- CwlPreconditionTesting (from `https://github.com/mattgallagher/CwlPreconditionTesting.git`) | ||
|
||
EXTERNAL SOURCES: | ||
CwlCatchException: | ||
:git: https://github.com/mattgallagher/CwlCatchException.git | ||
CwlPreconditionTesting: | ||
:git: https://github.com/mattgallagher/CwlPreconditionTesting.git | ||
|
||
CHECKOUT OPTIONS: | ||
CwlCatchException: | ||
:commit: b14c111e9b33cd142bd4bc75c482cfd5c3490923 | ||
:git: https://github.com/mattgallagher/CwlCatchException.git | ||
CwlPreconditionTesting: | ||
:commit: b2e4800abf854366d4492051069cce7b44d20ba1 | ||
:git: https://github.com/mattgallagher/CwlPreconditionTesting.git | ||
|
||
SPEC CHECKSUMS: | ||
CwlCatchException: 70a52ae44ea5d46db7bd385f801a94942420cd8c | ||
CwlPreconditionTesting: d9b35890c80b34668cd90da5bef077fd817a99fc | ||
|
||
PODFILE CHECKSUM: 540c3fa6ae55d09ebef0fe29fae919227da61157 | ||
|
||
COCOAPODS: 1.4.0.beta.2 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
SnapTests/Core/Domain/Model/Test Doubles/EnvironmentStub.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Foundation | ||
|
||
final class EnvironmentStub: Environment { | ||
var keys = [String: String]() | ||
|
||
func get(_ key: String) -> String? { | ||
return keys[key] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import XCTest | ||
|
||
final class TestTargetSpec: XCTestCase { | ||
|
||
private var environment: EnvironmentStub! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
environment = EnvironmentStub() | ||
} | ||
|
||
override func tearDown() { | ||
environment = nil | ||
super.tearDown() | ||
} | ||
|
||
func test_should_throw_assertion_if_environment_path_is_not_set() { | ||
givenEnviromentIsNotSet() | ||
|
||
let reference = givenTestTarget() | ||
|
||
assertThrowException() { | ||
let _ = reference.reference(for: .reference).path | ||
} | ||
} | ||
|
||
func test_should_no_throw_if_environment_path_is_set() { | ||
givenEnvironment() | ||
|
||
let reference = givenTestTarget() | ||
|
||
assertNoThrowException() { | ||
let _ = reference.reference(for: .reference).path | ||
} | ||
} | ||
|
||
func test_should_throw_assertion_if_given_path_is_invalid() { | ||
givenEnvironment(with: "invalid/path/") | ||
|
||
let reference = givenTestTarget() | ||
|
||
assertThrowException() { | ||
let _ = reference.reference(for: .reference).path | ||
} | ||
} | ||
|
||
func test_should_return_correct_path_for_test_target() { | ||
givenEnvironment() | ||
|
||
let reference = givenTestTarget() | ||
|
||
let referencePath = reference.reference(for: .reference).path | ||
let expectedPath = "\(currentPath)/Snap/file/[email protected]" | ||
|
||
XCTAssertEqual(referencePath.path, expectedPath) | ||
} | ||
|
||
func test_should_return_correct_path_for_test_target_with_reference_path_with_spaces() { | ||
givenEnvironment() | ||
|
||
let reference = givenTestTarget( | ||
with: "function name" | ||
) | ||
|
||
let referencePath = reference.reference(for: .reference).path | ||
let expectedPath = "\(currentPath)/Snap/file/[email protected]" | ||
|
||
XCTAssertEqual(referencePath.path, expectedPath) | ||
} | ||
|
||
func test_should_return_correct_path_for_test_target_with_custom_name() { | ||
givenEnvironment() | ||
|
||
let reference = givenTestTarget( | ||
with: "function name", | ||
named: "custom name" | ||
) | ||
|
||
let referencePath = reference.reference(for: .reference).path | ||
let expectedPath = "\(currentPath)/Snap/file/[email protected]" | ||
|
||
XCTAssertEqual(referencePath.path, expectedPath) | ||
} | ||
|
||
func test_should_return_correct_path_for_different_test_targets() { | ||
givenEnvironment() | ||
|
||
let reference = givenTestTarget( | ||
with: "function name", | ||
named: "custom name" | ||
) | ||
|
||
let referencePath = reference.reference(for: .reference).path | ||
let failedPath = reference.reference(for: .failed).path | ||
let diffPath = reference.reference(for: .diff).path | ||
|
||
let expectedReferencePath = "\(currentPath)/Snap/file/[email protected]" | ||
let expectedFailedPath = "\(currentPath)/Snap/Failed/file/[email protected]" | ||
let expectedDiffPath = "\(currentPath)/Snap/Diff/file/[email protected]" | ||
|
||
XCTAssertEqual(referencePath.path, expectedReferencePath) | ||
XCTAssertEqual(failedPath.path, expectedFailedPath) | ||
XCTAssertEqual(diffPath.path, expectedDiffPath) | ||
} | ||
} | ||
|
||
// MARK: - Helpers | ||
|
||
extension TestTargetSpec { | ||
private func givenEnviromentIsNotSet() { | ||
environment.keys[Path.referenceImage] = nil | ||
} | ||
|
||
private func givenEnvironment(with path: String? = FileManager.default.currentDirectoryPath) { | ||
environment.keys[Path.referenceImage] = path | ||
} | ||
|
||
private func givenTestTarget(with function: String = "function", | ||
file: String = "file", | ||
named: String? = nil) -> TestTarget | ||
{ | ||
return TestTarget( | ||
function: function, | ||
file: file, | ||
named: named, | ||
fileManager: .default, | ||
environment: environment | ||
) | ||
} | ||
var currentPath: String { | ||
return FileManager.default.currentDirectoryPath | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
SnapTests/Core/Infrastructure/Extension/CALayer/CALayerImageSpec.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
SnapTests/Core/Infrastructure/Extension/UIImage/UIImageCompareSpec.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
SnapTests/Core/Infrastructure/Extension/UIImage/UIImageNormalizedSpec.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
SnapTests/Resources/Extension/XCTestCase/XCTestCase+CustomAsserts.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import XCTest | ||
import CwlCatchException | ||
import CwlPreconditionTesting | ||
|
||
extension XCTestCase { | ||
func assertThrowException(f: @escaping () -> Void) { | ||
let instruction = catchBadInstruction { | ||
f() | ||
} | ||
|
||
guard let _ = instruction else { | ||
XCTFail("No exceptions were thrown") | ||
return | ||
} | ||
} | ||
|
||
func assertNoThrowException(f: @escaping () -> Void) { | ||
XCTAssertNil(catchBadInstruction { f() }) | ||
} | ||
} |