ione 1.2.4 → 1.3.0.pre0

Sign up to get free protection for your applications and to get access to all the features.
@@ -91,7 +91,7 @@ module Ione
91
91
  promise.try do
92
92
  3 + 4
93
93
  end
94
- promise.future.value.should eq(7)
94
+ promise.future.value.should == 7
95
95
  end
96
96
 
97
97
  it 'fails the promise when the block raises an error' do
@@ -105,7 +105,7 @@ module Ione
105
105
  promise.try(:foo, 3) do |a, b|
106
106
  a.length + b
107
107
  end
108
- promise.future.value.should eq(6)
108
+ promise.future.value.should == 6
109
109
  end
110
110
 
111
111
  it 'returns nil' do
@@ -216,8 +216,8 @@ module Ione
216
216
  future.on_complete { |v, _| v1 = v }
217
217
  future.on_complete { |v, _| v2 = v }
218
218
  promise.fulfill('bar')
219
- v1.should eq('bar')
220
- v2.should eq('bar')
219
+ v1.should == 'bar'
220
+ v2.should == 'bar'
221
221
  end
222
222
 
223
223
  it 'passes future as the third parameter to the block when it expects three arguments' do
@@ -319,15 +319,15 @@ module Ione
319
319
  future.on_complete { |f| raise 'Blurgh' }
320
320
  future.on_complete { |f| value = f.value }
321
321
  promise.fulfill('bar')
322
- value.should eq('bar')
322
+ value.should == 'bar'
323
323
  end
324
324
 
325
325
  it 'notifies all listeners when the promise fails, even when one raises an error' do
326
326
  err = nil
327
327
  future.on_complete { |f| raise 'Blurgh' }
328
- future.on_complete { |f| begin; f.value; rescue => e; err = e; end }
328
+ future.on_complete { |f| begin; f.value; rescue => err; e = err; end }
329
329
  promise.fail(error)
330
- err.message.should eq('bork')
330
+ err.message.should == 'bork'
331
331
  end
332
332
 
333
333
  it 'notifies listeners registered after the promise was fulfilled' do
@@ -335,7 +335,7 @@ module Ione
335
335
  promise.fulfill('bar')
336
336
  future.on_complete { |vv, ee, ff| v = vv; e = ee; f = ff }
337
337
  f.should equal(future)
338
- v.should eq('bar')
338
+ v.should == 'bar'
339
339
  e.should be_nil
340
340
  end
341
341
 
@@ -345,7 +345,7 @@ module Ione
345
345
  future.on_complete { |vv, ee, ff| v = vv; e = ee; f = ff }
346
346
  f.should equal(future)
347
347
  v.should be_nil
348
- e.message.should eq('bork')
348
+ e.message.should == 'bork'
349
349
  end
350
350
 
351
351
  it 'notifies listeners registered after the promise failed' do
@@ -376,8 +376,8 @@ module Ione
376
376
  future.on_value { |v| v1 = v }
377
377
  future.on_value { |v| v2 = v }
378
378
  promise.fulfill('bar')
379
- v1.should eq('bar')
380
- v2.should eq('bar')
379
+ v1.should == 'bar'
380
+ v2.should == 'bar'
381
381
  end
382
382
 
383
383
  it 'notifies all listeners even when one raises an error' do
@@ -385,7 +385,7 @@ module Ione
385
385
  future.on_value { |v| raise 'Blurgh' }
386
386
  future.on_value { |v| value = v }
387
387
  promise.fulfill('bar')
388
- value.should eq('bar')
388
+ value.should == 'bar'
389
389
  end
390
390
 
391
391
  it 'notifies listeners registered after the promise was resolved' do
@@ -393,8 +393,8 @@ module Ione
393
393
  promise.fulfill('bar')
394
394
  future.on_value { |v| v1 = v }
395
395
  future.on_value { |v| v2 = v }
396
- v1.should eq('bar')
397
- v2.should eq('bar')
396
+ v1.should == 'bar'
397
+ v2.should == 'bar'
398
398
  end
399
399
 
400
400
  it 'does not raise any error when the listener raises an error when already resolved' do
@@ -479,7 +479,7 @@ module Ione
479
479
  p.fulfill('bar')
480
480
  end
481
481
  d.value
482
- future.value.should eq('bar')
482
+ future.value.should == 'bar'
483
483
  end
484
484
 
485
485
  it 'blocks on #value until completed, when value is nil' do
@@ -506,7 +506,7 @@ module Ione
506
506
  end
507
507
  sleep 0.1
508
508
  promise.fulfill(:hello)
509
- listeners.map(&:value).should eq(Array.new(10, :hello))
509
+ listeners.map(&:value).should == Array.new(10, :hello)
510
510
  end
511
511
 
512
512
  it 'is aliased as #get' do
@@ -524,7 +524,7 @@ module Ione
524
524
  f = p.future.map { |v| v * 2 }
525
525
  f.on_value { |v| mapped_value = v }
526
526
  p.fulfill(3)
527
- mapped_value.should eq(3 * 2)
527
+ mapped_value.should == 3 * 2
528
528
  end
529
529
 
530
530
  it 'will be resolved with the specified value' do
@@ -533,7 +533,7 @@ module Ione
533
533
  f = p.future.map(7)
534
534
  f.on_value { |v| mapped_value = v }
535
535
  p.fulfill(3)
536
- mapped_value.should eq(7)
536
+ mapped_value.should == 7
537
537
  end
538
538
 
539
539
  it 'will be resolved with the result of the given block, even if a value is specified' do
@@ -542,7 +542,7 @@ module Ione
542
542
  f = p.future.map(7) { |v| v * 2 }
543
543
  f.on_value { |v| mapped_value = v }
544
544
  p.fulfill(3)
545
- mapped_value.should eq(3 * 2)
545
+ mapped_value.should == 3 * 2
546
546
  end
547
547
 
548
548
  it 'will be resolved with nil when neither value nor block is specified' do
@@ -581,7 +581,7 @@ module Ione
581
581
  p = Promise.new
582
582
  f = p.future.flat_map { |v| Future.resolved(v * 2) }
583
583
  p.fulfill(3)
584
- f.value.should eq(3 * 2)
584
+ f.value.should == 3 * 2
585
585
  end
586
586
 
587
587
  it 'fails when the block raises an error' do
@@ -598,7 +598,7 @@ module Ione
598
598
  p = Promise.new
599
599
  f = p.future.flat_map { fake_future }
600
600
  p.fulfill
601
- f.value.should eq(:foobar)
601
+ f.value.should == :foobar
602
602
  end
603
603
  end
604
604
 
@@ -608,7 +608,7 @@ module Ione
608
608
  p = Promise.new
609
609
  f = p.future.then { |v| Future.resolved(v * 2) }
610
610
  p.fulfill(3)
611
- f.value.should eq(3 * 2)
611
+ f.value.should == 3 * 2
612
612
  end
613
613
  end
614
614
 
@@ -620,7 +620,7 @@ module Ione
620
620
  p = Promise.new
621
621
  f = p.future.then { |v| fake_future }
622
622
  p.fulfill
623
- f.value.should eq(:foobar)
623
+ f.value.should == :foobar
624
624
  end
625
625
  end
626
626
 
@@ -641,7 +641,7 @@ module Ione
641
641
  p = Promise.new
642
642
  f = p.future.then { |v| v * 2 }
643
643
  p.fulfill(3)
644
- f.value.should eq(3 * 2)
644
+ f.value.should == 3 * 2
645
645
  end
646
646
  end
647
647
 
@@ -662,21 +662,21 @@ module Ione
662
662
  p = Promise.new
663
663
  f = p.future.recover { 'foo' }
664
664
  p.fail(error)
665
- f.value.should eq('foo')
665
+ f.value.should == 'foo'
666
666
  end
667
667
 
668
668
  it 'resolves to a specfied value when the source future fails' do
669
669
  p = Promise.new
670
670
  f = p.future.recover('bar')
671
671
  p.fail(error)
672
- f.value.should eq('bar')
672
+ f.value.should == 'bar'
673
673
  end
674
674
 
675
675
  it 'resovles to a value created by the block even when a value is specified when the source future fails' do
676
676
  p = Promise.new
677
677
  f = p.future.recover('bar') { 'foo' }
678
678
  p.fail(error)
679
- f.value.should eq('foo')
679
+ f.value.should == 'foo'
680
680
  end
681
681
 
682
682
  it 'resolves to nil value when no value nor block is specified and the source future fails' do
@@ -690,14 +690,14 @@ module Ione
690
690
  p = Promise.new
691
691
  f = p.future.recover { |e| e.message }
692
692
  p.fail(error)
693
- f.value.should eq(error.message)
693
+ f.value.should == error.message
694
694
  end
695
695
 
696
696
  it 'resolves to the value of the source future when the source future is resolved' do
697
697
  p = Promise.new
698
698
  f = p.future.recover { 'foo' }
699
699
  p.fulfill('bar')
700
- f.value.should eq('bar')
700
+ f.value.should == 'bar'
701
701
  end
702
702
 
703
703
  it 'fails with the error raised in the given block' do
@@ -717,16 +717,17 @@ module Ione
717
717
  f = p1.future.fallback { p2.future }
718
718
  p1.fail(error)
719
719
  p2.fulfill('foo')
720
- f.value.should eq('foo')
720
+ f.value.should == 'foo'
721
721
  end
722
722
 
723
723
  it 'yields the error to the block' do
724
- p = Promise.new
725
- f = p.future.fallback do |error|
724
+ p1 = Promise.new
725
+ p2 = Promise.new
726
+ f = p1.future.fallback do |error|
726
727
  Future.resolved(error.message)
727
728
  end
728
- p.fail(error)
729
- f.value.should eq(error.message)
729
+ p1.fail(error)
730
+ f.value.should == error.message
730
731
  end
731
732
 
732
733
  it 'is resolved with the value of the source future when the source future fullfills' do
@@ -735,7 +736,7 @@ module Ione
735
736
  f = p1.future.fallback { p2.future }
736
737
  p2.fulfill('bar')
737
738
  p1.fulfill('foo')
738
- f.value.should eq('foo')
739
+ f.value.should == 'foo'
739
740
  end
740
741
 
741
742
  it 'fails when the block raises an error' do
@@ -760,7 +761,7 @@ module Ione
760
761
  p = Promise.new
761
762
  f = p.future.fallback { fake_future }
762
763
  p.fail(error)
763
- f.value.should eq('foo')
764
+ f.value.should == 'foo'
764
765
  end
765
766
  end
766
767
  end
@@ -770,7 +771,7 @@ module Ione
770
771
  future = Future.traverse([1, 2, 3]) do |element|
771
772
  Future.resolved(element * 2)
772
773
  end
773
- future.value.should eq([2, 4, 6])
774
+ future.value.should == [2, 4, 6]
774
775
  end
775
776
 
776
777
  it 'fails if any of the source futures fail' do
@@ -799,12 +800,12 @@ module Ione
799
800
  fake_future = double(:fake_future)
800
801
  fake_future.stub(:on_complete) { |&listener| listener.call(:foobar, nil) }
801
802
  future = Future.traverse([1, 2, 3]) { fake_future }
802
- future.value.should eq([:foobar, :foobar, :foobar])
803
+ future.value.should == [:foobar, :foobar, :foobar]
803
804
  end
804
805
 
805
806
  it 'accepts an enumerable of values' do
806
807
  future = Future.traverse([1, 2, 3].to_enum) { |v| Future.resolved(v * 2) }
807
- future.value.should eq([2, 4, 6])
808
+ future.value.should == [2, 4, 6]
808
809
  end
809
810
  end
810
811
 
@@ -818,7 +819,7 @@ module Ione
818
819
  future = Future.reduce(futures, {}) do |accumulator, value|
819
820
  accumulator.merge(value)
820
821
  end
821
- future.value.should eq({'foo' => 'bar', 'qux' => 'baz', 'hello' => 'world'})
822
+ future.value.should == {'foo' => 'bar', 'qux' => 'baz', 'hello' => 'world'}
822
823
  end
823
824
 
824
825
  it 'accepts boolean accumulators' do
@@ -829,7 +830,7 @@ module Ione
829
830
  future = Future.reduce(futures, false) do |accumulator, value|
830
831
  accumulator || value.empty?
831
832
  end
832
- future.value.should eq(true)
833
+ future.value.should == true
833
834
  end
834
835
 
835
836
  it 'calls the block with the values in the order of the source futures' do
@@ -843,7 +844,7 @@ module Ione
843
844
  promises[2].fulfill(2)
844
845
  promises[4].fulfill(4)
845
846
  promises[3].fulfill(3)
846
- future.value.should eq([0, 1, 2, 3, 4])
847
+ future.value.should == [0, 1, 2, 3, 4]
847
848
  end
848
849
 
849
850
  it 'uses the first value as initial value when no intial value is given' do
@@ -855,7 +856,7 @@ module Ione
855
856
  promises[1].fulfill(2)
856
857
  promises[0].fulfill(1)
857
858
  promises[2].fulfill(3)
858
- future.value.should eq(6)
859
+ future.value.should == 6
859
860
  end
860
861
 
861
862
  it 'fails if any of the source futures fail' do
@@ -892,7 +893,7 @@ module Ione
892
893
 
893
894
  context 'when the list of futures is empty' do
894
895
  it 'returns a future that resolves to the initial value' do
895
- Future.reduce([], :foo).value.should eq(:foo)
896
+ Future.reduce([], :foo).value.should == :foo
896
897
  end
897
898
 
898
899
  it 'returns a future that resolves to nil there is also no initial value' do
@@ -906,13 +907,13 @@ module Ione
906
907
  ff2.stub(:on_complete) { |&listener| listener.call(2, nil) }
907
908
  ff3.stub(:on_complete) { |&listener| listener.call(3, nil) }
908
909
  future = Future.reduce([ff1, ff2, ff3], 0) { |sum, n| sum + n }
909
- future.value.should eq(6)
910
+ future.value.should == 6
910
911
  end
911
912
 
912
913
  it 'accepts an enumerable of futures' do
913
914
  futures = [Future.resolved(1), Future.resolved(2), Future.resolved(3)].to_enum
914
915
  future = Future.reduce(futures, 0) { |sum, n| sum + n }
915
- future.value.should eq(6)
916
+ future.value.should == 6
916
917
  end
917
918
 
918
919
  it 'handles a really long list of futures' do
@@ -931,7 +932,7 @@ module Ione
931
932
  promises[1].fulfill(1)
932
933
  promises[0].fulfill(0)
933
934
  promises[2].fulfill(2)
934
- future.value.should eq([1, 0, 2])
935
+ future.value.should == [1, 0, 2]
935
936
  end
936
937
 
937
938
  it 'fails if any of the source futures fail' do
@@ -962,7 +963,7 @@ module Ione
962
963
 
963
964
  context 'when the list of futures is empty' do
964
965
  it 'returns a future that resolves to the initial value' do
965
- Future.reduce([], :foo, ordered: false).value.should eq(:foo)
966
+ Future.reduce([], :foo, ordered: false).value.should == :foo
966
967
  end
967
968
 
968
969
  it 'returns a future that resolves to nil there is also no initial value' do
@@ -1087,7 +1088,7 @@ module Ione
1087
1088
  p2.fulfill(2)
1088
1089
  p1.fulfill(1)
1089
1090
  p3.fulfill(3)
1090
- f.value.should eq([1, 2, 3])
1091
+ f.value.should == [1, 2, 3]
1091
1092
  end
1092
1093
 
1093
1094
  it 'fails if any of the source futures fail' do
@@ -1105,20 +1106,20 @@ module Ione
1105
1106
  end
1106
1107
 
1107
1108
  it 'completes with an empty list when no futures are given' do
1108
- Future.all.value.should eq([])
1109
+ Future.all.value.should == []
1109
1110
  end
1110
1111
 
1111
1112
  it 'completes with an empty list when an empty list is given' do
1112
- Future.all([]).value.should eq([])
1113
+ Future.all([]).value.should == []
1113
1114
  end
1114
1115
 
1115
1116
  it 'completes with an empty list when an empty enumerable is given' do
1116
- Future.all([].to_enum).value.should eq([])
1117
+ Future.all([].to_enum).value.should == []
1117
1118
  end
1118
1119
 
1119
1120
  it 'completes with a list of one item when a single future is given' do
1120
1121
  f = Future.resolved(1)
1121
- Future.all(f).value.should eq([1])
1122
+ Future.all(f).value.should == [1]
1122
1123
  end
1123
1124
 
1124
1125
  it 'accepts a list of futures' do
@@ -1151,7 +1152,7 @@ module Ione
1151
1152
  ff2.stub(:on_complete) { |&listener| listener.call(2, nil) }
1152
1153
  ff3.stub(:on_complete) { |&listener| listener.call(3, nil) }
1153
1154
  future = Future.all(ff1, ff2, ff3)
1154
- future.value.should eq([1, 2, 3])
1155
+ future.value.should == [1, 2, 3]
1155
1156
  end
1156
1157
  end
1157
1158
  end
@@ -1173,7 +1174,7 @@ module Ione
1173
1174
  p3 = Promise.new
1174
1175
  f = Future.first(p1.future, p2.future, p3.future)
1175
1176
  p2.fulfill('foo')
1176
- f.value.should eq('foo')
1177
+ f.value.should == 'foo'
1177
1178
  end
1178
1179
 
1179
1180
  it 'is unaffected by the fullfillment of the other futures' do
@@ -1225,7 +1226,7 @@ module Ione
1225
1226
  end
1226
1227
 
1227
1228
  it 'completes with the value of the given future, when only one is given' do
1228
- Future.first(Future.resolved('foo')).value.should eq('foo')
1229
+ Future.first(Future.resolved('foo')).value.should == 'foo'
1229
1230
  end
1230
1231
 
1231
1232
  it 'accepts a list of futures' do
@@ -1249,7 +1250,7 @@ module Ione
1249
1250
  ff1.stub(:on_complete) { |&listener| listener.call(1, nil) }
1250
1251
  ff2.stub(:on_complete) { |&listener| listener.call(2, nil) }
1251
1252
  future = Future.first(ff1, ff2)
1252
- future.value.should eq(1)
1253
+ future.value.should == 1
1253
1254
  end
1254
1255
  end
1255
1256
  end
@@ -1275,14 +1276,14 @@ module Ione
1275
1276
  it 'calls its value callbacks immediately' do
1276
1277
  value = nil
1277
1278
  future.on_value { |v| value = v }
1278
- value.should eq('hello world')
1279
+ value.should == 'hello world'
1279
1280
  end
1280
1281
 
1281
1282
  it 'calls its complete callbacks immediately' do
1282
1283
  f, v = nil, nil
1283
1284
  future.on_complete { |vv, _, ff| f = ff; v = vv }
1284
1285
  f.should equal(future)
1285
- v.should eq('hello world')
1286
+ v.should == 'hello world'
1286
1287
  end
1287
1288
 
1288
1289
  it 'calls its complete callbacks with the right arity' do
@@ -1292,11 +1293,11 @@ module Ione
1292
1293
  future.on_complete { |vv, ee, ff| f2 = ff }
1293
1294
  f1.should equal(future)
1294
1295
  f2.should equal(future)
1295
- v.should eq('hello world')
1296
+ v.should == 'hello world'
1296
1297
  end
1297
1298
 
1298
1299
  it 'does not block on #value' do
1299
- future.value.should eq('hello world')
1300
+ future.value.should == 'hello world'
1300
1301
  end
1301
1302
 
1302
1303
  it 'defaults to the value nil' do
@@ -1326,14 +1327,14 @@ module Ione
1326
1327
  it 'call its failure callbacks immediately' do
1327
1328
  error = nil
1328
1329
  future.on_failure { |e| error = e }
1329
- error.message.should eq('bork')
1330
+ error.message.should == 'bork'
1330
1331
  end
1331
1332
 
1332
1333
  it 'calls its complete callbacks immediately' do
1333
1334
  f, e = nil, nil
1334
1335
  future.on_complete { |_, ee, ff| f = ff; e = ee }
1335
1336
  f.should equal(future)
1336
- e.message.should eq('bork')
1337
+ e.message.should == 'bork'
1337
1338
  end
1338
1339
 
1339
1340
  it 'calls its complete callbacks with the right arity' do
@@ -1343,7 +1344,7 @@ module Ione
1343
1344
  future.on_complete { |vv, ee, ff| f2 = ff }
1344
1345
  f1.should equal(future)
1345
1346
  f2.should equal(future)
1346
- e.message.should eq('bork')
1347
+ e.message.should == 'bork'
1347
1348
  end
1348
1349
 
1349
1350
  it 'does not block on #value' do