Skip to content

Commit f659b35

Browse files
committed
Merge pull request #12 from polydice/feature/xctest
Replace Quick and Nimble with XCTest
2 parents df8c8db + 7906da3 commit f659b35

File tree

11 files changed

+215
-244
lines changed

11 files changed

+215
-244
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
## Develop Branch
44

5-
#### Added
6-
75
* Syntax check with SwiftLint [#3](https://github.com/polydice/iCook-tvOS/pull/3)
86
* Code coverage
97
* A little help from [Danger](http://danger.systems/) [#4](https://github.com/polydice/iCook-tvOS/pull/4)
108
* Protocol extended features
119
* Swift 3 syntax updates [#5](https://github.com/polydice/iCook-tvOS/pull/5)
1210
* Simpler project quick start [#6](https://github.com/polydice/iCook-tvOS/pull/6)
1311
* Replace Freddy with Swift Codable [#11](https://github.com/polydice/iCook-tvOS/pull/11)
12+
* Replace Quick and Nimble with XCTest [#12](https://github.com/polydice/iCook-tvOS/pull/12)
1413

1514
## v1.0.0
1615

Podfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ target :iCookTV do
1717
pod "TreasureData-iOS-SDK", "0.1.15"
1818

1919
target :iCookTVTests do
20-
pod "Nimble"
21-
pod "Quick"
2220
pod "SwiftLint", "0.24.0"
2321
end
2422
end

Podfile.lock

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ PODS:
88
- KeenClientTD (3.2.27)
99
- Keys (1.0.1)
1010
- Kingfisher (3.2.4)
11-
- Nimble (7.0.3)
12-
- Quick (1.2.0)
1311
- SwiftLint (0.24.0)
1412
- TreasureData-iOS-SDK (0.1.15):
1513
- KeenClientTD (= 3.2.27)
@@ -22,8 +20,6 @@ DEPENDENCIES:
2220
- Hue (~> 2.0.0)
2321
- Keys (from `Pods/CocoaPodsKeys`)
2422
- Kingfisher (~> 3.2.0)
25-
- Nimble
26-
- Quick
2723
- SwiftLint (= 0.24.0)
2824
- TreasureData-iOS-SDK (= 0.1.15)
2925

@@ -40,11 +36,9 @@ SPEC CHECKSUMS:
4036
KeenClientTD: ddb29a702bd4cfce5d526519ca8959d70c324c6a
4137
Keys: a576f4c9c1c641ca913a959a9c62ed3f215a8de9
4238
Kingfisher: 8d80f39da403cd9c9ee11984e1655f4d6a566cdb
43-
Nimble: 7f5a9c447a33002645a071bddafbfb24ea70e0ac
44-
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
4539
SwiftLint: a014c92b4664e8b13f380f8640a51bb1733778ba
4640
TreasureData-iOS-SDK: cc878af36b85ae3540a9a5bdb36b7bdc8707b719
4741

48-
PODFILE CHECKSUM: 3ed7b21c8acb46a6e14e06ff31e882ac9d392b95
42+
PODFILE CHECKSUM: e5951c6489057187d3b6c52cfcfe304dc59eb489
4943

5044
COCOAPODS: 1.3.1

iCookTV.xcodeproj/project.pbxproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
B5EFE6C21DC600FF00236D1A /* VideosGridLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5EFE6C11DC600FF00236D1A /* VideosGridLayout.swift */; };
6666
B5F7BF4C1BA9C95F00A75099 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F7BF4B1BA9C95F00A75099 /* AppDelegate.swift */; };
6767
B5F7BF531BA9C95F00A75099 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B5F7BF521BA9C95F00A75099 /* Assets.xcassets */; };
68-
B5F7BF5E1BA9C95F00A75099 /* iCookTVTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F7BF5D1BA9C95F00A75099 /* iCookTVTests.swift */; };
6968
E0CC9B4F972579066B42862A /* Pods_iCookTV.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1068EAEDE861A2EEA0CF2228 /* Pods_iCookTV.framework */; };
7069
/* End PBXBuildFile section */
7170

@@ -149,7 +148,6 @@
149148
B5F7BF521BA9C95F00A75099 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
150149
B5F7BF541BA9C95F00A75099 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
151150
B5F7BF591BA9C95F00A75099 /* iCookTV.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iCookTV.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
152-
B5F7BF5D1BA9C95F00A75099 /* iCookTVTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iCookTVTests.swift; sourceTree = "<group>"; };
153151
B5F7BF5F1BA9C95F00A75099 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
154152
CCC5F61AC4253D5EB2FF6C5F /* Pods_iCookTV_iCookTVTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_iCookTV_iCookTVTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
155153
F631C183B75D6A45DF934799 /* Pods-iCookTV-iCookTVTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iCookTV-iCookTVTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-iCookTV-iCookTVTests/Pods-iCookTV-iCookTVTests.release.xcconfig"; sourceTree = "<group>"; };
@@ -347,7 +345,6 @@
347345
B5761A521CCF4D3D008CCC08 /* CategorySpec.swift */,
348346
B52BD6801D60B62E0023D4E9 /* DataCollectionSpec.swift */,
349347
B52BD67E1D6034A10023D4E9 /* DataSourceSpec.swift */,
350-
B5F7BF5D1BA9C95F00A75099 /* iCookTVTests.swift */,
351348
B5761A571CCF5752008CCC08 /* ResourceHelper.swift */,
352349
B5761A591CCF6CCD008CCC08 /* VideoSpec.swift */,
353350
);
@@ -597,8 +594,6 @@
597594
"${BUILT_PRODUCTS_DIR}/Keys/Keys.framework",
598595
"${BUILT_PRODUCTS_DIR}/Kingfisher/Kingfisher.framework",
599596
"${BUILT_PRODUCTS_DIR}/TreasureData-iOS-SDK/TreasureData_iOS_SDK.framework",
600-
"${BUILT_PRODUCTS_DIR}/Nimble/Nimble.framework",
601-
"${BUILT_PRODUCTS_DIR}/Quick/Quick.framework",
602597
);
603598
name = "[CP] Embed Pods Frameworks";
604599
outputPaths = (
@@ -609,8 +604,6 @@
609604
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Keys.framework",
610605
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Kingfisher.framework",
611606
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TreasureData_iOS_SDK.framework",
612-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework",
613-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework",
614607
);
615608
runOnlyForDeploymentPostprocessing = 0;
616609
shellPath = /bin/sh;
@@ -696,7 +689,6 @@
696689
B5761A531CCF4D3D008CCC08 /* CategorySpec.swift in Sources */,
697690
B52BD6811D60B62E0023D4E9 /* DataCollectionSpec.swift in Sources */,
698691
B52BD67F1D6034A10023D4E9 /* DataSourceSpec.swift in Sources */,
699-
B5F7BF5E1BA9C95F00A75099 /* iCookTVTests.swift in Sources */,
700692
B5761A581CCF5752008CCC08 /* ResourceHelper.swift in Sources */,
701693
B5761A5A1CCF6CCD008CCC08 /* VideoSpec.swift in Sources */,
702694
);

iCookTV/Models/Category.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626

2727
import Foundation
2828

29-
struct Category: Codable {
29+
struct Category {
3030

3131
let id: String
3232
let name: String
3333
let coverURLs: [String]
3434

35-
// MARK: - Codable
35+
}
36+
37+
38+
extension Category: Codable {
3639

3740
private enum CodingKeys: String, CodingKey {
3841
case id
@@ -44,6 +47,8 @@ struct Category: Codable {
4447
case coverURLs = "cover-urls"
4548
}
4649

50+
// MARK: - Decodable
51+
4752
init(from decoder: Decoder) throws {
4853
let container = try decoder.container(keyedBy: CodingKeys.self)
4954
id = try container.decode(String.self, forKey: .id)
@@ -53,6 +58,8 @@ struct Category: Codable {
5358
coverURLs = try attributes.decode([String].self, forKey: .coverURLs)
5459
}
5560

61+
// MARK: - Encodable
62+
5663
func encode(to encoder: Encoder) throws {
5764
var container = encoder.container(keyedBy: CodingKeys.self)
5865
try container.encode(id, forKey: .id)

iCookTV/Models/Video.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import Foundation
2828

29-
struct Video: Codable {
29+
struct Video {
3030

3131
let id: String
3232
let title: String
@@ -48,7 +48,10 @@ struct Video: Codable {
4848
return (hours > 0 ? "\(hours):" : "") + String(format: "%d:%02d", minutes, seconds)
4949
}
5050

51-
// MARK: - Codable
51+
}
52+
53+
54+
extension Video: Codable {
5255

5356
private enum CodingKeys: String, CodingKey {
5457
case id
@@ -65,6 +68,8 @@ struct Video: Codable {
6568
case cover = "cover-url"
6669
}
6770

71+
// MARK: - Decodable
72+
6873
init(from decoder: Decoder) throws {
6974
let container = try decoder.container(keyedBy: CodingKeys.self)
7075
id = try container.decode(String.self, forKey: .id)
@@ -79,6 +84,8 @@ struct Video: Codable {
7984
cover = try attributes.decode(String.self, forKey: .cover)
8085
}
8186

87+
// MARK: - Encodable
88+
8289
func encode(to encoder: Encoder) throws {
8390
var container = encoder.container(keyedBy: CodingKeys.self)
8491
try container.encode(id, forKey: .id)

iCookTVTests/CategorySpec.swift

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,50 @@
2525
//
2626

2727
@testable import iCookTV
28-
import Nimble
29-
import Quick
28+
import XCTest
3029

31-
class CategorySpec: QuickSpec {
32-
33-
override func spec() {
30+
final class CategorySpec: XCTestCase {
3431

32+
func testDecoding() throws {
33+
// Given Category.json
3534
let data: Data = Resources.testData(named: "Category.json")!
3635

37-
describe("decoding") {
38-
it("should parse JSON as Category") {
39-
let decoder = JSONDecoder()
40-
let category = try! decoder.decode(Category.self, from: data)
41-
42-
expect(category.id).to(equal("9527"))
43-
expect(category.name).to(equal("愛料理廚房"))
44-
expect(category.coverURLs).to(equal([
45-
"https://imag.es/1.jpg",
46-
"https://imag.es/2.jpg",
47-
"https://imag.es/3.jpg",
48-
"https://imag.es/4.jpg"
49-
]))
50-
}
51-
}
36+
// When decoding
37+
let decoder = JSONDecoder()
38+
let category = try decoder.decode(Category.self, from: data)
39+
40+
// It should parse JSON as Category
41+
XCTAssertEqual(category.id, "9527")
42+
XCTAssertEqual(category.name, "愛料理廚房")
43+
XCTAssertEqual(category.coverURLs, [
44+
"https://imag.es/1.jpg",
45+
"https://imag.es/2.jpg",
46+
"https://imag.es/3.jpg",
47+
"https://imag.es/4.jpg"
48+
])
49+
}
50+
51+
func testEncoding() throws {
52+
// Given a Category object
53+
let category = Category(
54+
id: "9527",
55+
name: "愛料理廚房",
56+
coverURLs: [
57+
"https://imag.es/1.jpg",
58+
"https://imag.es/2.jpg"
59+
]
60+
)
61+
62+
// When encoding
63+
let encoder = JSONEncoder()
64+
let json = try encoder.encode(category)
65+
let jsonString = String(data: json, encoding: .utf8)
5266

67+
// It should encode Category to JSON
68+
XCTAssert(jsonString!.contains("\"id\":\"9527\""))
69+
XCTAssert(jsonString!.contains("\"attributes\":{"))
70+
XCTAssert(jsonString!.contains("\"name\":\"愛料理廚房\""))
71+
XCTAssert(jsonString!.contains("\"cover-urls\":[\"https:\\/\\/imag.es\\/1.jpg\",\"https:\\/\\/imag.es\\/2.jpg\"]"))
5372
}
5473

5574
}

0 commit comments

Comments
 (0)