From a582ce059b29cdc1356e34834bcc41187e954122 Mon Sep 17 00:00:00 2001 From: Andrey Vyazovoy Date: Fri, 27 Oct 2023 00:52:27 -0400 Subject: [PATCH] Migrate all tests to Quick 7 (Nimble 12) --- Examples/Podfile.lock | 14 ++++----- SimpleSource.podspec | 4 +-- Tests/BasicDataSourceTests.swift | 2 +- Tests/CoreDataSourceTests.swift | 22 +++++++------- Tests/IndexedUpdateHandlerTests.swift | 43 ++++++++++++--------------- Tests/UIKitViewUpdateTests.swift | 2 +- 6 files changed, 41 insertions(+), 46 deletions(-) diff --git a/Examples/Podfile.lock b/Examples/Podfile.lock index ad208ca..64dff80 100644 --- a/Examples/Podfile.lock +++ b/Examples/Podfile.lock @@ -1,13 +1,13 @@ PODS: - Dwifft (0.9) - - Nimble (10.0.0) - - Quick (5.0.1) + - Nimble (12.3.0) + - Quick (7.3.0) - SimpleSource (2.0.5): - Dwifft (~> 0.9.0) - SimpleSource/Tests (2.0.5): - Dwifft (~> 0.9.0) - - Nimble (~> 10.0) - - Quick (~> 5.0) + - Nimble (~> 12.0) + - Quick (~> 7.0) - SwiftyJSON (5.0.1) DEPENDENCIES: @@ -28,9 +28,9 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Dwifft: 42912068ed2a8146077d1a1404df18625bd086e1 - Nimble: 5316ef81a170ce87baf72dd961f22f89a602ff84 - Quick: 749aa754fd1e7d984f2000fe051e18a3a9809179 - SimpleSource: 319cae1ee1f41165a9320577b11aad223972f525 + Nimble: f8a8219d16f176429b951e8f7e72df5c23ceddc0 + Quick: d32871931c05547cb4e0bc9009d66a18b50d8558 + SimpleSource: d2aa14f3f8c509cfdd3ee6b30838118bb6e6a4c6 SwiftyJSON: 2f33a42c6fbc52764d96f13368585094bfd8aa5e PODFILE CHECKSUM: a5deddba5204624da3222bdb26450e64fabfabc5 diff --git a/SimpleSource.podspec b/SimpleSource.podspec index 5828539..79f813f 100644 --- a/SimpleSource.podspec +++ b/SimpleSource.podspec @@ -14,8 +14,8 @@ Pod::Spec.new do |s| s.test_spec 'Tests' do |test_spec| test_spec.resource = 'Tests/Model/*.xcdatamodeld' test_spec.source_files = 'Tests/**/*.swift' - test_spec.dependency 'Nimble', '~> 10.0' - test_spec.dependency 'Quick', '~> 5.0' + test_spec.dependency 'Nimble', '~> 12.0' + test_spec.dependency 'Quick', '~> 7.0' end end diff --git a/Tests/BasicDataSourceTests.swift b/Tests/BasicDataSourceTests.swift index e22d110..019781a 100644 --- a/Tests/BasicDataSourceTests.swift +++ b/Tests/BasicDataSourceTests.swift @@ -4,7 +4,7 @@ import SimpleSource class BasicDataSourceTests: QuickSpec { - override func spec() { + override class func spec() { describe("A BasicDataSource") { typealias Section = BasicSection diff --git a/Tests/CoreDataSourceTests.swift b/Tests/CoreDataSourceTests.swift index d8e3ff0..d469bd2 100644 --- a/Tests/CoreDataSourceTests.swift +++ b/Tests/CoreDataSourceTests.swift @@ -7,36 +7,36 @@ private let StoreFilename = "SimpleSource-UnitTest-Store" class CoreDataSourceTests: QuickSpec { - lazy var model: NSManagedObjectModel = { - let modelURL = Bundle(for: type(of: self)).url(forResource: "TestModel", withExtension: "momd")! + static var model: NSManagedObjectModel = { + let modelURL = Bundle(for: CoreDataSourceTests.self).url(forResource: "TestModel", withExtension: "momd")! return NSManagedObjectModel(contentsOf: modelURL)! }() - lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = { + static var persistentStoreCoordinator: NSPersistentStoreCoordinator = { let fileManager = FileManager.default let directoryURL = try! fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) let url = directoryURL.appendingPathComponent("\(StoreFilename).sqlite") try? fileManager.removeItem(at: url) - let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.model) + let coordinator = NSPersistentStoreCoordinator(managedObjectModel: model) try? _ = coordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil) return coordinator }() - lazy var context: NSManagedObjectContext = { + static var context: NSManagedObjectContext = { let managedObjectContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType) - managedObjectContext.persistentStoreCoordinator = self.persistentStoreCoordinator + managedObjectContext.persistentStoreCoordinator = persistentStoreCoordinator return managedObjectContext }() - lazy var fetchController: NSFetchedResultsController = { () -> NSFetchedResultsController in + static var fetchController: NSFetchedResultsController = { () -> NSFetchedResultsController in let request: NSFetchRequest = TestEntity.fetchRequest() request.sortDescriptors = [NSSortDescriptor(key: #keyPath(TestEntity.name), ascending: true)] - let controller = NSFetchedResultsController(fetchRequest: request, managedObjectContext: self.context, sectionNameKeyPath: #keyPath(TestEntity.section), cacheName: nil) + let controller = NSFetchedResultsController(fetchRequest: request, managedObjectContext: context, sectionNameKeyPath: #keyPath(TestEntity.section), cacheName: nil) try? controller.performFetch() return controller }() - override func spec() { + override class func spec() { describe("A CoreDataSource") { let dataSource = CoreDataSource(fetchedResultsController: fetchController) @@ -130,8 +130,8 @@ class CoreDataSourceTests: QuickSpec { } } - private func createEntity(name: String, section: Int16) -> TestEntity { - let entity = NSEntityDescription.insertNewObject(forEntityName: "TestEntity", into: self.context) as! TestEntity + private static func createEntity(name: String, section: Int16) -> TestEntity { + let entity = NSEntityDescription.insertNewObject(forEntityName: "TestEntity", into: context) as! TestEntity entity.name = name entity.section = section return entity diff --git a/Tests/IndexedUpdateHandlerTests.swift b/Tests/IndexedUpdateHandlerTests.swift index 72efa91..f13ac6f 100644 --- a/Tests/IndexedUpdateHandlerTests.swift +++ b/Tests/IndexedUpdateHandlerTests.swift @@ -4,39 +4,38 @@ import Nimble class IndexedUpdateHandlerTests: QuickSpec { - var subscriptions: [IndexedUpdateHandler.Subscription] = [] - - override func spec() { + override class func spec() { describe("An IndexedUpdateHandler") { let updateHandler = IndexedUpdateHandler() + var subscriptions: [IndexedUpdateHandler.Subscription]! + + beforeEach { + subscriptions = [] + } it("forwards full updates to a subscribed observer") { var receivedFullUpdates = 0 - let subscription = updateHandler.subscribe { update in + subscriptions.append(updateHandler.subscribe { update in if case .full = update { receivedFullUpdates = receivedFullUpdates + 1 } else { fail("Unexpected update received.") } - } - self.subscriptions = [subscription] + }) updateHandler.sendFullUpdate() expect(receivedFullUpdates) == 1 updateHandler.send(update: .full) expect(receivedFullUpdates) == 2 - - self.subscriptions = [] } it("forwards delta updates to a subscribed observer") { var receivedUpdates: [IndexedUpdate] = [] - let subscription = updateHandler.subscribe { update in + subscriptions.append(updateHandler.subscribe { update in receivedUpdates.append(update) - } - self.subscriptions = [subscription] + }) let sentInsertedSections = IndexSet([1, 2]) let sentUpdatedSections = IndexSet([3, 4, 5]) @@ -72,17 +71,13 @@ class IndexedUpdateHandlerTests: QuickSpec { case .full: fail("Unexpected update received.") } - - self.subscriptions = [] } it("stops sending updates to removed observers") { var updatesForSubscriptionA = 0 var updatesForSubscriptionB = 0 - self.subscriptions = [] - - self.subscriptions.append(updateHandler.subscribe { _ in + subscriptions.append(updateHandler.subscribe { _ in updatesForSubscriptionA = updatesForSubscriptionA + 1 }) @@ -90,7 +85,7 @@ class IndexedUpdateHandlerTests: QuickSpec { expect(updatesForSubscriptionA) == 1 expect(updatesForSubscriptionB) == 0 - self.subscriptions.append(updateHandler.subscribe { _ in + subscriptions.append(updateHandler.subscribe { _ in updatesForSubscriptionB = updatesForSubscriptionB + 1 }) @@ -98,19 +93,19 @@ class IndexedUpdateHandlerTests: QuickSpec { expect(updatesForSubscriptionA) == 2 expect(updatesForSubscriptionB) == 1 - _ = self.subscriptions.removeLast() + _ = subscriptions.removeLast() updateHandler.sendFullUpdate() expect(updatesForSubscriptionA) == 3 expect(updatesForSubscriptionB) == 1 - _ = self.subscriptions.removeLast() + _ = subscriptions.removeLast() updateHandler.sendFullUpdate() expect(updatesForSubscriptionA) == 3 expect(updatesForSubscriptionB) == 1 - expect(self.subscriptions.isEmpty) == true + expect(subscriptions.isEmpty) == true } it("properly removes observation closures") { @@ -119,12 +114,12 @@ class IndexedUpdateHandlerTests: QuickSpec { do { let object = TestObject() weakObject = object - self.subscriptions.append(updateHandler.subscribe { [object] _ in _ = object }) + subscriptions.append(updateHandler.subscribe { [object] _ in _ = object }) } - expect(weakObject != nil) == true - self.subscriptions = [] - expect(weakObject == nil) == true + expect(weakObject).toNot(beNil()) + subscriptions = [] + expect(weakObject).to(beNil()) } } } diff --git a/Tests/UIKitViewUpdateTests.swift b/Tests/UIKitViewUpdateTests.swift index fd48166..e44f2df 100644 --- a/Tests/UIKitViewUpdateTests.swift +++ b/Tests/UIKitViewUpdateTests.swift @@ -23,7 +23,7 @@ class UIKitViewUpdateTests: QuickSpec { var value: Bool } - override func spec() { + override class func spec() { let vcTypes: [DataSourceUpdateable.Type] = [TableViewController.self, CollectionViewController.self] for type in vcTypes {