@@ -204,7 +204,27 @@ class SignalProducerSpec: QuickSpec {
204204 }
205205 }
206206
207- describe ( " init(_ block:) " ) {
207+ describe ( " init closure overloading " ) {
208+ it ( " should be inferred and overloaded without ambiguity " ) {
209+ let action : ( ) -> String = { " " }
210+ let throwableAction : ( ) throws -> String = { " " }
211+ let resultAction1 : ( ) -> Result < String , NoError > = { . success( " " ) }
212+ let resultAction2 : ( ) -> Result < String , AnyError > = { . success( " " ) }
213+ let throwableResultAction : ( ) throws -> Result < String , NoError > = { . success( " " ) }
214+
215+ expect ( type ( of: SignalProducer ( action) ) ) == SignalProducer < String , AnyError > . self
216+ expect ( type ( of: SignalProducer < String , NoError > ( action) ) ) == SignalProducer < String , NoError > . self
217+ expect ( type ( of: SignalProducer < String , TestError > ( action) ) ) == SignalProducer < String , TestError > . self
218+
219+ expect ( type ( of: SignalProducer ( resultAction1) ) ) == SignalProducer < String , NoError > . self
220+ expect ( type ( of: SignalProducer ( resultAction2) ) ) == SignalProducer < String , AnyError > . self
221+
222+ expect ( type ( of: SignalProducer ( throwableAction) ) ) == SignalProducer < String , AnyError > . self
223+ expect ( type ( of: SignalProducer ( throwableResultAction) ) ) == SignalProducer < Result < String , NoError > , AnyError > . self
224+ }
225+ }
226+
227+ describe ( " init(_:) lazy value " ) {
208228 it ( " should not evaluate the supplied closure until started " ) {
209229 var evaluated : Bool = false
210230 func lazyGetter( ) -> String {
@@ -287,7 +307,7 @@ class SignalProducerSpec: QuickSpec {
287307 }
288308 }
289309
290- describe ( " SignalProducer.attempt " ) {
310+ describe ( " init(_:) lazy result " ) {
291311 it ( " should run the operation once per start() " ) {
292312 var operationRunTimes = 0
293313 let operation : ( ) -> Result < String , NSError > = {
@@ -296,8 +316,8 @@ class SignalProducerSpec: QuickSpec {
296316 return . success( " OperationValue " )
297317 }
298318
299- SignalProducer . attempt ( operation) . start ( )
300- SignalProducer . attempt ( operation) . start ( )
319+ SignalProducer ( operation) . start ( )
320+ SignalProducer ( operation) . start ( )
301321
302322 expect ( operationRunTimes) == 2
303323 }
@@ -308,7 +328,7 @@ class SignalProducerSpec: QuickSpec {
308328 return . success( operationReturnValue)
309329 }
310330
311- let signalProducer = SignalProducer . attempt ( operation)
331+ let signalProducer = SignalProducer ( operation)
312332
313333 expect ( signalProducer) . to ( sendValue ( operationReturnValue, sendError: nil , complete: true ) )
314334 }
@@ -319,20 +339,19 @@ class SignalProducerSpec: QuickSpec {
319339 return . failure( operationError)
320340 }
321341
322- let signalProducer = SignalProducer . attempt ( operation)
342+ let signalProducer = SignalProducer ( operation)
323343
324344 expect ( signalProducer) . to ( sendValue ( nil , sendError: operationError, complete: false ) )
325345 }
326346 }
327347
328- describe ( " SignalProducer.attempt throws " ) {
348+ describe ( " init(_:) throwable lazy value " ) {
329349 it ( " should send a successful value then complete " ) {
330350 let operationReturnValue = " OperationValue "
331351
332- let signalProducer = SignalProducer
333- . attempt { ( ) throws -> String in
334- operationReturnValue
335- }
352+ let signalProducer = SignalProducer { ( ) throws -> String in
353+ operationReturnValue
354+ }
336355
337356 var error : Error ?
338357 signalProducer. startWithFailed {
@@ -345,10 +364,9 @@ class SignalProducerSpec: QuickSpec {
345364 it ( " should send the error " ) {
346365 let operationError = TestError . default
347366
348- let signalProducer = SignalProducer
349- . attempt { ( ) throws -> String in
350- throw operationError
351- }
367+ let signalProducer = SignalProducer { ( ) throws -> String in
368+ throw operationError
369+ }
352370
353371 var error : TestError ?
354372 signalProducer. startWithFailed {
@@ -2691,14 +2709,14 @@ class SignalProducerSpec: QuickSpec {
26912709 }
26922710}
26932711
2712+ // MARK: - Helpers
2713+
26942714private func == < T> ( left: Expectation < T . Type > , right: Any . Type ) {
26952715 left. to ( NonNilMatcherFunc { expression, _ in
26962716 return try expression. evaluate ( ) ! == right
26972717 } )
26982718}
26992719
2700- // MARK: - Helpers
2701-
27022720extension SignalProducer {
27032721 internal static func pipe( ) -> ( SignalProducer , ProducedSignal . Observer ) {
27042722 let ( signal, observer) = ProducedSignal . pipe ( )
@@ -2728,6 +2746,6 @@ extension SignalProducer {
27282746 }
27292747 }
27302748
2731- return SignalProducer . attempt ( operation)
2749+ return SignalProducer ( operation)
27322750 }
27332751}
0 commit comments