change from XCTest to Spectre

This commit is contained in:
Yonas Kolb
2017-07-26 00:55:11 +02:00
parent 6b2f360119
commit 66be8cdc9a
7 changed files with 76 additions and 39 deletions
+9 -1
View File
@@ -8,8 +8,16 @@
import Foundation
public enum SpecError: Error {
public enum SpecError: Error, CustomStringConvertible {
case unknownTargetType(String)
case unknownTargetPlatform(String)
case invalidDependency([String: Any])
public var description: String {
switch self {
case let .unknownTargetType(type): return "Unknown Target type: \(type)"
case let .unknownTargetPlatform(platform): return "Unknown Target platform: \(platform)"
case let .invalidDependency(dependency): return "Unknown Target dependency: \(dependency)"
}
}
}
+5 -1
View File
@@ -68,7 +68,11 @@ extension Target: JSONObjectConvertible {
sources = jsonDictionary.json(atKeyPath: "sources") ?? []
}
sourceExludes = jsonDictionary.json(atKeyPath: "sourceExludes") ?? []
dependencies = jsonDictionary.json(atKeyPath: "dependencies") ?? []
if jsonDictionary["dependencies"] == nil {
dependencies = []
} else {
dependencies = try jsonDictionary.json(atKeyPath: "dependencies", invalidItemBehaviour: .fail)
}
prebuildScripts = jsonDictionary.json(atKeyPath: "prebuildScripts") ?? []
postbuildScripts = jsonDictionary.json(atKeyPath: "postbuildScripts") ?? []
}
+8 -9
View File
@@ -1,4 +1,4 @@
import XCTest
import Spectre
import PathKit
import XcodeGenKit
import xcodeproj
@@ -14,17 +14,16 @@ func generate(specPath: Path, projectPath: Path) throws {
try project.write(path: projectPath, override: true)
_ = try XcodeProj(path: projectPath)
} else {
XCTFail("Spec has errors:\n\(lintedSpec.errors.map { $0.description}.joined(separator: "\n"))")
throw failure("Spec has errors:\n\(lintedSpec.errors.map { $0.description}.joined(separator: "\n"))")
}
}
class FixtureTests: XCTestCase {
func fixtureTests() {
func testGeneration() throws {
try generate(specPath: fixturePath + "TestProject/spec.yml", projectPath: fixturePath + "TestProject/GeneratedProject.xcodeproj")
describe("Test Project") {
$0.it("generates") {
try generate(specPath: fixturePath + "TestProject/spec.yml", projectPath: fixturePath + "TestProject/GeneratedProject.xcodeproj")
}
}
static var allTests = [
("testGeneration", testGeneration),
]
}
+10 -9
View File
@@ -1,9 +1,9 @@
import XCTest
import Spectre
import XcodeGenKit
import xcodeproj
import PathKit
class GeneratorTests: XCTestCase {
func generatorTests() {
func getProject(_ spec: Spec) throws -> XcodeProj {
let lintedSpec = SpecLinter.lint(spec)
@@ -11,12 +11,13 @@ class GeneratorTests: XCTestCase {
return try generator.generate()
}
func testGeneratorGeneratesDefaultConfigs() throws {
let project = try getProject(Spec(name: "test"))
XCTAssert(project.pbxproj.objects.buildConfigurations.count == 2)
}
describe("Generator") {
static var allTests = [
("testGeneratorGeneratesDefaultConfigs", testGeneratorGeneratesDefaultConfigs),
]
$0.it("provide defaults") {
let project = try getProject(Spec(name: "test"))
try expect(project.pbxproj.objects.buildConfigurations.count) == 2
}
}
}
+26 -14
View File
@@ -1,9 +1,9 @@
import XCTest
import Spectre
import PathKit
import XcodeGenKit
import xcodeproj
class SpecLoadingTests: XCTestCase {
func specLoadingTests() {
@discardableResult
func getSpec(_ spec: [String: Any]) throws -> Spec {
@@ -14,22 +14,34 @@ class SpecLoadingTests: XCTestCase {
return try Spec(jsonDictionary: specDictionary)
}
func expectSpecFailure(_ expectedError: SpecError, _ spec: [String: Any]) {
expectError(expectedError) {
func expectSpecFailure(_ expectedError: SpecError, _ spec: [String: Any]) throws {
try expectError(expectedError) {
try getSpec(spec)
}
}
func testIncorrectTargetPlatform() throws {
expectSpecFailure(.unknownTargetPlatform("invalid"), ["targets": [["name": "test", "type": "application", "platform": "invalid"]]])
let validTarget: [String: Any] = ["name": "test", "type": "application", "platform": "iOS"]
let invalidName = "invalid"
describe("The project spec") {
$0.it("fails with incorrect platform") {
var target = validTarget
target["platform"] = invalidName
try expectSpecFailure(.unknownTargetPlatform("invalid"), ["targets": [target]])
}
$0.it("fails with incorrect product type") {
var target = validTarget
target["type"] = invalidName
try expectSpecFailure(.unknownTargetType("invalid"), ["targets": [target]])
}
$0.it("fails with invalid target dependency") {
var target = validTarget
target["dependencies"] = [["invalid": "target"]]
try expectSpecFailure(.invalidDependency(["invalid": "target"]), ["targets": [target]])
}
}
func testIncorrectTargetProductType() throws {
expectSpecFailure(.unknownTargetType("invalid"), ["targets": [["name": "test", "type": "invalid", "platform": "iOS"]]])
}
static var allTests = [
("testIncorrectTargetPlatform", testIncorrectTargetPlatform),
("testIncorrectTargetProductType", testIncorrectTargetProductType),
]
}
+7 -5
View File
@@ -1,12 +1,14 @@
import Foundation
import XCTest
import Spectre
func expectError(_ expectedError: Error, closure: () throws -> ()) {
func expectError<T: Error>(_ expectedError: T, closure: () throws -> ()) throws where T: CustomStringConvertible {
do {
try closure()
XCTFail("Supposed to fail with \"\(expectedError)\"")
} catch let error as T {
try expect(error.description) == expectedError.description
return
} catch {
XCTAssert(error.localizedDescription == expectedError.localizedDescription,
"Expected error \"\(expectedError.localizedDescription)\" but got \"\(error.localizedDescription)\"")
throw failure("Supposed to fail with \"\(expectedError)\"")
}
throw failure("Supposed to fail with \"\(expectedError)\"")
}
+11
View File
@@ -0,0 +1,11 @@
import Foundation
import XCTest
class XCodeGenKitTests: XCTestCase {
func testXcodeGenKit() {
generatorTests()
specLoadingTests()
fixtureTests()
}
}