Skip to content

Commit 80e8442

Browse files
committed
Convert collection specs to XCTestCases
1 parent f7f7f76 commit 80e8442

File tree

2 files changed

+115
-114
lines changed

2 files changed

+115
-114
lines changed

iCookTVTests/DataCollectionSpec.swift

Lines changed: 72 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
//
2626

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

31-
class DataCollectionSpec: QuickSpec {
30+
final class DataCollectionSpec: XCTestCase {
3231

3332
private struct TestCollection: DataCollection {
3433
typealias DataType = Int
@@ -37,68 +36,77 @@ class DataCollectionSpec: QuickSpec {
3736

3837
private var dataCollection = TestCollection(items: [])
3938

40-
override func spec() {
41-
42-
beforeEach {
43-
self.dataCollection = TestCollection(items: [1, 1, 2, 3, 5, 8])
44-
}
45-
46-
describe("count") {
47-
it("should return the count of items") {
48-
expect(self.dataCollection.count) == 6
49-
}
50-
}
51-
52-
describe("subscript") {
53-
it("should return the item at index") {
54-
expect(self.dataCollection[0]) == 1
55-
expect(self.dataCollection[1]) == 1
56-
expect(self.dataCollection[2]) == 2
57-
expect(self.dataCollection[3]) == 3
58-
expect(self.dataCollection[4]) == 5
59-
expect(self.dataCollection[5]) == 8
60-
}
61-
}
62-
63-
describe("append(_:)") {
64-
it("should append items to collection") {
65-
let collection = self.dataCollection.append([13, 21, 34, 55])
66-
expect(self.dataCollection.count) == 6
67-
expect(collection.count) == 10
68-
expect(collection[6]) == 13
69-
expect(collection[7]) == 21
70-
expect(collection[8]) == 34
71-
expect(collection[9]) == 55
72-
}
73-
}
74-
75-
describe("insert(_:atIndex:)") {
76-
it("should insert item to collection") {
77-
let collection = self.dataCollection.insert(42, atIndex: 3)
78-
expect(self.dataCollection.count) == 6
79-
expect(collection.count) == 7
80-
expect(collection.items) == [1, 1, 2, 42, 3, 5, 8]
81-
}
82-
}
83-
84-
describe("deleteItem(atIndex:)") {
85-
it("should delete item at index") {
86-
let collection = self.dataCollection.deleteItem(atIndex: 3)
87-
expect(self.dataCollection.count) == 6
88-
expect(collection.count) == 5
89-
expect(collection.items) == [1, 1, 2, 5, 8]
90-
}
91-
}
92-
93-
describe("moveItem(fromIndex:toIndex:)") {
94-
it("should reorder the items") {
95-
let collection = self.dataCollection.moveItem(fromIndex: 1, toIndex: 4)
96-
expect(self.dataCollection.count) == 6
97-
expect(collection.count) == 6
98-
expect(collection.items) == [1, 2, 3, 5, 1, 8]
99-
}
100-
}
39+
override func setUp() {
40+
dataCollection = TestCollection(items: [1, 1, 2, 3, 5, 8])
41+
}
42+
43+
func testCount() {
44+
// It should return the count of items
45+
XCTAssertEqual(dataCollection.count, 6)
46+
}
47+
48+
func testSubscript() {
49+
// It should return the item at index
50+
XCTAssertEqual(dataCollection[0], 1)
51+
XCTAssertEqual(dataCollection[1], 1)
52+
XCTAssertEqual(dataCollection[2], 2)
53+
XCTAssertEqual(dataCollection[3], 3)
54+
XCTAssertEqual(dataCollection[4], 5)
55+
XCTAssertEqual(dataCollection[5], 8)
56+
}
57+
58+
func testAppendItems() {
59+
// Given
60+
let newItems = [13, 21, 34, 55]
61+
62+
// When
63+
let newCollection = dataCollection.append(newItems)
64+
65+
// Then the original data collection should remain the same
66+
XCTAssertEqual(dataCollection.count, 6)
67+
68+
// It should append items to the new collection
69+
XCTAssertEqual(newCollection.count, 10)
70+
XCTAssertEqual(newCollection[6], 13)
71+
XCTAssertEqual(newCollection[7], 21)
72+
XCTAssertEqual(newCollection[8], 34)
73+
XCTAssertEqual(newCollection[9], 55)
74+
}
75+
76+
func testInsertItemAtIndex() {
77+
// When
78+
let newCollection = dataCollection.insert(42, atIndex: 3)
79+
80+
// Then the original data collection should remain the same
81+
XCTAssertEqual(dataCollection.count, 6)
82+
83+
// It should insert item to the new collection
84+
XCTAssertEqual(newCollection.count, 7)
85+
XCTAssertEqual(newCollection.items, [1, 1, 2, 42, 3, 5, 8])
86+
}
87+
88+
func testDeleteItemAtIndex() {
89+
// When
90+
let newCollection = dataCollection.deleteItem(atIndex: 3)
91+
92+
// Then the original data collection should remain the same
93+
XCTAssertEqual(dataCollection.count, 6)
94+
95+
// It should delete item at index in the new collection
96+
XCTAssertEqual(newCollection.count, 5)
97+
XCTAssertEqual(newCollection.items, [1, 1, 2, 5, 8])
98+
}
99+
100+
func testMoveItemFromIndexToIndex() {
101+
// When
102+
let newCollection = dataCollection.moveItem(fromIndex: 1, toIndex: 4)
103+
104+
// Then the original data collection should remain the same
105+
XCTAssertEqual(dataCollection.count, 6)
101106

107+
// It should reorder the items in the new collection
108+
XCTAssertEqual(newCollection.count, 6)
109+
XCTAssertEqual(newCollection.items, [1, 2, 3, 5, 1, 8])
102110
}
103111

104112
}

iCookTVTests/DataSourceSpec.swift

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -26,73 +26,66 @@
2626

2727
@testable import iCookTV
2828
import UIKit
29-
import Nimble
30-
import Quick
29+
import XCTest
3130

32-
class DataSourceSpec: QuickSpec {
31+
final class DataSourceSpec: XCTestCase {
3332

3433
private struct TestCollection: DataCollection {
3534
typealias DataType = String
3635
private(set) var items: [String]
3736
}
3837

3938
private var dataSource = DataSource(dataCollection: TestCollection(items: []))
40-
private let dataCollection = TestCollection(items: [
41-
"Lorem", "ipsum", "dolor", "sit", "amet"
42-
])
4339
private let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: UICollectionViewLayout())
4440

45-
override func spec() {
41+
override func setUp() {
42+
dataSource = DataSource(dataCollection: TestCollection(items: [
43+
"Lorem", "ipsum", "dolor", "sit", "amet"
44+
]))
45+
}
4646

47-
beforeEach {
48-
self.dataSource = DataSource(dataCollection: self.dataCollection)
49-
}
47+
func testNumberOfItems() {
48+
// It should return the count of items
49+
XCTAssertEqual(dataSource.numberOfItems, 5)
50+
}
5051

51-
describe("SourceType") {
52-
describe("numberOfItems") {
53-
it("should return the count of items") {
54-
expect(self.dataSource.numberOfItems) == 5
55-
}
56-
}
52+
func testSubscript() {
53+
// It should return the item at index
54+
XCTAssertEqual(dataSource[0], "Lorem")
55+
XCTAssertEqual(dataSource[1], "ipsum")
56+
XCTAssertEqual(dataSource[2], "dolor")
57+
XCTAssertEqual(dataSource[3], "sit")
58+
XCTAssertEqual(dataSource[4], "amet")
59+
}
5760

58-
describe("subscript") {
59-
it("should return the item at index") {
60-
expect(self.dataSource[0]) == "Lorem"
61-
expect(self.dataSource[1]) == "ipsum"
62-
expect(self.dataSource[2]) == "dolor"
63-
expect(self.dataSource[3]) == "sit"
64-
expect(self.dataSource[4]) == "amet"
65-
}
66-
}
67-
}
61+
func testAppendItemsToCollectionView() {
62+
// Given
63+
let items = ["consectetur", "adipisicing", "elit"]
6864

69-
describe("append(_:toCollectionView:") {
70-
it("should append items to collection") {
71-
let items = ["consectetur", "adipisicing", "elit"]
72-
self.dataSource.append(items, toCollectionView: self.collectionView)
65+
// When
66+
dataSource.append(items, toCollectionView: collectionView)
67+
68+
// It should append items to collection
69+
XCTAssertEqual(dataSource.numberOfItems, 8)
70+
XCTAssertEqual(dataSource[5], "consectetur")
71+
XCTAssertEqual(dataSource[6], "adipisicing")
72+
XCTAssertEqual(dataSource[7], "elit")
73+
}
7374

74-
expect(self.dataSource.numberOfItems) == 8
75-
expect(self.dataSource[5]) == "consectetur"
76-
expect(self.dataSource[6]) == "adipisicing"
77-
expect(self.dataSource[7]) == "elit"
78-
}
79-
}
75+
func testMoveItemAtIndexPathToTopInCollectionView() {
76+
// Given
77+
let indexPath = IndexPath(row: 2, section: 0)
8078

81-
describe("moveItem(atIndexPathToTop:inCollectionView:") {
82-
it("should reorder the items") {
83-
self.dataSource.moveItem(
84-
atIndexPathToTop: IndexPath(row: 2, section: 0),
85-
inCollectionView: self.collectionView
86-
)
87-
expect(self.dataSource.numberOfItems) == 5
88-
expect(self.dataSource[0]) == "dolor"
89-
expect(self.dataSource[1]) == "Lorem"
90-
expect(self.dataSource[2]) == "ipsum"
91-
expect(self.dataSource[3]) == "sit"
92-
expect(self.dataSource[4]) == "amet"
93-
}
94-
}
79+
// When
80+
dataSource.moveItem(atIndexPathToTop: indexPath, inCollectionView: collectionView)
9581

82+
// It should reorder the items
83+
XCTAssertEqual(dataSource.numberOfItems, 5)
84+
XCTAssertEqual(dataSource[0], "dolor")
85+
XCTAssertEqual(dataSource[1], "Lorem")
86+
XCTAssertEqual(dataSource[2], "ipsum")
87+
XCTAssertEqual(dataSource[3], "sit")
88+
XCTAssertEqual(dataSource[4], "amet")
9689
}
9790

9891
}

0 commit comments

Comments
 (0)