@@ -15,6 +15,7 @@ private func waitForOperation<T>(fromProducer producer: SignalProducer<Operation
1515 when: ( ) -> ( ) ,
1616 onAppend: T -> ( ) = { fail ( " Invalid operation type: .Append( \( $0) ) " ) } ,
1717 onInsert: ( T , Int ) -> ( ) = { fail ( " Invalid operation type: .Insert( \( $0) , \( $1) ) " ) } ,
18+ onUpdate: ( T , Int ) -> ( ) = { fail ( " Invalid operation type: .Update( \( $0) , \( $1) ) " ) } ,
1819 onDelete: Int -> ( ) = { fail ( " Invalid operation type: .Delete( \( $0) ) " ) } ) {
1920
2021 waitUntil { done in
@@ -24,6 +25,8 @@ private func waitForOperation<T>(fromProducer producer: SignalProducer<Operation
2425 onAppend ( value)
2526 case . Insert( let value, let index) :
2627 onInsert ( value, index)
28+ case . Update( let value, let index) :
29+ onUpdate ( value, index)
2730 case . RemoveElement( let index) :
2831 onDelete ( index)
2932 }
@@ -38,19 +41,21 @@ private func waitForOperation<T>(fromSignal signal: Signal<Operation<T>, NoError
3841 when: ( ) -> ( ) ,
3942 onAppend: T -> ( ) = { fail ( " Invalid operation type: .Append( \( $0) ) " ) } ,
4043 onInsert: ( T , Int ) -> ( ) = { fail ( " Invalid operation type: .Insert( \( $0) , \( $1) ) " ) } ,
44+ onUpdate: ( T , Int ) -> ( ) = { fail ( " Invalid operation type: .Update( \( $0) , \( $1) ) " ) } ,
4145 onDelete: Int -> ( ) = { fail ( " Invalid operation type: .Delete( \( $0) ) " ) } ) {
4246
4347 let producer = SignalProducer < Operation < T > , NoError > { ( observer, disposable) in signal. observe ( observer) }
44- waitForOperation ( fromProducer: producer, when: when, onAppend: onAppend, onInsert: onInsert, onDelete: onDelete)
48+ waitForOperation ( fromProducer: producer, when: when, onAppend: onAppend, onInsert: onInsert, onUpdate : onUpdate , onDelete: onDelete)
4549}
4650
4751private func waitForOperation< T> ( fromArray array: ReactiveArray < T > ,
4852 when: ( ) -> ( ) ,
4953 onAppend: T -> ( ) = { fail ( " Invalid operation type: .Append( \( $0) ) " ) } ,
5054 onInsert: ( T , Int ) -> ( ) = { fail ( " Invalid operation type: .Insert( \( $0) , \( $1) ) " ) } ,
55+ onUpdate: ( T , Int ) -> ( ) = { fail ( " Invalid operation type: .Update( \( $0) , \( $1) ) " ) } ,
5156 onDelete: Int -> ( ) = { fail ( " Invalid operation type: .Delete( \( $0) ) " ) } ) {
5257
53- waitForOperation ( fromSignal: array. signal, when: when, onAppend: onAppend, onInsert: onInsert, onDelete: onDelete)
58+ waitForOperation ( fromSignal: array. signal, when: when, onAppend: onAppend, onInsert: onInsert, onUpdate : onUpdate , onDelete: onDelete)
5459}
5560
5661class ReactiveArraySpec : QuickSpec {
@@ -101,6 +106,7 @@ class ReactiveArraySpec: QuickSpec {
101106 array. insert ( 5 , atIndex: 1 )
102107
103108 expect ( array [ 1 ] ) . to ( equal ( 5 ) )
109+ expect ( array. toArray ( ) ) . to ( equal ( [ 1 , 5 , 2 , 3 , 4 ] ) )
104110 }
105111
106112 it ( " signals an insert operation " ) {
@@ -171,15 +177,16 @@ class ReactiveArraySpec: QuickSpec {
171177 array [ 1 ] = 5
172178
173179 expect ( array [ 1 ] ) . to ( equal ( 5 ) )
180+ expect ( array. toArray ( ) ) . to ( equal ( [ 1 , 5 , 3 , 4 ] ) )
174181 }
175182
176- it ( " signals an insert operation " ) {
183+ it ( " signals an update operation " ) {
177184 waitForOperation (
178185 fromArray: array,
179186 when: {
180187 array [ 1 ] = 5
181188 } ,
182- onInsert : { ( value, index) in
189+ onUpdate : { ( value, index) in
183190 expect ( value) . to ( equal ( 5 ) )
184191 expect ( index) . to ( equal ( 1 ) )
185192 }
@@ -210,7 +217,7 @@ class ReactiveArraySpec: QuickSpec {
210217 when: {
211218 array [ 1 ] = 5
212219 } ,
213- onInsert : { ( value, index) in
220+ onUpdate : { ( value, index) in
214221 expect ( value) . to ( equal ( 15 ) )
215222 expect ( index) . to ( equal ( 1 ) )
216223 }
@@ -365,6 +372,23 @@ class ReactiveArraySpec: QuickSpec {
365372
366373 }
367374
375+ context ( " when an update operation is executed " ) {
376+
377+ it ( " signals the operations " ) {
378+ waitForOperation (
379+ fromSignal: array. signal,
380+ when: {
381+ array [ 1 ] = 5
382+ } ,
383+ onUpdate: { ( value, index) in
384+ expect ( value) . to ( equal ( 5 ) )
385+ expect ( index) . to ( equal ( 1 ) )
386+ }
387+ )
388+ }
389+
390+ }
391+
368392 context ( " when a delete operation is executed " ) {
369393
370394 it ( " signals the operations " ) {
@@ -411,7 +435,7 @@ class ReactiveArraySpec: QuickSpec {
411435 . take ( 1 )
412436 . collect ( )
413437 . startWithNext { counts in
414- expect ( counts) . to ( equal ( [ countBeforeOperation + 1 ] ) )
438+ expect ( counts) . to ( equal ( [ countBeforeOperation + 2 ] ) )
415439 done ( )
416440 }
417441
@@ -422,6 +446,21 @@ class ReactiveArraySpec: QuickSpec {
422446
423447 }
424448
449+ context ( " when an update operation is executed " ) {
450+
451+ beforeEach {
452+ producer = producer. skip ( 1 )
453+ }
454+
455+ it ( " updates the count " ) {
456+ waitUntil { done in
457+ array [ 1 ] = 656
458+ expect ( array. count) . to ( equal ( countBeforeOperation) )
459+ done ( )
460+ }
461+ }
462+
463+ }
425464
426465 context ( " when an append operation is executed " ) {
427466
0 commit comments