@@ -21,13 +21,15 @@ class ActionTests: QuickSpec {
21
21
var errors : TestableObserver < ActionError > !
22
22
var enabled : TestableObserver < Bool > !
23
23
var executing : TestableObserver < Bool > !
24
+ var executionObservables : TestableObserver < Observable < String > > !
24
25
25
26
beforeEach {
26
27
inputs = scheduler. createObserver ( String . self)
27
28
elements = scheduler. createObserver ( String . self)
28
29
errors = scheduler. createObserver ( ActionError . self)
29
30
enabled = scheduler. createObserver ( Bool . self)
30
31
executing = scheduler. createObserver ( Bool . self)
32
+ executionObservables = scheduler. createObserver ( Observable< String> . self )
31
33
}
32
34
33
35
func bindAction( action: Action < String , String > ) {
@@ -50,6 +52,18 @@ class ActionTests: QuickSpec {
50
52
action. executing
51
53
. bindTo ( executing)
52
54
. addDisposableTo ( disposeBag)
55
+
56
+ action. executionObservables
57
+ . bindTo ( executionObservables)
58
+ . addDisposableTo ( disposeBag)
59
+
60
+ // Dummy subscription for multiple subcription tests
61
+ action. inputs. subscribe ( ) . addDisposableTo ( disposeBag)
62
+ action. elements. subscribe ( ) . addDisposableTo ( disposeBag)
63
+ action. errors. subscribe ( ) . addDisposableTo ( disposeBag)
64
+ action. enabled. subscribe ( ) . addDisposableTo ( disposeBag)
65
+ action. executing. subscribe ( ) . addDisposableTo ( disposeBag)
66
+ action. executionObservables. subscribe ( ) . addDisposableTo ( disposeBag)
53
67
}
54
68
55
69
describe ( " single element action " ) {
@@ -91,6 +105,10 @@ class ActionTests: QuickSpec {
91
105
next ( 20 , false ) ,
92
106
] )
93
107
}
108
+
109
+ it ( " executes twice " ) {
110
+ XCTAssertEqual ( executionObservables. events. count, 2 )
111
+ }
94
112
}
95
113
96
114
var action : Action < String , String > !
@@ -164,6 +182,10 @@ class ActionTests: QuickSpec {
164
182
next ( 20 , false ) ,
165
183
] )
166
184
}
185
+
186
+ it ( " executes twice " ) {
187
+ XCTAssertEqual ( executionObservables. events. count, 2 )
188
+ }
167
189
}
168
190
169
191
var action : Action < String , String > !
@@ -242,6 +264,10 @@ class ActionTests: QuickSpec {
242
264
next ( 20 , false ) ,
243
265
] )
244
266
}
267
+
268
+ it ( " executes twice " ) {
269
+ XCTAssertEqual ( executionObservables. events. count, 2 )
270
+ }
245
271
}
246
272
247
273
var action : Action < String , String > !
@@ -303,6 +329,10 @@ class ActionTests: QuickSpec {
303
329
next ( 0 , false ) ,
304
330
] )
305
331
}
332
+
333
+ it ( " never executes " ) {
334
+ XCTAssertEqual ( executionObservables. events. count, 0 )
335
+ }
306
336
}
307
337
308
338
var action : Action < String , String > !
@@ -337,19 +367,31 @@ class ActionTests: QuickSpec {
337
367
describe ( " execute function return value " ) {
338
368
var action : Action < String , String > !
339
369
var element : TestableObserver < String > !
370
+ var executionObservables : TestableObserver < Observable < String > > !
371
+
372
+ beforeEach {
373
+ element = scheduler. createObserver ( String . self)
374
+ executionObservables = scheduler. createObserver ( Observable< String> . self )
375
+ }
376
+
377
+ func bindAndExecute( action: Action < String , String > ) {
378
+ action. executionObservables
379
+ . bindTo ( executionObservables)
380
+ . addDisposableTo ( disposeBag)
381
+
382
+ scheduler. scheduleAt ( 10 ) {
383
+ action. execute ( " a " )
384
+ . bindTo ( element)
385
+ . addDisposableTo ( disposeBag)
386
+ }
387
+
388
+ scheduler. start ( )
389
+ }
340
390
341
391
context ( " single element action " ) {
342
392
beforeEach {
343
393
action = Action { Observable . just ( $0) }
344
- element = scheduler. createObserver ( String . self)
345
-
346
- scheduler. scheduleAt ( 10 ) {
347
- action. execute ( " a " )
348
- . bindTo ( element)
349
- . addDisposableTo ( disposeBag)
350
- }
351
-
352
- scheduler. start ( )
394
+ bindAndExecute ( action: action)
353
395
}
354
396
355
397
it ( " element receives single value " ) {
@@ -358,20 +400,16 @@ class ActionTests: QuickSpec {
358
400
completed ( 10 ) ,
359
401
] )
360
402
}
403
+
404
+ it ( " executes once " ) {
405
+ XCTAssertEqual ( executionObservables. events. count, 1 )
406
+ }
361
407
}
362
408
363
409
context ( " multiple element action " ) {
364
410
beforeEach {
365
411
action = Action { Observable . of ( $0, $0, $0) }
366
- element = scheduler. createObserver ( String . self)
367
-
368
- scheduler. scheduleAt ( 10 ) {
369
- action. execute ( " a " )
370
- . bindTo ( element)
371
- . addDisposableTo ( disposeBag)
372
- }
373
-
374
- scheduler. start ( )
412
+ bindAndExecute ( action: action)
375
413
}
376
414
377
415
it ( " element receives mutiple values " ) {
@@ -382,48 +420,44 @@ class ActionTests: QuickSpec {
382
420
completed ( 10 ) ,
383
421
] )
384
422
}
423
+
424
+ it ( " executes once " ) {
425
+ XCTAssertEqual ( executionObservables. events. count, 1 )
426
+ }
385
427
}
386
428
387
429
context ( " error action " ) {
388
430
beforeEach {
389
431
action = Action { _ in Observable . error ( TestError) }
390
- element = scheduler. createObserver ( String . self)
391
-
392
- scheduler. scheduleAt ( 10 ) {
393
- action. execute ( " a " )
394
- . bindTo ( element)
395
- . addDisposableTo ( disposeBag)
396
- }
397
-
398
- scheduler. start ( )
432
+ bindAndExecute ( action: action)
399
433
}
400
434
401
435
it ( " element fails with underlyingError " ) {
402
436
XCTAssertEqual ( element. events, [
403
437
error ( 10 , ActionError . underlyingError ( TestError) )
404
438
] )
405
439
}
440
+
441
+ it ( " executes once " ) {
442
+ XCTAssertEqual ( executionObservables. events. count, 1 )
443
+ }
406
444
}
407
445
408
446
context ( " disabled " ) {
409
447
beforeEach {
410
448
action = Action ( enabledIf: Observable . just ( false ) ) { Observable . just ( $0) }
411
- element = scheduler. createObserver ( String . self)
412
-
413
- scheduler. scheduleAt ( 10 ) {
414
- action. execute ( " a " )
415
- . bindTo ( element)
416
- . addDisposableTo ( disposeBag)
417
- }
418
-
419
- scheduler. start ( )
449
+ bindAndExecute ( action: action)
420
450
}
421
451
422
452
it ( " element fails with notEnabled " ) {
423
453
XCTAssertEqual ( element. events, [
424
454
error ( 10 , ActionError . notEnabled)
425
455
] )
426
456
}
457
+
458
+ it ( " never executes " ) {
459
+ XCTAssertEqual ( executionObservables. events. count, 0 )
460
+ }
427
461
}
428
462
}
429
463
0 commit comments