Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MobiusCore/Test/AnonymousDisposableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Quick

class AnonymousDisposableTests: QuickSpec {
// swiftlint:disable:next function_body_length
override func spec() {
override class func spec() {
describe("AnonymousDisposable") {
var disposable: AnonymousDisposable!
var invocationCount: Int!
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/AnyConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Nimble
import Quick

class ConnectionTests: QuickSpec {
override func spec() {
override class func spec() {
describe("Connection") {
context("when initializing with closures") {
var connection: Connection<Int>!
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/AnyMobiusLoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Nimble
import Quick

class AnyMobiusLoggerTests: QuickSpec {
override func spec() {
override class func spec() {
describe("AnyMobiusLogger") {
var delegate: TestMobiusLogger!
var logger: AnyMobiusLogger<String, String, String>!
Expand Down
9 changes: 4 additions & 5 deletions MobiusCore/Test/AsyncDispatchQueueConnectableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import Nimble
import Quick

class AsyncDispatchQueueConnectableTests: QuickSpec {
private let acceptQueue = DispatchQueue(label: "accept queue")

override func spec() {
override class func spec() {
describe("AsyncDispatchQueueConnectable") {
var connectable: AsyncDispatchQueueConnectable<String, String>!
var underlyingConnectable: RecordingTestConnectable!
let acceptQueue = DispatchQueue(label: "accept queue")

beforeEach {
underlyingConnectable = RecordingTestConnectable(expectedQueue: self.acceptQueue)
connectable = AsyncDispatchQueueConnectable(underlyingConnectable, acceptQueue: self.acceptQueue)
underlyingConnectable = RecordingTestConnectable(expectedQueue: acceptQueue)
connectable = AsyncDispatchQueueConnectable(underlyingConnectable, acceptQueue: acceptQueue)
}

context("when connected") {
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/CompositeDisposableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Nimble
import Quick

class CompositeDisposableTests: QuickSpec {
override func spec() {
override class func spec() {
describe("CompositeDisposable") {
var one: TestDisposable!
var two: TestDisposable!
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/ConnectablePublisherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Quick

class ConnectablePublisherTests: QuickSpec {
// swiftlint:disable:next function_body_length
override func spec() {
override class func spec() {
describe("ConnectablePublisher") {
var publisher: ConnectablePublisher<String>!
var received: [String]!
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/EffectHandlers/AnyEffectHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private typealias Event = String

class AnyEffectHandlerTests: QuickSpec {
// swiftlint:disable:next function_body_length
override func spec() {
override class func spec() {
describe("AnyEffectHandler") {
var effectHandler: AnyEffectHandler<Effect, Event>!
var receivedEvents: [Event]!
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/EffectHandlers/CallbackTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Quick

class CallbackTests: QuickSpec {
// swiftlint:disable:next function_body_length
override func spec() {
override class func spec() {
describe("Callbacks") {
context("Ending a Callback") {
var onEndCalledTimes: Int!
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/EffectHandlers/EffectHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private enum Event {
}

class EffectHandlerTests: QuickSpec {
override func spec() {
override class func spec() {
describe("Handling effects with EffectHandler") {
var effectHandler: AnyEffectHandler<Effect, Event>!
var executeEffect: ((Effect) -> Void)!
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/EffectHandlers/EffectRouterDSLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private enum Event: Equatable {

class EffectRouterDSLTests: QuickSpec {
// swiftlint:disable:next function_body_length
override func spec() {
override class func spec() {
context("An EffectHandler which always ends as soon as it is called") {
var wasDisposed: Bool!
var connection: Connection<Int>!
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/EffectHandlers/EffectRouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private enum Event {

class EffectRouterTests: QuickSpec {
// swiftlint:disable:next function_body_length
override func spec() {
override class func spec() {
context("Router happy paths") {
var receivedEvents: [Event]!
var disposed1: Bool!
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/EffectHandlers/EnumRouteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private func unwrap<Input, Parameters, Output>(
}

class ParameterExtractionRouteTests: QuickSpec {
override func spec() {
override class func spec() {
context("Different types of enums being unwrapped") {
it("supports routing to an effect with nothing to unwrap") {
let route = EffectRouter<Effect, Never>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private enum Effect: Equatable {
/// We had seen small volumes of this second issue in production. (Spotify internal: IOS-42623)
class EventRouterDisposalLogicalRaceRegressionTest: QuickSpec {
// swiftlint:disable:next function_body_length
override func spec() {
override class func spec() {
describe("Effect Handler connection") {
var controller: MobiusController<Model, Event, Effect>!
var collaborator: EffectCollaborator!
Expand Down
7 changes: 4 additions & 3 deletions MobiusCore/Test/EventSources/AnyEventSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Nimble
import Quick

class AnyEventSourceTests: QuickSpec {
override func spec() {
override class func spec() {
describe("AnyEventSource") {
var eventConsumer: TestConsumer!
var delegateEventSource: TestEventSource<String>!
Expand All @@ -18,18 +18,19 @@ class AnyEventSourceTests: QuickSpec {
}

it("should forward delegate consumer to closure") {
let consumerForwarded = self.expectation(description: "consumer forwarded")
var forwarded = false

let source = AnyEventSource<String>({ consumer in
let testString = UUID().uuidString
consumer(testString)
if eventConsumer.received == [testString] {
consumerForwarded.fulfill()
forwarded = true
}
return TestDisposable()
})

_ = source.subscribe(consumer: eventConsumer.accept)
expect(forwarded).toEventually(beTrue())
}

it("should forward events from delegate event source") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Quick

class CompositeEventSourceBuilderTest: QuickSpec {
// swiftlint:disable:next function_body_length
override func spec() {
override class func spec() {
var eventsReceived: [Int]!
var compositeEventSource: AnyEventSource<Int>!
var disposable: Disposable!
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/FirstTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FirstTests: QuickSpec {
case refresh
}

override func spec() {
override class func spec() {
describe("First") {
var sut: First<String, Effect>!

Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/InitializationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Quick

class InitializationTests: QuickSpec {
// swiftlint:disable:next function_body_length
override func spec() {
override class func spec() {
describe("Initialization") {
var builder: Mobius.Builder<String, String, String>!
var updateFunction: Update<String, String, String>!
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/LoggingInitiateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Nimble
import Quick

class LoggingInitiateTests: QuickSpec {
override func spec() {
override class func spec() {
describe("LoggingInitiate") {
var logger: TestMobiusLogger!
var loggingInitiate: Initiate<String, String>!
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/LoggingUpdateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Nimble
import Quick

class LoggingUpdateTests: QuickSpec {
override func spec() {
override class func spec() {
describe("LoggingUpdate") {
var logger: TestMobiusLogger!
var loggingUpdate: Update<String, String, String>!
Expand Down
63 changes: 31 additions & 32 deletions MobiusCore/Test/MobiusControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ import Quick
// swiftlint:disable file_length
// swiftlint:disable:next type_body_length
class MobiusControllerTests: QuickSpec {
let loopQueue = DispatchQueue(label: "loop queue")
let viewQueue = DispatchQueue(label: "view queue")

// swiftlint:disable:next function_body_length
override func spec() {
override class func spec() {
let loopQueue = DispatchQueue(label: "loop queue")
let viewQueue = DispatchQueue(label: "view queue")

let makeSureAllEffectsAndEventsHaveBeenProcessed: () -> Void = {
loopQueue.sync {
// Waiting synchronously for effects to be completed
}

viewQueue.sync {
// Waiting synchronously for view observations to be completed
}
}

describe("MobiusController") {
var controller: MobiusController<String, String, String>!
var updateFunction: Update<String, String, String>!
Expand All @@ -31,8 +41,7 @@ class MobiusControllerTests: QuickSpec {
}

beforeEach {
view = RecordingTestConnectable(expectedQueue: self.viewQueue)
let loopQueue = self.loopQueue
view = RecordingTestConnectable(expectedQueue: viewQueue)

updateFunction = .init { model, event in
dispatchPrecondition(condition: .onQueue(loopQueue))
Expand All @@ -57,8 +66,8 @@ class MobiusControllerTests: QuickSpec {
.makeController(
from: "S",
initiate: initiate,
loopQueue: self.loopQueue,
viewQueue: self.viewQueue
loopQueue: loopQueue,
viewQueue: viewQueue
)
}

Expand All @@ -79,7 +88,7 @@ class MobiusControllerTests: QuickSpec {
expect(view.recorder.items).toEventually(equal(["S", "S-hey"]))
}
it("should allow multiple connections") {
let secondaryView = RecordingTestConnectable(expectedQueue: self.viewQueue)
let secondaryView = RecordingTestConnectable(expectedQueue: viewQueue)

controller.connectView(view)
controller.connectView(secondaryView)
Expand All @@ -105,13 +114,13 @@ class MobiusControllerTests: QuickSpec {
controller.start()

view.dispatch("restarted")
self.makeSureAllEffectsAndEventsHaveBeenProcessed()
makeSureAllEffectsAndEventsHaveBeenProcessed()

expect(view.recorder.items).toEventually(equal(["S", "S-restarted"]))
}
it("should retain updated state") {
view.dispatch("hi")
self.makeSureAllEffectsAndEventsHaveBeenProcessed()
makeSureAllEffectsAndEventsHaveBeenProcessed()

controller.stop()

Expand Down Expand Up @@ -189,7 +198,7 @@ class MobiusControllerTests: QuickSpec {
expect(view.recorder.items).toEventually(equal(["S"]))
}
it("should allow disconnecting by id") {
let secondaryView = RecordingTestConnectable(expectedQueue: self.viewQueue)
let secondaryView = RecordingTestConnectable(expectedQueue: viewQueue)

let connectionID = controller.connectView(view)
let secondaryConnectionID = controller.connectView(secondaryView)
Expand All @@ -198,7 +207,7 @@ class MobiusControllerTests: QuickSpec {
controller.disconnectView(id: secondaryConnectionID)
}
it("should not send events to a disconnected view") {
let disconnectedView = RecordingTestConnectable(expectedQueue: self.viewQueue)
let disconnectedView = RecordingTestConnectable(expectedQueue: viewQueue)
controller.connectView(disconnectedView)
controller.disconnectView()

Expand Down Expand Up @@ -230,15 +239,15 @@ class MobiusControllerTests: QuickSpec {

describe("multiple view connections") {
it("should not allow disconnecting without a connection id") {
let secondaryView = RecordingTestConnectable(expectedQueue: self.viewQueue)
let secondaryView = RecordingTestConnectable(expectedQueue: viewQueue)

controller.connectView(view)
controller.connectView(secondaryView)

expect(controller.disconnectView()).to(raiseError())
}
it("should not allow disconnecting an invalid connection id") {
let secondaryView = RecordingTestConnectable(expectedQueue: self.viewQueue)
let secondaryView = RecordingTestConnectable(expectedQueue: viewQueue)

controller.connectView(view)
controller.connectView(secondaryView)
Expand Down Expand Up @@ -339,7 +348,7 @@ class MobiusControllerTests: QuickSpec {
controller.start()

view.dispatch("the last event")
self.makeSureAllEffectsAndEventsHaveBeenProcessed()
makeSureAllEffectsAndEventsHaveBeenProcessed()

controller.stop()

Expand Down Expand Up @@ -393,8 +402,8 @@ class MobiusControllerTests: QuickSpec {
.makeController(
from: "S",
initiate: initiate,
loopQueue: self.loopQueue,
viewQueue: self.viewQueue
loopQueue: loopQueue,
viewQueue: viewQueue
)
controller.connectView(view)
controller.start()
Expand Down Expand Up @@ -430,8 +439,8 @@ class MobiusControllerTests: QuickSpec {
.makeController(
from: "S",
initiate: initiate,
loopQueue: self.loopQueue,
viewQueue: self.viewQueue
loopQueue: loopQueue,
viewQueue: viewQueue
)
controller.connectView(view)
controller.start()
Expand All @@ -456,13 +465,13 @@ class MobiusControllerTests: QuickSpec {
effectObserver = MockConnectable()
controller = Mobius
.loop(update: Update { model, _ in .next(model) }, effectHandler: effectObserver)
.makeController(from: NSObject(), loopQueue: self.loopQueue, viewQueue: self.viewQueue)
.makeController(from: NSObject(), loopQueue: loopQueue, viewQueue: viewQueue)
controller.connectView(modelObserver)
controller.start()
}

it("should release any references to the loop") {
self.makeSureAllEffectsAndEventsHaveBeenProcessed()
makeSureAllEffectsAndEventsHaveBeenProcessed()
controller.stop()
controller.disconnectView()
controller = nil
Expand All @@ -471,16 +480,6 @@ class MobiusControllerTests: QuickSpec {
}
}
}

func makeSureAllEffectsAndEventsHaveBeenProcessed() {
loopQueue.sync {
// Waiting synchronously for effects to be completed
}

viewQueue.sync {
// Waiting synchronously for view observations to be completed
}
}
}

class MockConnectable: Connectable {
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/MobiusHooksTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Nimble
import Quick

class MobiusHooksTests: QuickSpec {
override func spec() {
override class func spec() {
let someString = UUID().uuidString

describe("MobiusHooks") {
Expand Down
2 changes: 1 addition & 1 deletion MobiusCore/Test/MobiusIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Quick
// Should only test public APIs
class MobiusIntegrationTests: QuickSpec {
// swiftlint:disable:next function_body_length
override func spec() {
override class func spec() {
describe("Mobius integration tests") {
let update = Update<String, String, String> { _, event in
switch event {
Expand Down
Loading
Loading