let expectation: XCTestExpectation init(nextValues: [T] , expectation: XCTestExpectation) { self.nextValues = nextValues self.expectation = expectation } func handleNextValue(nextValue: T) -> Void { guard !nextValues.isEmpty else { fatalError("Can't handle \(nextValue)") } let stubbedValue = nextValues.removeFirst() XCTAssertEqual(stubbedValue, nextValue) if nextValues.isEmpty { expectation.fulfill() } } } 42