ione 1.3.0.pre2 → 1.3.0.pre3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/ione/future.rb +5 -3
- data/lib/ione/io/acceptor.rb +1 -0
- data/lib/ione/io/base_connection.rb +2 -0
- data/lib/ione/io/connection.rb +1 -0
- data/lib/ione/io/io_reactor.rb +6 -6
- data/lib/ione/io/ssl_connection.rb +1 -0
- data/lib/ione/version.rb +1 -1
- data/spec/integration/io_spec.rb +3 -3
- data/spec/integration/ssl_spec.rb +7 -2
- data/spec/ione/byte_buffer_spec.rb +38 -38
- data/spec/ione/future_spec.rb +64 -65
- data/spec/ione/heap_spec.rb +18 -18
- data/spec/ione/io/acceptor_spec.rb +5 -5
- data/spec/ione/io/connection_common.rb +2 -2
- data/spec/ione/io/io_reactor_spec.rb +19 -19
- data/spec/ione/io/ssl_acceptor_spec.rb +3 -3
- data/spec/ione/io/ssl_connection_spec.rb +3 -3
- data/spec/spec_helper.rb +4 -0
- data/spec/support/fake_server.rb +1 -0
- metadata +16 -18
data/spec/ione/future_spec.rb
CHANGED
@@ -91,7 +91,7 @@ module Ione
|
|
91
91
|
promise.try do
|
92
92
|
3 + 4
|
93
93
|
end
|
94
|
-
promise.future.value.should
|
94
|
+
promise.future.value.should eq(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
|
108
|
+
promise.future.value.should eq(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
|
220
|
-
v2.should
|
219
|
+
v1.should eq('bar')
|
220
|
+
v2.should eq('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
|
322
|
+
value.should eq('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 =>
|
328
|
+
future.on_complete { |f| begin; f.value; rescue => e; err = e; end }
|
329
329
|
promise.fail(error)
|
330
|
-
err.message.should
|
330
|
+
err.message.should eq('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
|
338
|
+
v.should eq('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
|
348
|
+
e.message.should eq('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
|
380
|
-
v2.should
|
379
|
+
v1.should eq('bar')
|
380
|
+
v2.should eq('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
|
388
|
+
value.should eq('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
|
397
|
-
v2.should
|
396
|
+
v1.should eq('bar')
|
397
|
+
v2.should eq('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
|
482
|
+
future.value.should eq('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
|
509
|
+
listeners.map(&:value).should eq(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
|
527
|
+
mapped_value.should eq(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
|
536
|
+
mapped_value.should eq(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
|
545
|
+
mapped_value.should eq(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
|
584
|
+
f.value.should eq(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
|
601
|
+
f.value.should eq(: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
|
611
|
+
f.value.should eq(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
|
623
|
+
f.value.should eq(: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
|
644
|
+
f.value.should eq(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
|
665
|
+
f.value.should eq('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
|
672
|
+
f.value.should eq('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
|
679
|
+
f.value.should eq('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
|
693
|
+
f.value.should eq(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
|
700
|
+
f.value.should eq('bar')
|
701
701
|
end
|
702
702
|
|
703
703
|
it 'fails with the error raised in the given block' do
|
@@ -717,17 +717,16 @@ module Ione
|
|
717
717
|
f = p1.future.fallback { p2.future }
|
718
718
|
p1.fail(error)
|
719
719
|
p2.fulfill('foo')
|
720
|
-
f.value.should
|
720
|
+
f.value.should eq('foo')
|
721
721
|
end
|
722
722
|
|
723
723
|
it 'yields the error to the block' do
|
724
|
-
|
725
|
-
|
726
|
-
f = p1.future.fallback do |error|
|
724
|
+
p = Promise.new
|
725
|
+
f = p.future.fallback do |error|
|
727
726
|
Future.resolved(error.message)
|
728
727
|
end
|
729
|
-
|
730
|
-
f.value.should
|
728
|
+
p.fail(error)
|
729
|
+
f.value.should eq(error.message)
|
731
730
|
end
|
732
731
|
|
733
732
|
it 'is resolved with the value of the source future when the source future fullfills' do
|
@@ -736,7 +735,7 @@ module Ione
|
|
736
735
|
f = p1.future.fallback { p2.future }
|
737
736
|
p2.fulfill('bar')
|
738
737
|
p1.fulfill('foo')
|
739
|
-
f.value.should
|
738
|
+
f.value.should eq('foo')
|
740
739
|
end
|
741
740
|
|
742
741
|
it 'fails when the block raises an error' do
|
@@ -761,7 +760,7 @@ module Ione
|
|
761
760
|
p = Promise.new
|
762
761
|
f = p.future.fallback { fake_future }
|
763
762
|
p.fail(error)
|
764
|
-
f.value.should
|
763
|
+
f.value.should eq('foo')
|
765
764
|
end
|
766
765
|
end
|
767
766
|
end
|
@@ -771,7 +770,7 @@ module Ione
|
|
771
770
|
future = Future.traverse([1, 2, 3]) do |element|
|
772
771
|
Future.resolved(element * 2)
|
773
772
|
end
|
774
|
-
future.value.should
|
773
|
+
future.value.should eq([2, 4, 6])
|
775
774
|
end
|
776
775
|
|
777
776
|
it 'fails if any of the source futures fail' do
|
@@ -800,12 +799,12 @@ module Ione
|
|
800
799
|
fake_future = double(:fake_future)
|
801
800
|
fake_future.stub(:on_complete) { |&listener| listener.call(:foobar, nil) }
|
802
801
|
future = Future.traverse([1, 2, 3]) { fake_future }
|
803
|
-
future.value.should
|
802
|
+
future.value.should eq([:foobar, :foobar, :foobar])
|
804
803
|
end
|
805
804
|
|
806
805
|
it 'accepts an enumerable of values' do
|
807
806
|
future = Future.traverse([1, 2, 3].to_enum) { |v| Future.resolved(v * 2) }
|
808
|
-
future.value.should
|
807
|
+
future.value.should eq([2, 4, 6])
|
809
808
|
end
|
810
809
|
end
|
811
810
|
|
@@ -819,7 +818,7 @@ module Ione
|
|
819
818
|
future = Future.reduce(futures, {}) do |accumulator, value|
|
820
819
|
accumulator.merge(value)
|
821
820
|
end
|
822
|
-
future.value.should
|
821
|
+
future.value.should eq({'foo' => 'bar', 'qux' => 'baz', 'hello' => 'world'})
|
823
822
|
end
|
824
823
|
|
825
824
|
it 'accepts boolean accumulators' do
|
@@ -830,7 +829,7 @@ module Ione
|
|
830
829
|
future = Future.reduce(futures, false) do |accumulator, value|
|
831
830
|
accumulator || value.empty?
|
832
831
|
end
|
833
|
-
future.value.should
|
832
|
+
future.value.should eq(true)
|
834
833
|
end
|
835
834
|
|
836
835
|
it 'calls the block with the values in the order of the source futures' do
|
@@ -844,7 +843,7 @@ module Ione
|
|
844
843
|
promises[2].fulfill(2)
|
845
844
|
promises[4].fulfill(4)
|
846
845
|
promises[3].fulfill(3)
|
847
|
-
future.value.should
|
846
|
+
future.value.should eq([0, 1, 2, 3, 4])
|
848
847
|
end
|
849
848
|
|
850
849
|
it 'uses the first value as initial value when no intial value is given' do
|
@@ -856,7 +855,7 @@ module Ione
|
|
856
855
|
promises[1].fulfill(2)
|
857
856
|
promises[0].fulfill(1)
|
858
857
|
promises[2].fulfill(3)
|
859
|
-
future.value.should
|
858
|
+
future.value.should eq(6)
|
860
859
|
end
|
861
860
|
|
862
861
|
it 'fails if any of the source futures fail' do
|
@@ -893,7 +892,7 @@ module Ione
|
|
893
892
|
|
894
893
|
context 'when the list of futures is empty' do
|
895
894
|
it 'returns a future that resolves to the initial value' do
|
896
|
-
Future.reduce([], :foo).value.should
|
895
|
+
Future.reduce([], :foo).value.should eq(:foo)
|
897
896
|
end
|
898
897
|
|
899
898
|
it 'returns a future that resolves to nil there is also no initial value' do
|
@@ -907,13 +906,13 @@ module Ione
|
|
907
906
|
ff2.stub(:on_complete) { |&listener| listener.call(2, nil) }
|
908
907
|
ff3.stub(:on_complete) { |&listener| listener.call(3, nil) }
|
909
908
|
future = Future.reduce([ff1, ff2, ff3], 0) { |sum, n| sum + n }
|
910
|
-
future.value.should
|
909
|
+
future.value.should eq(6)
|
911
910
|
end
|
912
911
|
|
913
912
|
it 'accepts an enumerable of futures' do
|
914
913
|
futures = [Future.resolved(1), Future.resolved(2), Future.resolved(3)].to_enum
|
915
914
|
future = Future.reduce(futures, 0) { |sum, n| sum + n }
|
916
|
-
future.value.should
|
915
|
+
future.value.should eq(6)
|
917
916
|
end
|
918
917
|
|
919
918
|
it 'handles a really long list of futures' do
|
@@ -932,7 +931,7 @@ module Ione
|
|
932
931
|
promises[1].fulfill(1)
|
933
932
|
promises[0].fulfill(0)
|
934
933
|
promises[2].fulfill(2)
|
935
|
-
future.value.should
|
934
|
+
future.value.should eq([1, 0, 2])
|
936
935
|
end
|
937
936
|
|
938
937
|
it 'fails if any of the source futures fail' do
|
@@ -963,7 +962,7 @@ module Ione
|
|
963
962
|
|
964
963
|
context 'when the list of futures is empty' do
|
965
964
|
it 'returns a future that resolves to the initial value' do
|
966
|
-
Future.reduce([], :foo, ordered: false).value.should
|
965
|
+
Future.reduce([], :foo, ordered: false).value.should eq(:foo)
|
967
966
|
end
|
968
967
|
|
969
968
|
it 'returns a future that resolves to nil there is also no initial value' do
|
@@ -1088,7 +1087,7 @@ module Ione
|
|
1088
1087
|
p2.fulfill(2)
|
1089
1088
|
p1.fulfill(1)
|
1090
1089
|
p3.fulfill(3)
|
1091
|
-
f.value.should
|
1090
|
+
f.value.should eq([1, 2, 3])
|
1092
1091
|
end
|
1093
1092
|
|
1094
1093
|
it 'fails if any of the source futures fail' do
|
@@ -1106,20 +1105,20 @@ module Ione
|
|
1106
1105
|
end
|
1107
1106
|
|
1108
1107
|
it 'completes with an empty list when no futures are given' do
|
1109
|
-
Future.all.value.should
|
1108
|
+
Future.all.value.should eq([])
|
1110
1109
|
end
|
1111
1110
|
|
1112
1111
|
it 'completes with an empty list when an empty list is given' do
|
1113
|
-
Future.all([]).value.should
|
1112
|
+
Future.all([]).value.should eq([])
|
1114
1113
|
end
|
1115
1114
|
|
1116
1115
|
it 'completes with an empty list when an empty enumerable is given' do
|
1117
|
-
Future.all([].to_enum).value.should
|
1116
|
+
Future.all([].to_enum).value.should eq([])
|
1118
1117
|
end
|
1119
1118
|
|
1120
1119
|
it 'completes with a list of one item when a single future is given' do
|
1121
1120
|
f = Future.resolved(1)
|
1122
|
-
Future.all(f).value.should
|
1121
|
+
Future.all(f).value.should eq([1])
|
1123
1122
|
end
|
1124
1123
|
|
1125
1124
|
it 'accepts a list of futures' do
|
@@ -1152,7 +1151,7 @@ module Ione
|
|
1152
1151
|
ff2.stub(:on_complete) { |&listener| listener.call(2, nil) }
|
1153
1152
|
ff3.stub(:on_complete) { |&listener| listener.call(3, nil) }
|
1154
1153
|
future = Future.all(ff1, ff2, ff3)
|
1155
|
-
future.value.should
|
1154
|
+
future.value.should eq([1, 2, 3])
|
1156
1155
|
end
|
1157
1156
|
end
|
1158
1157
|
end
|
@@ -1174,7 +1173,7 @@ module Ione
|
|
1174
1173
|
p3 = Promise.new
|
1175
1174
|
f = Future.first(p1.future, p2.future, p3.future)
|
1176
1175
|
p2.fulfill('foo')
|
1177
|
-
f.value.should
|
1176
|
+
f.value.should eq('foo')
|
1178
1177
|
end
|
1179
1178
|
|
1180
1179
|
it 'is unaffected by the fullfillment of the other futures' do
|
@@ -1226,7 +1225,7 @@ module Ione
|
|
1226
1225
|
end
|
1227
1226
|
|
1228
1227
|
it 'completes with the value of the given future, when only one is given' do
|
1229
|
-
Future.first(Future.resolved('foo')).value.should
|
1228
|
+
Future.first(Future.resolved('foo')).value.should eq('foo')
|
1230
1229
|
end
|
1231
1230
|
|
1232
1231
|
it 'accepts a list of futures' do
|
@@ -1250,7 +1249,7 @@ module Ione
|
|
1250
1249
|
ff1.stub(:on_complete) { |&listener| listener.call(1, nil) }
|
1251
1250
|
ff2.stub(:on_complete) { |&listener| listener.call(2, nil) }
|
1252
1251
|
future = Future.first(ff1, ff2)
|
1253
|
-
future.value.should
|
1252
|
+
future.value.should eq(1)
|
1254
1253
|
end
|
1255
1254
|
end
|
1256
1255
|
end
|
@@ -1276,14 +1275,14 @@ module Ione
|
|
1276
1275
|
it 'calls its value callbacks immediately' do
|
1277
1276
|
value = nil
|
1278
1277
|
future.on_value { |v| value = v }
|
1279
|
-
value.should
|
1278
|
+
value.should eq('hello world')
|
1280
1279
|
end
|
1281
1280
|
|
1282
1281
|
it 'calls its complete callbacks immediately' do
|
1283
1282
|
f, v = nil, nil
|
1284
1283
|
future.on_complete { |vv, _, ff| f = ff; v = vv }
|
1285
1284
|
f.should equal(future)
|
1286
|
-
v.should
|
1285
|
+
v.should eq('hello world')
|
1287
1286
|
end
|
1288
1287
|
|
1289
1288
|
it 'calls its complete callbacks with the right arity' do
|
@@ -1293,11 +1292,11 @@ module Ione
|
|
1293
1292
|
future.on_complete { |vv, ee, ff| f2 = ff }
|
1294
1293
|
f1.should equal(future)
|
1295
1294
|
f2.should equal(future)
|
1296
|
-
v.should
|
1295
|
+
v.should eq('hello world')
|
1297
1296
|
end
|
1298
1297
|
|
1299
1298
|
it 'does not block on #value' do
|
1300
|
-
future.value.should
|
1299
|
+
future.value.should eq('hello world')
|
1301
1300
|
end
|
1302
1301
|
|
1303
1302
|
it 'defaults to the value nil' do
|
@@ -1327,14 +1326,14 @@ module Ione
|
|
1327
1326
|
it 'call its failure callbacks immediately' do
|
1328
1327
|
error = nil
|
1329
1328
|
future.on_failure { |e| error = e }
|
1330
|
-
error.message.should
|
1329
|
+
error.message.should eq('bork')
|
1331
1330
|
end
|
1332
1331
|
|
1333
1332
|
it 'calls its complete callbacks immediately' do
|
1334
1333
|
f, e = nil, nil
|
1335
1334
|
future.on_complete { |_, ee, ff| f = ff; e = ee }
|
1336
1335
|
f.should equal(future)
|
1337
|
-
e.message.should
|
1336
|
+
e.message.should eq('bork')
|
1338
1337
|
end
|
1339
1338
|
|
1340
1339
|
it 'calls its complete callbacks with the right arity' do
|
@@ -1344,7 +1343,7 @@ module Ione
|
|
1344
1343
|
future.on_complete { |vv, ee, ff| f2 = ff }
|
1345
1344
|
f1.should equal(future)
|
1346
1345
|
f2.should equal(future)
|
1347
|
-
e.message.should
|
1346
|
+
e.message.should eq('bork')
|
1348
1347
|
end
|
1349
1348
|
|
1350
1349
|
it 'does not block on #value' do
|
data/spec/ione/heap_spec.rb
CHANGED
@@ -17,9 +17,9 @@ module Ione
|
|
17
17
|
it 'returns the number of items in the heap' do
|
18
18
|
heap.push(13)
|
19
19
|
heap.push(100)
|
20
|
-
heap.size.should
|
20
|
+
heap.size.should eq(2)
|
21
21
|
heap.push(101)
|
22
|
-
heap.size.should
|
22
|
+
heap.size.should eq(3)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -40,7 +40,7 @@ module Ione
|
|
40
40
|
heap.push(3)
|
41
41
|
heap.push(6)
|
42
42
|
heap.push(5)
|
43
|
-
heap.size.should
|
43
|
+
heap.size.should eq(4)
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'is aliased as #<<' do
|
@@ -48,14 +48,14 @@ module Ione
|
|
48
48
|
heap << 3
|
49
49
|
heap << 6
|
50
50
|
heap << 5
|
51
|
-
heap.size.should
|
51
|
+
heap.size.should eq(4)
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'does not add duplicates' do
|
55
55
|
heap << 3
|
56
56
|
heap << 3
|
57
57
|
heap << 3
|
58
|
-
heap.size.should
|
58
|
+
heap.size.should eq(1)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -66,21 +66,21 @@ module Ione
|
|
66
66
|
|
67
67
|
it 'returns the only item when there is only one' do
|
68
68
|
heap.push(3)
|
69
|
-
heap.peek.should
|
69
|
+
heap.peek.should eq(3)
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'returns the smallest item' do
|
73
73
|
heap.push(10)
|
74
74
|
heap.push(3)
|
75
75
|
heap.push(7)
|
76
|
-
heap.peek.should
|
76
|
+
heap.peek.should eq(3)
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'does not remove the item from the heap' do
|
80
80
|
heap.push(3)
|
81
|
-
heap.peek.should
|
82
|
-
heap.peek.should
|
83
|
-
heap.peek.should
|
81
|
+
heap.peek.should eq(3)
|
82
|
+
heap.peek.should eq(3)
|
83
|
+
heap.peek.should eq(3)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -91,7 +91,7 @@ module Ione
|
|
91
91
|
|
92
92
|
it 'returns and removes the only item when there is only one' do
|
93
93
|
heap.push(3)
|
94
|
-
heap.pop.should
|
94
|
+
heap.pop.should eq(3)
|
95
95
|
heap.should be_empty
|
96
96
|
end
|
97
97
|
|
@@ -99,14 +99,14 @@ module Ione
|
|
99
99
|
heap.push(10)
|
100
100
|
heap.push(3)
|
101
101
|
heap.push(7)
|
102
|
-
heap.pop.should
|
103
|
-
heap.pop.should
|
104
|
-
heap.size.should
|
102
|
+
heap.pop.should eq(3)
|
103
|
+
heap.pop.should eq(7)
|
104
|
+
heap.size.should eq(1)
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'removes the item from the heap' do
|
108
108
|
heap.push(3)
|
109
|
-
heap.pop.should
|
109
|
+
heap.pop.should eq(3)
|
110
110
|
heap.pop.should be_nil
|
111
111
|
end
|
112
112
|
end
|
@@ -125,8 +125,8 @@ module Ione
|
|
125
125
|
heap.push(101)
|
126
126
|
heap.delete(4)
|
127
127
|
heap.pop
|
128
|
-
heap.peek.should
|
129
|
-
heap.size.should
|
128
|
+
heap.peek.should eq(100)
|
129
|
+
heap.size.should eq(2)
|
130
130
|
end
|
131
131
|
|
132
132
|
it 'removes the last item from the heap' do
|
@@ -155,7 +155,7 @@ module Ione
|
|
155
155
|
heap.push(3)
|
156
156
|
heap.push(4)
|
157
157
|
heap.push(5)
|
158
|
-
heap.delete(4).should
|
158
|
+
heap.delete(4).should eq(4)
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'returns nil when the item is not found' do
|
@@ -174,8 +174,8 @@ module Ione
|
|
174
174
|
acceptor.bind
|
175
175
|
acceptor.read
|
176
176
|
accepted_handlers.should have(1).item
|
177
|
-
accepted_handlers.first.host.should
|
178
|
-
accepted_handlers.first.port.should
|
177
|
+
accepted_handlers.first.host.should eq('example.com')
|
178
|
+
accepted_handlers.first.port.should eq(3333)
|
179
179
|
end
|
180
180
|
|
181
181
|
it 'passes the unblocker along to the connection handler' do
|
@@ -197,9 +197,9 @@ module Ione
|
|
197
197
|
acceptor.on_accept { |c| received_connection2 = c }
|
198
198
|
acceptor.bind
|
199
199
|
acceptor.read
|
200
|
-
received_connection1.host.should
|
201
|
-
received_connection2.host.should
|
202
|
-
received_connection2.port.should
|
200
|
+
received_connection1.host.should eq('example.com')
|
201
|
+
received_connection2.host.should eq('example.com')
|
202
|
+
received_connection2.port.should eq(3333)
|
203
203
|
end
|
204
204
|
|
205
205
|
it 'ignores exceptions raised by the connection callback' do
|
@@ -40,7 +40,7 @@ shared_examples_for 'a connection' do |options|
|
|
40
40
|
handler.on_closed { calls += 1 }
|
41
41
|
handler.close
|
42
42
|
handler.close
|
43
|
-
calls.should
|
43
|
+
calls.should eq(1)
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'returns false if it did nothing' do
|
@@ -251,7 +251,7 @@ shared_examples_for 'a connection' do |options|
|
|
251
251
|
data = nil
|
252
252
|
handler.on_data { |d| data = d }
|
253
253
|
handler.read
|
254
|
-
data.should
|
254
|
+
data.should eq('foo bar')
|
255
255
|
end
|
256
256
|
|
257
257
|
context 'when #read_nonblock raises an error' do
|