reacto 0.1.0 → 1.0.0

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.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/README.md +932 -11
  4. data/doc/reactive_programming_with_reacto.md +238 -0
  5. data/lib/reacto.rb +70 -0
  6. data/lib/reacto/behaviours.rb +24 -1
  7. data/lib/reacto/constants.rb +4 -1
  8. data/lib/reacto/executors.rb +8 -10
  9. data/lib/reacto/labeled_trackable.rb +14 -2
  10. data/lib/reacto/operations.rb +23 -2
  11. data/lib/reacto/operations/act.rb +69 -0
  12. data/lib/reacto/operations/append.rb +45 -0
  13. data/lib/reacto/operations/blocking_enumerable.rb +40 -0
  14. data/lib/reacto/operations/buffer.rb +1 -4
  15. data/lib/reacto/operations/chunk.rb +81 -0
  16. data/lib/reacto/operations/chunk_while.rb +56 -0
  17. data/lib/reacto/operations/cycle.rb +27 -0
  18. data/lib/reacto/operations/delay_each.rb +75 -0
  19. data/lib/reacto/operations/depend_on.rb +4 -5
  20. data/lib/reacto/operations/diff.rb +8 -10
  21. data/lib/reacto/operations/drop.rb +6 -8
  22. data/lib/reacto/operations/drop_while.rb +23 -0
  23. data/lib/reacto/operations/each_collect.rb +57 -0
  24. data/lib/reacto/operations/each_with_object.rb +31 -0
  25. data/lib/reacto/operations/extremums.rb +54 -0
  26. data/lib/reacto/operations/find_index.rb +28 -0
  27. data/lib/reacto/operations/flat_map.rb +2 -2
  28. data/lib/reacto/operations/flatten.rb +2 -7
  29. data/lib/reacto/operations/flatten_labeled.rb +44 -0
  30. data/lib/reacto/operations/{label.rb → group_by_label.rb} +1 -1
  31. data/lib/reacto/operations/include.rb +40 -0
  32. data/lib/reacto/operations/inject.rb +15 -9
  33. data/lib/reacto/operations/map.rb +15 -13
  34. data/lib/reacto/operations/merge.rb +17 -16
  35. data/lib/reacto/operations/operation_on_labeled.rb +29 -0
  36. data/lib/reacto/operations/partition.rb +52 -0
  37. data/lib/reacto/operations/prepend.rb +0 -3
  38. data/lib/reacto/operations/rescue_and_replace_error.rb +21 -0
  39. data/lib/reacto/operations/retry.rb +26 -0
  40. data/lib/reacto/operations/retry_when.rb +30 -0
  41. data/lib/reacto/operations/select.rb +2 -6
  42. data/lib/reacto/operations/slice.rb +50 -0
  43. data/lib/reacto/operations/slice_when.rb +41 -0
  44. data/lib/reacto/operations/split_labeled.rb +32 -0
  45. data/lib/reacto/operations/take.rb +9 -14
  46. data/lib/reacto/operations/take_while.rb +28 -0
  47. data/lib/reacto/operations/throttle.rb +2 -3
  48. data/lib/reacto/operations/track_on.rb +1 -3
  49. data/lib/reacto/shared_trackable.rb +2 -5
  50. data/lib/reacto/subscriptions/buffered_subscription.rb +10 -9
  51. data/lib/reacto/subscriptions/executor_subscription.rb +12 -4
  52. data/lib/reacto/subscriptions/tracker_subscription.rb +0 -4
  53. data/lib/reacto/subscriptions/zipping_subscription.rb +0 -1
  54. data/lib/reacto/trackable.rb +429 -64
  55. data/lib/reacto/version.rb +1 -1
  56. data/reacto.gemspec +2 -3
  57. data/spec/reacto/labeled_trackable_spec.rb +17 -0
  58. data/spec/reacto/trackable/act_spec.rb +15 -0
  59. data/spec/reacto/trackable/all_spec.rb +38 -0
  60. data/spec/reacto/trackable/any_spec.rb +39 -0
  61. data/spec/reacto/trackable/append_spec.rb +38 -0
  62. data/spec/reacto/trackable/buffer_spec.rb +11 -15
  63. data/spec/reacto/trackable/chunk_spec.rb +86 -0
  64. data/spec/reacto/trackable/chunk_while_spec.rb +22 -0
  65. data/spec/reacto/trackable/class_level/combine_last_spec.rb +1 -3
  66. data/spec/reacto/trackable/class_level/interval_spec.rb +4 -6
  67. data/spec/reacto/trackable/class_level/make_spec.rb +0 -15
  68. data/spec/reacto/trackable/{zip_spec.rb → class_level/zip_spec.rb} +0 -2
  69. data/spec/reacto/trackable/concat_spec.rb +12 -12
  70. data/spec/reacto/trackable/count_spec.rb +38 -0
  71. data/spec/reacto/trackable/cycle_spec.rb +14 -0
  72. data/spec/reacto/trackable/delay_each_spec.rb +18 -0
  73. data/spec/reacto/trackable/depend_on_spec.rb +6 -9
  74. data/spec/reacto/trackable/diff_spec.rb +3 -5
  75. data/spec/reacto/trackable/drop_errors_spec.rb +1 -3
  76. data/spec/reacto/trackable/drop_while_spec.rb +15 -0
  77. data/spec/reacto/trackable/each_cons_spec.rb +53 -0
  78. data/spec/reacto/trackable/each_slice_spec.rb +37 -0
  79. data/spec/reacto/trackable/each_with_index_spec.rb +33 -0
  80. data/spec/reacto/trackable/each_with_object_spec.rb +26 -0
  81. data/spec/reacto/trackable/entries_spec.rb +25 -0
  82. data/spec/reacto/trackable/execute_on_spec.rb +33 -0
  83. data/spec/reacto/trackable/find_index_spec.rb +31 -0
  84. data/spec/reacto/trackable/find_spec.rb +34 -0
  85. data/spec/reacto/trackable/first_spec.rb +36 -0
  86. data/spec/reacto/trackable/flat_map_latest_spec.rb +5 -5
  87. data/spec/reacto/trackable/flat_map_spec.rb +25 -0
  88. data/spec/reacto/trackable/flatten_labeled_spec.rb +48 -0
  89. data/spec/reacto/trackable/grep_spec.rb +29 -0
  90. data/spec/reacto/trackable/grep_v_spec.rb +23 -0
  91. data/spec/reacto/trackable/{label_spec.rb → group_by_label_spec.rb} +4 -11
  92. data/spec/reacto/trackable/include_spec.rb +23 -0
  93. data/spec/reacto/trackable/inject_spec.rb +30 -4
  94. data/spec/reacto/trackable/lift_spec.rb +1 -3
  95. data/spec/reacto/trackable/map_spec.rb +17 -3
  96. data/spec/reacto/trackable/max_by_spec.rb +12 -0
  97. data/spec/reacto/trackable/max_spec.rb +19 -0
  98. data/spec/reacto/trackable/merge_spec.rb +6 -7
  99. data/spec/reacto/trackable/min_by_spec.rb +12 -0
  100. data/spec/reacto/trackable/min_spec.rb +19 -0
  101. data/spec/reacto/trackable/minmax_by_spec.rb +12 -0
  102. data/spec/reacto/trackable/minmax_spec.rb +19 -0
  103. data/spec/reacto/trackable/none_spec.rb +38 -0
  104. data/spec/reacto/trackable/on_spec.rb +11 -4
  105. data/spec/reacto/trackable/one_spec.rb +38 -0
  106. data/spec/reacto/trackable/partition_spec.rb +23 -0
  107. data/spec/reacto/trackable/prepend_spec.rb +1 -3
  108. data/spec/reacto/trackable/reject_spec.rb +21 -0
  109. data/spec/reacto/trackable/rescue_and_replace_error_spec.rb +48 -0
  110. data/spec/reacto/trackable/rescue_and_replace_error_with_spec.rb +26 -0
  111. data/spec/reacto/trackable/retry_spec.rb +50 -0
  112. data/spec/reacto/trackable/retry_when_spec.rb +33 -0
  113. data/spec/reacto/trackable/select_spec.rb +18 -7
  114. data/spec/reacto/trackable/slice_after_spec.rb +38 -0
  115. data/spec/reacto/trackable/slice_before_spec.rb +38 -0
  116. data/spec/reacto/trackable/slice_when_spec.rb +26 -0
  117. data/spec/reacto/trackable/sort_by_spec.rb +16 -0
  118. data/spec/reacto/trackable/sort_spec.rb +23 -0
  119. data/spec/reacto/trackable/split_labeled_spec.rb +37 -0
  120. data/spec/reacto/trackable/take_while_spec.rb +16 -0
  121. data/spec/reacto/trackable/throttle_spec.rb +2 -3
  122. data/spec/reacto/trackable/track_on_spec.rb +2 -3
  123. data/spec/reacto/trackable/uniq_spec.rb +2 -4
  124. data/spec/support/helpers.rb +9 -1
  125. metadata +135 -25
  126. data/Gemfile.lock +0 -32
  127. data/lib/reacto/operations/cache.rb +0 -53
  128. data/spec/reacto/trackable/cache_spec.rb +0 -64
@@ -1,4 +1,4 @@
1
1
  module Reacto
2
- VERSION = '0.1.0'
2
+ VERSION = '1.0.0'
3
3
  end
4
4
 
data/reacto.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.authors = ['Nickolay Tzvetinov - Meddle']
12
12
  spec.email = ['n.tzvetinov@gmail.com']
13
13
  spec.description = 'Concurrent Reactive Programming for Ruby'
14
- spec.summary = 'Concurrent Reactive Programming for Ruby'
14
+ spec.summary = 'Reactive Programming for Ruby with some concurrency thrown into the mix.'
15
15
  spec.homepage = 'https://github.com/meddle0x53/reacto'
16
16
  spec.license = 'MIT'
17
17
 
@@ -22,6 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency 'bundler', '~> 1.3'
23
23
  spec.add_development_dependency 'rspec', '~> 3.3.0'
24
24
 
25
- spec.add_dependency 'concurrent-ruby', '~> 1.0.0'
25
+ spec.add_dependency 'concurrent-ruby', '~> 1.0.2'
26
26
  end
27
-
@@ -0,0 +1,17 @@
1
+ context Reacto::LabeledTrackable do
2
+ subject do
3
+ described_class.new('label') do |subscriber|
4
+ subscriber.on_value(5)
5
+ subscriber.on_value(15)
6
+ subscriber.on_close
7
+ end
8
+ end
9
+
10
+ context '#relabel' do
11
+ it 'creates new LabeledTrackable with label created by the block passed' do
12
+ trackable = subject.relabel { |label| label.gsub('l', 'r') }
13
+
14
+ expect(trackable.label).to eq('raber')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ context Reacto::Trackable do
2
+ context '#act' do
3
+ it 'can be used to do something with the currently incloming data, ' \
4
+ 'without changing it (if imuttable), for example logging' do
5
+ notifications = []
6
+
7
+ trackable = described_class.enumerable((1..20)).act do |notification|
8
+ notifications << notification
9
+ end
10
+ trackable.on(value: test_on_value)
11
+
12
+ expect(notifications.size).to eq(21)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,38 @@
1
+ context Reacto::Trackable do
2
+ context '#all?' do
3
+ it 'passes each incoming value to the given block. The resulting ' \
4
+ 'Reacto::Trackable emits only one value - `true` if the block never ' \
5
+ 'returns `false` or `nil`. Test true.' do
6
+ trackable = described_class.enumerable((1..5)).all? do |value|
7
+ value < 6
8
+ end
9
+
10
+ trackable.on(value: test_on_value)
11
+
12
+ expect(test_data.size).to be(1)
13
+ expect(test_data.first).to be(true)
14
+ end
15
+
16
+ it 'passes each incoming value to the given block. The resulting ' \
17
+ 'Reacto::Trackable emits only one value - `true` if the block never ' \
18
+ 'returns `false` or `nil`. Test false.' do
19
+ trackable = described_class.enumerable((1..7)).all? do |value|
20
+ value < 6
21
+ end
22
+
23
+ trackable.on(value: test_on_value)
24
+
25
+ expect(test_data.size).to be(1)
26
+ expect(test_data.first).to be(false)
27
+ end
28
+
29
+ it 'if the block is not given, adds an implicit block of { |obj| obj }' do
30
+ trackable = described_class.enumerable((1..7)).all?
31
+
32
+ trackable.on(value: test_on_value)
33
+
34
+ expect(test_data.size).to be(1)
35
+ expect(test_data.first).to be(true)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ context Reacto::Trackable do
2
+ context '#any?' do
3
+ it 'passes each incoming value to the given block. The resulting ' \
4
+ 'Reacto::Trackable emits only one value - `true` if the block returns ' \
5
+ 'even one `true`. Test true.' do
6
+ trackable = described_class.enumerable((5..10)).any? do |value|
7
+ value < 6
8
+ end
9
+
10
+ trackable.on(value: test_on_value)
11
+
12
+ expect(test_data.size).to be(1)
13
+ expect(test_data.first).to be(true)
14
+ end
15
+
16
+ it 'passes each incoming value to the given block. The resulting ' \
17
+ 'Reacto::Trackable emits only one value - `true` if the block returns ' \
18
+ 'even one `true`. Test false.' do
19
+ trackable = described_class.enumerable((6..10)).any? do |value|
20
+ value < 6
21
+ end
22
+
23
+ trackable.on(value: test_on_value)
24
+
25
+ expect(test_data.size).to be(1)
26
+ expect(test_data.first).to be(false)
27
+ end
28
+
29
+ it 'if the block is not given, adds an implicit block of { |obj| obj }' do
30
+ trackable = described_class.enumerable([nil, nil]).any?
31
+
32
+ trackable.on(value: test_on_value)
33
+
34
+ expect(test_data.size).to be(1)
35
+ expect(test_data.first).to be(false)
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,38 @@
1
+ context Reacto::Trackable do
2
+ context '#append' do
3
+ it 'emits a given enumerable after all the values, incoming from the ' \
4
+ 'caller are emitted' do
5
+ source = described_class.enumerable((1..5))
6
+ trackable = source.append((6..10))
7
+
8
+ trackable.on(value: test_on_value)
9
+
10
+ expect(test_data.size).to be(10)
11
+ expect(test_data).to eq((1..10).to_a)
12
+ end
13
+
14
+ it 'does not append anything if `condition: :source_empty` is given ' \
15
+ 'and the source has emitted values' do
16
+ source = described_class.enumerable((1..5))
17
+ trackable = source.append((6..10), condition: :source_empty)
18
+
19
+ trackable.on(value: test_on_value)
20
+
21
+ expect(test_data.size).to be(5)
22
+ expect(test_data).to eq((1..5).to_a)
23
+ end
24
+
25
+ it 'emits a given enumerable after the `close` notification, incoming ' \
26
+ 'from the caller is emitted if `condition: :source_empty` is given and ' \
27
+ 'no values were emitted' do
28
+ source = described_class.close
29
+ trackable = source.append((6..10), condition: :source_empty)
30
+
31
+ trackable.on(value: test_on_value)
32
+
33
+ expect(test_data.size).to be(5)
34
+ expect(test_data).to eq((6..10).to_a)
35
+ end
36
+ end
37
+ end
38
+
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  context Reacto::Trackable do
4
2
  context '#buffer' do
5
3
  context 'count' do
@@ -9,8 +7,9 @@ context Reacto::Trackable do
9
7
  value: test_on_value, close: test_on_close, error: test_on_error
10
8
  )
11
9
 
12
- expect(test_data).to be ==
10
+ expect(test_data).to eq(
13
11
  [(1..5).to_a, (6..10).to_a, (11..15).to_a, (16..20).to_a, '|']
12
+ )
14
13
  end
15
14
  end
16
15
 
@@ -21,15 +20,14 @@ context Reacto::Trackable do
21
20
  value: test_on_value, close: test_on_close, error: test_on_error
22
21
  )
23
22
  trackable.await(subscription)
24
- expect(test_data).to be ==
25
- [
26
- [0, 1, 2, 3],
27
- [4, 5, 6, 7, 8],
28
- [9, 10, 11, 12, 13],
29
- [14, 15, 16, 17, 18],
30
- [19],
31
- "|"
32
- ]
23
+ expect(test_data).to eq([
24
+ [0, 1, 2, 3],
25
+ [4, 5, 6, 7, 8],
26
+ [9, 10, 11, 12, 13],
27
+ [14, 15, 16, 17, 18],
28
+ [19],
29
+ '|'
30
+ ])
33
31
  end
34
32
  end
35
33
 
@@ -49,10 +47,8 @@ context Reacto::Trackable do
49
47
  trackable.on(
50
48
  value: test_on_value, close: test_on_close, error: test_on_error
51
49
  )
52
- expect(test_data).to be ==
53
- [[1, 2, 3], [4, 5], [6], '|']
50
+ expect(test_data).to eq([[1, 2, 3], [4, 5], [6], '|'])
54
51
  end
55
52
  end
56
53
  end
57
54
  end
58
-
@@ -0,0 +1,86 @@
1
+ context Reacto::Trackable do
2
+ context '#chunk' do
3
+ def expect_values(trackable, label, expected)
4
+ expect_trackable_values(trackable, expected, label: label)
5
+ end
6
+
7
+ let(:data) { [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] }
8
+ subject(:test_source) { described_class.enumerable(data) }
9
+
10
+ it 'creates a Reacto::Trackable which chunks the incoming values ' \
11
+ 'together based on the return value of the given block. ' \
12
+ 'The chuncks are emitted as LabeledTrackable instances' do
13
+ trackable = test_source.chunk { |v| v.even? }
14
+
15
+ attach_test_trackers(trackable)
16
+
17
+ expect(test_data.length).to be(6)
18
+ expect_values(test_data.first, false, [3, 1])
19
+ expect_values(test_data[1], true, [4])
20
+ expect_values(test_data[2], false, [1, 5, 9])
21
+ expect_values(test_data[3], true, [2, 6])
22
+ expect_values(test_data[4], false, [5, 3, 5])
23
+ expect(test_data.last).to eq('|')
24
+ end
25
+
26
+ it 'uses nil as flag to group items' \
27
+ 'together based on the return value of the given block. ' \
28
+ 'The chuncks are emitted as LabeledTrackable instances' do
29
+ trackable = test_source.chunk { |v| v.even? ? 'even' : nil }
30
+
31
+ attach_test_trackers(trackable)
32
+
33
+ expect(test_data.length).to be(3)
34
+ expect_values(test_data.first, 'even', [4])
35
+ expect_values(test_data[1], 'even', [2, 6])
36
+ expect(test_data.last).to eq('|')
37
+ end
38
+
39
+ it 'uses :_separator as flag to group items' \
40
+ 'together based on the return value of the given block. ' \
41
+ 'The chuncks are emitted as LabeledTrackable instances' do
42
+ trackable = test_source.chunk { |v| v.even? ? :_separator : 'odd' }
43
+
44
+ attach_test_trackers(trackable)
45
+
46
+ expect(test_data.length).to be(4)
47
+ expect_values(test_data.first, 'odd', [3, 1])
48
+ expect_values(test_data[1], 'odd', [1, 5, 9])
49
+ expect_values(test_data[2], 'odd', [5, 3, 5])
50
+ expect(test_data.last).to eq('|')
51
+ end
52
+
53
+ it 'uses :_alone as flag to emit a LabeledTrackable which emits only one ' \
54
+ 'value, the one marked as :_alone' do
55
+ trackable = test_source.chunk do |v|
56
+ v.even? ? :_alone : 'odd'
57
+ end
58
+
59
+ attach_test_trackers(trackable)
60
+
61
+ expect(test_data.length).to be(7)
62
+ expect_values(test_data.first, 'odd', [3, 1])
63
+ expect_values(test_data[1], :_alone, [4])
64
+ expect_values(test_data[2], 'odd', [1, 5, 9])
65
+ expect_values(test_data[3], :_alone, [2])
66
+ expect_values(test_data[4], :_alone, [6])
67
+ expect_values(test_data[5], 'odd', [5, 3, 5])
68
+ expect(test_data.last).to eq('|')
69
+ end
70
+
71
+ it 'emits an error if the label returned by the ckunking function is a ' \
72
+ 'symbol, which starts with `_` and it is not :_separator or :_alone' do
73
+ trackable = test_source.chunk do |v|
74
+ v.even? ? :_stuff : 'odd'
75
+ end
76
+
77
+ attach_test_trackers(trackable)
78
+
79
+ expect(test_data.length).to be(2)
80
+ expect_values(test_data.first, 'odd', [3, 1])
81
+ expect(test_data.last).to eq(RuntimeError.new(
82
+ 'symbols beginning with an underscore are reserved'
83
+ ))
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,22 @@
1
+ context Reacto::Trackable do
2
+ context '#chunk_while' do
3
+
4
+ let(:data) { [1, 2, 4, 9, 10, 11, 12, 15, 16, 19, 20, 21] }
5
+ subject(:source_trackable) { described_class.enumerable(data) }
6
+
7
+ it 'emits a Trackable for each chunked values. ' \
8
+ 'The beginnings of chunks are defined by the block.' do
9
+ trackable = source_trackable.chunk_while { |i, j| i + 1 == j }
10
+
11
+ attach_test_trackers(trackable)
12
+
13
+ expect(test_data.length).to be(6)
14
+ expect_trackable_values(test_data.first, [1, 2])
15
+ expect_trackable_values(test_data[1], [4])
16
+ expect_trackable_values(test_data[2], [9, 10, 11, 12])
17
+ expect_trackable_values(test_data[3], [15, 16])
18
+ expect_trackable_values(test_data[4], [19, 20, 21])
19
+ expect(test_data.last).to eq('|')
20
+ end
21
+ end
22
+ end
@@ -1,9 +1,7 @@
1
- require 'spec_helper'
2
-
3
1
  context Reacto::Trackable do
4
2
  context '.combine_last' do
5
3
  it 'combines the notifications of Trackables based on their ' \
6
- 'sequence number - the first notification of the sources, then ' \
4
+ 'sequence number - the first notifications of the sources, then ' \
7
5
  'the next ones and in the end closes if any of the sources closes' do
8
6
  trackable1 = described_class.interval(0.3).take(4)
9
7
  trackable2 = described_class.interval(0.7, ('a'..'b').each)
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  context Reacto::Trackable do
4
2
  context '.interval' do
5
3
  it 'emits an infinite sequence of number on every n seconds by default' do
@@ -8,7 +6,7 @@ context Reacto::Trackable do
8
6
  sleep 1
9
7
  subscription.unsubscribe
10
8
 
11
- expect(test_data).to be == (0..2).to_a
9
+ expect(test_data).to eq((0..2).to_a)
12
10
  end
13
11
 
14
12
  it 'can use any enumerator to produce the sequence to emit' do
@@ -17,7 +15,7 @@ context Reacto::Trackable do
17
15
  sleep 1
18
16
  subscription.unsubscribe
19
17
 
20
- expect(test_data).to be == ('a'..'i').to_a
18
+ expect(test_data).to include(*('a'..'i').to_a)
21
19
  end
22
20
 
23
21
  it 'handles interval of intervals' do
@@ -28,7 +26,7 @@ context Reacto::Trackable do
28
26
 
29
27
  trackable.await(subscription)
30
28
 
31
- expect(test_data).to be == (10..15).to_a + ['|']
29
+ expect(test_data).to eq((10..15).to_a + ['|'])
32
30
  end
33
31
 
34
32
  it 'can use the immediate executor to block the current thread while ' \
@@ -38,7 +36,7 @@ context Reacto::Trackable do
38
36
  )
39
37
  subscription = attach_test_trackers(trackable)
40
38
 
41
- expect(test_data).to be == (1..5).to_a + ['|']
39
+ expect(test_data).to eq((1..5).to_a + ['|'])
42
40
  end
43
41
  end
44
42
  end
@@ -2,21 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  context Reacto::Trackable do
4
4
  context '.make' do
5
- it 'creates a new trackable with custom behaviour passed as lambda' do
6
- behaviour = lambda do |tracker|
7
- (1..10).each do |v|
8
- tracker.on_value(v)
9
- end
10
-
11
- tracker.on_close
12
- end
13
-
14
- attach_test_trackers described_class.make(behaviour)
15
-
16
- expect(test_data.size).to be(11)
17
- expect(test_data).to be == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, '|']
18
- end
19
-
20
5
  it 'creates a new trackable with custom behaviour passed as block' do
21
6
  trackable = described_class.make do |tracker|
22
7
  (1..10).each do |v|
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  context Reacto::Trackable do
4
2
  context '.zip' do
5
3
  it 'combines the first notifications of the source Trackable instances, ' \
@@ -1,34 +1,34 @@
1
- require 'spec_helper'
2
-
3
1
  context Reacto::Trackable do
2
+ subject(:test_source) { described_class.enumerable((1..5)) }
3
+
4
4
  context '#concat' do
5
5
  it 'starts emitting the values from the concatenated after emitting the ' \
6
6
  'values from the source, then emits a `close` notification' do
7
- trackable = source.concat(described_class.enumerable((6..10)))
7
+ trackable = test_source.concat(described_class.enumerable((6..10)))
8
8
  trackable.on(value: test_on_value, close: test_on_close)
9
9
 
10
- expect(test_data).to be == (5..10).to_a + ['|']
10
+ expect(test_data).to eq((1..10).to_a + ['|'])
11
11
  end
12
12
 
13
13
  it 'can be chained' do
14
- trackable = source
15
- .concat(described_class.enumerable((6..8)))
16
- .concat(described_class.enumerable((9..10)))
14
+ trackable = test_source
15
+ .concat(described_class.enumerable((6..8)))
16
+ .concat(described_class.enumerable((9..10)))
17
17
  trackable.on(value: test_on_value, close: test_on_close)
18
18
 
19
- expect(test_data).to be == (5..10).to_a + ['|']
19
+ expect(test_data).to eq((1..10).to_a + ['|'])
20
20
  end
21
21
 
22
22
  it 'closes on error' do
23
23
  err = StandardError.new('Hey')
24
- trackable = source
25
- .concat(described_class.error(err))
26
- .concat(described_class.enumerable((9..10)))
24
+ trackable = test_source
25
+ .concat(described_class.error(err))
26
+ .concat(described_class.enumerable((9..10)))
27
27
  trackable.on(
28
28
  value: test_on_value, close: test_on_close, error: test_on_error
29
29
  )
30
30
 
31
- expect(test_data).to be == [5, err]
31
+ expect(test_data).to eq([1, 2, 3, 4, 5, err])
32
32
  end
33
33
  end
34
34
  end