merge_enum 0.3.0 → 0.4.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.
@@ -3,470 +3,1072 @@ require File.expand_path(File.join('../', 'spec_helper'), File.dirname(__FILE__)
3
3
 
4
4
  describe MergeEnum::MergeEnumerable do
5
5
 
6
- describe "No Arguments to MergeEnumerable:" do
7
- it "count" do
8
- enum = MergeEnum::MergeEnumerable.new
9
- expect(enum.count).to be 0
10
- end
6
+ Target = MergeEnum::MergeEnumerable
11
7
 
12
- describe "option_first is" do
13
- it "positive" do
14
- enum = MergeEnum::MergeEnumerable.new first: 50
15
- expect(enum.count).to be 0
16
- end
17
- it "negative" do
18
- enum = MergeEnum::MergeEnumerable.new first: -50
19
- expect(enum.count).to be 0
20
- end
21
- it "nil" do
22
- enum = MergeEnum::MergeEnumerable.new first: nil
23
- expect(enum.count).to be 0
8
+ def self.test_empty ctx, lt, options = {}
9
+ test_all ctx, lt, [], options
10
+ end
11
+
12
+ def self.test_all ctx, lt, ary, options = {}
13
+ test_equal ctx, lt, ary, options
14
+ test_interrupt ctx, lt, ary, options
15
+ end
16
+
17
+ def self.test_equal ctx, lt, ary, options = {}
18
+ line = options[:line]
19
+ ctx.instance_eval do
20
+ _line = line ? " <at:#{line}>" : ""
21
+ context "#count#{_line}" do
22
+ subject { send(lt).count }
23
+ it { is_expected.to be ary.count }
24
24
  end
25
- it "false" do
26
- enum = MergeEnum::MergeEnumerable.new first: false
27
- expect(enum.count).to be 0
25
+ context "#to_a#{_line}" do
26
+ subject { send(lt).to_a }
27
+ it { is_expected.to eq ary.to_a }
28
28
  end
29
- it "true" do
30
- enum = MergeEnum::MergeEnumerable.new first: true
31
- expect{ enum.count }.to raise_error NoMethodError
29
+ end
30
+ end
31
+
32
+ def self.test_interrupt ctx, lt, ary, options = {}
33
+ line = options[:line]
34
+ ctx.instance_eval do
35
+ _line = line ? " <at:#{line}>" : ""
36
+ context "#none?#{_line}" do
37
+ subject { send(lt).none? }
38
+ it { is_expected.to be ary.none? }
32
39
  end
33
- it "illegal" do
34
- enum = MergeEnum::MergeEnumerable.new first: "hoge"
35
- expect(enum.count).to be 0
40
+ context "#any?#{_line}" do
41
+ subject { send(lt).any? }
42
+ it { is_expected.to be ary.any? }
36
43
  end
37
44
  end
45
+ end
38
46
 
39
- describe "option_compact is" do
40
- it "true" do
41
- enum = MergeEnum::MergeEnumerable.new compact: true
42
- expect(enum.count).to be 0
43
- end
44
- it "false" do
45
- enum = MergeEnum::MergeEnumerable.new compact: false
46
- expect(enum.count).to be 0
47
+ def self.test_error ctx, lt, options = {}
48
+ line = options[:line]
49
+ ctx.instance_eval do
50
+ _line = line ? " <at:#{line}>" : ""
51
+ context "#count#{_line}" do
52
+ subject { send(lt).count }
53
+ it { expect{ is_expected }.to raise_error }
47
54
  end
48
- it "nil" do
49
- enum = MergeEnum::MergeEnumerable.new compact: nil
50
- expect(enum.count).to be 0
55
+ context "#to_a#{_line}" do
56
+ subject { send(lt).to_a }
57
+ it { expect{ is_expected }.to raise_error }
51
58
  end
52
- it "Proc" do
53
- enum = MergeEnum::MergeEnumerable.new compact: Proc.new {}
54
- expect(enum.count).to be 0
59
+ context "#none?#{_line}" do
60
+ subject { send(lt).none? }
61
+ it { expect{ is_expected }.to raise_error }
55
62
  end
56
- it "Lambda" do
57
- enum = MergeEnum::MergeEnumerable.new compact: -> {}
58
- expect(enum.count).to be 0
63
+ context "#any?#{_line}" do
64
+ subject { send(lt).any? }
65
+ it { expect{ is_expected }.to raise_error }
59
66
  end
60
67
  end
61
68
  end
62
69
 
63
- describe "Empty Array to MergeEnumerable:" do
64
- it "count" do
65
- enum = MergeEnum::MergeEnumerable.new []
66
- expect(enum.count).to be 0
70
+ describe ".new nil" do
71
+ let(:enum) { Target.new nil }
72
+ test_error self, :enum, line: __LINE__
73
+ end
74
+
75
+ ["hoge", "foo", "bar"].each do |val|
76
+ describe ".new '#{val}'" do
77
+ let(:enum) { Target.new val }
78
+ test_error self, :enum, line: __LINE__
79
+ end
80
+ end
81
+
82
+ describe ".new [], nil" do
83
+ let(:enum) { Target.new [], nil }
84
+ test_error self, :enum, line: __LINE__
85
+ end
86
+
87
+ describe ".new" do
88
+
89
+ describe "{}" do
90
+ let(:enum) { Target.new }
91
+
92
+ test_empty self, :enum, line: __LINE__
67
93
  end
68
94
 
69
- describe "option_first" do
70
- it "positive" do
71
- enum = MergeEnum::MergeEnumerable.new [], first: 50
72
- expect(enum.count).to be 0
95
+ describe "first:" do
96
+ let(:enum) { Target.new first: first }
97
+
98
+ describe "0" do
99
+ let(:first) { 0 }
100
+ subject { enum }
101
+
102
+ test_empty self, :enum, line: __LINE__
73
103
  end
74
- it "negative" do
75
- enum = MergeEnum::MergeEnumerable.new [], first: -50
76
- expect(enum.count).to be 0
104
+
105
+ context "<positive>" do
106
+ [1, 2, 50].each do |val|
107
+ describe "#{val}" do
108
+ let(:first) { val }
109
+ test_empty self, :enum, line: __LINE__
110
+ end
111
+ end
77
112
  end
78
- it "nil" do
79
- enum = MergeEnum::MergeEnumerable.new [], first: nil
80
- expect(enum.count).to be 0
113
+
114
+ context "<negative>" do
115
+ [-1, -2, -50].each do |val|
116
+ describe "#{val}" do
117
+ let(:first) { val }
118
+ test_empty self, :enum, line: __LINE__
119
+ end
120
+ end
81
121
  end
82
- it "false" do
83
- enum = MergeEnum::MergeEnumerable.new [], first: false
84
- expect(enum.count).to be 0
122
+
123
+ describe "nil" do
124
+ let(:first) { nil }
125
+ test_empty self, :enum, line: __LINE__
85
126
  end
86
- it "true" do
87
- enum = MergeEnum::MergeEnumerable.new [], first: true
88
- expect{ enum.count }.to raise_error NoMethodError
127
+
128
+ describe "false" do
129
+ let(:first) { false }
130
+ test_empty self, :enum, line: __LINE__
89
131
  end
90
- it "with to_i" do
91
- enum = MergeEnum::MergeEnumerable.new 0...100, first: "hoge"
92
- expect(enum.count).to be 0
132
+
133
+ describe "true" do
134
+ let(:first) { true }
135
+ test_error self, :enum, line: __LINE__
93
136
  end
94
- it "with to_i" do
95
- enum = MergeEnum::MergeEnumerable.new 0...100, first: "10hoge"
96
- expect(enum.count).to be 10
137
+
138
+ context "<illegal>" do
139
+ ["hoge", "foo", "bar"].each do |val|
140
+ describe "'#{val}'" do
141
+ let(:first) { val }
142
+ test_empty self, :enum, line: __LINE__
143
+ end
144
+ end
97
145
  end
98
146
  end
99
147
 
100
- describe "option_compact" do
101
- it "true" do
102
- enum = MergeEnum::MergeEnumerable.new [], compact: true
103
- expect(enum.count).to be 0
148
+ describe "compact:" do
149
+ let(:enum) { Target.new compact: compact }
150
+
151
+ describe "true" do
152
+ let(:compact) { true }
153
+ test_empty self, :enum, line: __LINE__
104
154
  end
105
- it "false" do
106
- enum = MergeEnum::MergeEnumerable.new [], compact: false
107
- expect(enum.count).to be 0
155
+
156
+ describe "false" do
157
+ let(:compact) { false }
158
+ test_empty self, :enum, line: __LINE__
108
159
  end
109
- it "nil" do
110
- enum = MergeEnum::MergeEnumerable.new [], compact: nil
111
- expect(enum.count).to be 0
160
+
161
+ describe "nil" do
162
+ let(:compact) { nil }
163
+ test_empty self, :enum, line: __LINE__
112
164
  end
113
- it "Proc" do
114
- enum = MergeEnum::MergeEnumerable.new [], compact: Proc.new {}
115
- expect(enum.count).to be 0
165
+
166
+ describe "Proc.new {}" do
167
+ let(:compact) { Proc.new {} }
168
+ test_empty self, :enum, line: __LINE__
116
169
  end
117
- it "Lambda" do
118
- enum = MergeEnum::MergeEnumerable.new [], compact: -> {}
119
- expect(enum.count).to be 0
170
+
171
+ describe "-> {}" do
172
+ let(:compact) { -> {} }
173
+ test_empty self, :enum, line: __LINE__
120
174
  end
121
175
  end
122
- end
123
176
 
124
- describe "Illegal Argument to MergeEnumerable:" do
125
- it "illegal argument" do
126
- enum = MergeEnum::MergeEnumerable.new "hoge"
127
- expect{ enum.count }.to raise_error NoMethodError
177
+ describe "select:" do
178
+ let(:enum) { Target.new select: select }
179
+
180
+ describe "true" do
181
+ let(:select) { true }
182
+ test_error self, :enum, line: __LINE__
183
+ end
184
+
185
+ describe "false" do
186
+ let(:select) { false }
187
+ test_empty self, :enum, line: __LINE__
188
+ end
189
+
190
+ describe "nil" do
191
+ let(:select) { nil }
192
+ test_empty self, :enum, line: __LINE__
193
+ end
194
+
195
+ describe "Proc.new {}" do
196
+ let(:select) { Proc.new {} }
197
+ test_empty self, :enum, line: __LINE__
198
+ end
199
+
200
+ describe "-> {}" do
201
+ let(:select) { -> {} }
202
+ test_empty self, :enum, line: __LINE__
203
+ end
128
204
  end
129
205
  end
130
206
 
131
- describe "One Enumerable to MergeEnumerable:" do
132
- it "count" do
133
- enum = MergeEnum::MergeEnumerable.new 0...100
134
- expect(enum.count).to be 100
207
+ describe ".new []," do
208
+
209
+ describe "{}" do
210
+ let(:enum) { Target.new [], {} }
211
+
212
+ test_empty self, :enum, line: __LINE__
135
213
  end
136
214
 
137
- describe "option_first" do
138
- it "limited" do
139
- enum = MergeEnum::MergeEnumerable.new 0...100, first: 50
140
- expect(enum.count).to be 50
215
+ describe "first:" do
216
+ let(:enum) { Target.new [], first: first }
217
+
218
+ describe "0" do
219
+ let(:first) { 0 }
220
+ test_empty self, :enum, line: __LINE__
141
221
  end
142
- it "over" do
143
- enum = MergeEnum::MergeEnumerable.new 0...100, first: 200
144
- expect(enum.count).to be 100
222
+
223
+ context "<positive>" do
224
+ [1, 2, 50].each do |val|
225
+ describe "#{val}" do
226
+ let(:first) { val }
227
+ test_empty self, :enum, line: __LINE__
228
+ end
229
+ end
145
230
  end
146
- end
147
231
 
148
- describe "option_compact" do
149
- it "true" do
150
- ary = (0...100).map { |e| e.odd? ? e : nil }
151
- expect(ary.compact.count).to be 50
152
- expect(ary.count).to be 100
153
- enum = MergeEnum::MergeEnumerable.new ary, compact: true
154
- expect(enum.count).to be 50
232
+ context "<negative>" do
233
+ [-1, -2, -50].each do |val|
234
+ describe "#{val}" do
235
+ let(:first) { val }
236
+ test_empty self, :enum, line: __LINE__
237
+ end
238
+ end
155
239
  end
156
- it "false" do
157
- ary = (0...100).map { |e| e.odd? ? e : nil }
158
- enum = MergeEnum::MergeEnumerable.new ary, compact: false
159
- expect(enum.count).to be 100
240
+
241
+ describe "nil" do
242
+ let(:first) { nil }
243
+ test_empty self, :enum, line: __LINE__
160
244
  end
161
- it "nil" do
162
- ary = (0...100).map { |e| e.odd? ? e : nil }
163
- enum = MergeEnum::MergeEnumerable.new ary, compact: nil
164
- expect(enum.count).to be 100
245
+
246
+ describe "false" do
247
+ let(:first) { false }
248
+ test_empty self, :enum, line: __LINE__
165
249
  end
166
- it "Proc with no args" do
167
- ary = (0...100).map { |e| e.odd? ? e : nil }
168
- _proc = Proc.new { true }
169
- enum = MergeEnum::MergeEnumerable.new ary, compact: _proc
170
- expect(enum.count).to be 0
171
250
 
172
- _proc = Proc.new { false }
173
- enum = MergeEnum::MergeEnumerable.new ary, compact: _proc
174
- expect(enum.count).to be 100
251
+ describe "true" do
252
+ let(:first) { true }
253
+ test_error self, :enum, line: __LINE__
175
254
  end
176
- it "Proc with args" do
177
- ary = (0...100).map { |e| e.odd? ? e : nil }
178
- _proc = Proc.new { |e| e.nil? }
179
- enum = MergeEnum::MergeEnumerable.new ary, compact: _proc
180
- expect(enum.count).to be 50
181
255
 
182
- ary = 0...100
183
- _proc = Proc.new { |e| e < 30 }
184
- enum = MergeEnum::MergeEnumerable.new ary, compact: _proc
185
- expect(enum.count).to be 70
186
- end
187
- it "Lambda with no args" do
188
- ary = (0...100).map { |e| e.odd? ? e : nil }
189
- _proc = -> { true }
190
- enum = MergeEnum::MergeEnumerable.new ary, compact: _proc
191
- expect(enum.count).to be 0
192
- _proc = -> { false }
193
- enum = MergeEnum::MergeEnumerable.new ary, compact: _proc
194
- expect(enum.count).to be 100
195
- end
196
- it "Lambda with args" do
197
- ary = (0...100).map { |e| e.odd? ? e : nil }
198
- _proc = -> (e) { e.nil? }
199
- enum = MergeEnum::MergeEnumerable.new ary, compact: _proc
200
- expect(enum.count).to be 50
256
+ context "<illegal>" do
257
+ ["hoge", "foo", "bar"].each do |val|
258
+ describe "'#{val}'" do
259
+ let(:first) { val }
260
+ test_empty self, :enum, line: __LINE__
261
+ end
262
+ end
263
+ end
264
+ end
201
265
 
202
- ary = 0...100
203
- _proc = -> (e) { e < 30 }
204
- enum = MergeEnum::MergeEnumerable.new ary, compact: _proc
205
- expect(enum.count).to be 70
266
+ describe "compact:" do
267
+ let(:enum) { Target.new [], compact: compact }
268
+
269
+ describe "true" do
270
+ let(:compact) { true }
271
+ test_empty self, :enum, line: __LINE__
206
272
  end
207
- it "with option_first" do
208
- ary = (0...100).map { |e| e.odd? ? e : nil }
209
- _proc = -> (e) { e.nil? }
210
- enum = MergeEnum::MergeEnumerable.new ary, first: 30, compact: _proc
211
- expect(enum.count).to be 30
212
273
 
213
- enum = MergeEnum::MergeEnumerable.new ary, first: 60, compact: _proc
214
- expect(enum.count).to be 50
274
+ describe "false" do
275
+ let(:compact) { false }
276
+ test_empty self, :enum, line: __LINE__
215
277
  end
216
- end
217
- end
218
278
 
219
- describe "Two Enumerables to MergeEnumerable:" do
220
- it "count" do
221
- enum = MergeEnum::MergeEnumerable.new 0...100, 200...250
222
- expect(enum.count).to be 150
279
+ describe "nil" do
280
+ let(:compact) { nil }
281
+ test_empty self, :enum, line: __LINE__
282
+ end
283
+
284
+ describe "Proc.new {}" do
285
+ let(:compact) { Proc.new {} }
286
+ test_empty self, :enum, line: __LINE__
287
+ end
288
+
289
+ describe "-> {}" do
290
+ let(:compact) { -> {} }
291
+ test_empty self, :enum, line: __LINE__
292
+ end
223
293
  end
224
294
 
225
- describe "option_first" do
226
- it "limited at first" do
227
- enum = MergeEnum::MergeEnumerable.new 0...100, 200...250, first: 50
228
- expect(enum.count).to be 50
295
+ describe "select:" do
296
+ let(:enum) { Target.new select: select }
297
+
298
+ describe "true" do
299
+ let(:select) { true }
300
+ test_error self, :enum, line: __LINE__
229
301
  end
230
- it "limited at second" do
231
- enum = MergeEnum::MergeEnumerable.new 0...100, 200...250, first: 130
232
- expect(enum.count).to be 130
302
+
303
+ describe "false" do
304
+ let(:select) { false }
305
+ test_empty self, :enum, line: __LINE__
306
+ end
307
+
308
+ describe "nil" do
309
+ let(:select) { nil }
310
+ test_empty self, :enum, line: __LINE__
311
+ end
312
+
313
+ describe "Proc.new {}" do
314
+ let(:select) { Proc.new {} }
315
+ test_empty self, :enum, line: __LINE__
233
316
  end
234
- it "over" do
235
- enum = MergeEnum::MergeEnumerable.new 0...100, 200...250, first: 200
236
- expect(enum.count).to be 150
317
+
318
+ describe "-> {}" do
319
+ let(:select) { -> {} }
320
+ test_empty self, :enum, line: __LINE__
237
321
  end
238
322
  end
239
323
  end
240
324
 
241
- describe "Three Enumerables to MergeEnumerable:" do
242
- it "count" do
243
- enum = MergeEnum::MergeEnumerable.new 0...100, 200...250, 300...330
244
- expect(enum.count).to be 180
325
+ describe ".new" do
326
+ let(:enum) { Target.new ary }
327
+
328
+ describe "0...100" do
329
+ let(:ary) { 0...100 }
330
+ test_all self, :enum, 0...100, line: __LINE__
245
331
  end
332
+ end
333
+
334
+ describe ".new" do
335
+ let(:enum) { Target.new ary, first: first }
336
+
337
+ describe "0...100," do
338
+ let(:ary) { 0...100 }
339
+
340
+ describe "first:" do
341
+ describe "50" do
342
+ let(:first) { 50 }
343
+ test_all self, :enum, 0...50, line: __LINE__
344
+ end
246
345
 
247
- describe "option_first" do
248
- it "limited at first" do
249
- enum = MergeEnum::MergeEnumerable.new 0...100, 200...250, 300...330, first: 50
250
- expect(enum.count).to be 50
346
+ describe "200" do
347
+ let(:first) { 200 }
348
+ test_all self, :enum, 0...100, line: __LINE__
349
+ end
350
+
351
+ describe "'hoge'" do
352
+ let(:first) { "hoge" }
353
+ test_all self, :enum, 0...0, line: __LINE__
354
+ end
355
+
356
+ describe "'10hoge'" do
357
+ let(:first) { "10hoge" }
358
+ test_all self, :enum, 0...10, line: __LINE__
359
+ end
251
360
  end
252
- it "limited at second" do
253
- enum = MergeEnum::MergeEnumerable.new 0...100, 200...250, 300...330, first: 130
254
- expect(enum.count).to be 130
361
+ end
362
+ end
363
+
364
+ describe ".new" do
365
+ let(:enum) { Target.new ary, compact: compact }
366
+
367
+ describe "(0...100).map { |e| e.odd? ? e : nil }," do
368
+ let(:ary) { (0...100).map { |e| e.odd? ? e : nil } }
369
+
370
+ describe "compact:" do
371
+ describe "true" do
372
+ let(:compact) { true }
373
+ test_all self, :enum, (1...100).step(2), line: __LINE__
374
+ end
375
+
376
+ describe "false" do
377
+ let(:compact) { false }
378
+ test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
379
+ end
380
+
381
+ describe "nil" do
382
+ let(:compact) { nil }
383
+ test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
384
+ end
385
+
386
+ describe "Proc.new { true }" do
387
+ let(:compact) { Proc.new { true } }
388
+ test_all self, :enum, [], line: __LINE__
389
+ end
390
+
391
+ describe "Proc.new { false }" do
392
+ let(:compact) { Proc.new { false } }
393
+ test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
394
+ end
395
+
396
+ describe "Proc.new { |e| e.nil? }" do
397
+ let(:compact) { Proc.new { |e| e.nil? } }
398
+ test_all self, :enum, (1...100).step(2), line: __LINE__
399
+ end
400
+
401
+ describe "Proc.new { |e| e.nil? or e < 30 }" do
402
+ let(:compact) { Proc.new { |e| e.nil? or e < 30 } }
403
+ test_all self, :enum, (31...100).step(2), line: __LINE__
404
+ end
405
+
406
+ describe "-> { true }" do
407
+ let(:compact) { -> { true } }
408
+ test_all self, :enum, [], line: __LINE__
409
+ end
410
+
411
+ describe "-> { false }" do
412
+ let(:compact) { -> { false } }
413
+ test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
414
+ end
415
+
416
+ describe "-> (e) { e.nil? }" do
417
+ let(:compact) { -> (e) { e.nil? } }
418
+ test_all self, :enum, (1...100).step(2), line: __LINE__
419
+ end
420
+
421
+ describe "-> (e) { e.nil? or e < 30 }" do
422
+ let(:compact) { -> (e) { e.nil? or e < 30 } }
423
+ test_all self, :enum, (31...100).step(2), line: __LINE__
424
+ end
255
425
  end
256
- it "limited at third" do
257
- enum = MergeEnum::MergeEnumerable.new 0...100, 200...250, 300...330, first: 170
258
- expect(enum.count).to be 170
426
+ end
427
+ end
428
+
429
+ describe ".new" do
430
+ let(:enum) { Target.new ary, compact: compact, first: first }
431
+ describe "(0...100).map { |e| e.odd? ? e : nil }," do
432
+ let(:ary) { (0...100).map { |e| e.odd? ? e : nil } }
433
+ describe "compact:" do
434
+ describe "-> (e) { e.nil? }," do
435
+ let(:compact) { -> (e) { e.nil? } }
436
+
437
+ describe "first:" do
438
+ describe "30" do
439
+ let(:first) { 30 }
440
+ test_all self, :enum, (1...60).step(2), line: __LINE__
441
+ end
442
+
443
+ describe "60" do
444
+ let(:first) { 60 }
445
+ test_all self, :enum, (1...100).step(2), line: __LINE__
446
+ end
447
+ end
448
+ end
259
449
  end
260
- it "over" do
261
- enum = MergeEnum::MergeEnumerable.new 0...100, 200...250, 300...330, first: 200
262
- expect(enum.count).to be 180
450
+ end
451
+ end
452
+
453
+ describe ".new" do
454
+ let(:enum) { Target.new ary, select: select }
455
+
456
+ describe "(0...100).map { |e| e.odd? ? e : nil }," do
457
+ let(:ary) { (0...100).map { |e| e.odd? ? e : nil } }
458
+
459
+ describe "select:" do
460
+ describe "nil" do
461
+ let(:select) { nil }
462
+ test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
463
+ end
464
+
465
+ describe "Proc.new { true }" do
466
+ let(:select) { Proc.new { true } }
467
+ test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
468
+ end
469
+
470
+ describe "Proc.new { false }" do
471
+ let(:select) { Proc.new { false } }
472
+ test_all self, :enum, [], line: __LINE__
473
+ end
474
+
475
+ describe "Proc.new { |e| e.nil? }" do
476
+ let(:select) { Proc.new { |e| e.nil? } }
477
+ test_all self, :enum, Array.new(50, nil), line: __LINE__
478
+ end
479
+
480
+ describe "Proc.new { |e| not e.nil? and e < 30 }" do
481
+ let(:select) { Proc.new { |e| not e.nil? and e < 30 } }
482
+ test_all self, :enum, (1...30).step(2), line: __LINE__
483
+ end
484
+
485
+ describe "-> { true }" do
486
+ let(:select) { -> { true } }
487
+ test_all self, :enum, (0...100).map { |e| e.odd? ? e : nil }, line: __LINE__
488
+ end
489
+
490
+ describe "-> { false }" do
491
+ let(:select) { -> { false } }
492
+ test_all self, :enum, [], line: __LINE__
493
+ end
494
+
495
+ describe "-> (e) { e.nil? }" do
496
+ let(:select) { -> (e) { e.nil? } }
497
+ test_all self, :enum, Array.new(50, nil), line: __LINE__
498
+ end
499
+
500
+ describe "-> (e) { not e.nil? and e < 30 }" do
501
+ let(:select) { -> (e) { not e.nil? and e < 30 } }
502
+ test_all self, :enum, (1...30).step(2), line: __LINE__
503
+ end
263
504
  end
264
505
  end
265
506
  end
266
507
 
267
- describe "Lambda to MergeEnumerable:" do
268
- describe "option_first" do
269
- it "limited at first" do
270
- enum = MergeEnum::MergeEnumerable.new(
271
- -> { 0...100 },
272
- -> { 200...250 },
273
- first: 50
274
- )
275
- expect(enum.count).to be 50
276
- end
277
- it "over" do
278
- enum = MergeEnum::MergeEnumerable.new(
279
- -> { 0...100 },
280
- -> { 200...250 },
281
- first: 200
282
- )
283
- expect(enum.count).to be 150
508
+ describe ".new" do
509
+ let(:enum) { Target.new ary, select: select, first: first }
510
+ describe "(0...100).map { |e| e.odd? ? e : nil }," do
511
+ let(:ary) { (0...100).map { |e| e.odd? ? e : nil } }
512
+ describe "select:" do
513
+ describe "-> (e) { e.nil? }," do
514
+ let(:select) { -> (e) { e.nil? } }
515
+
516
+ describe "first:" do
517
+ describe "30" do
518
+ let(:first) { 30 }
519
+ test_all self, :enum, Array.new(30, nil), line: __LINE__
520
+ end
521
+
522
+ describe "60" do
523
+ let(:first) { 60 }
524
+ test_all self, :enum, Array.new(50, nil), line: __LINE__
525
+ end
526
+ end
527
+ end
284
528
  end
285
529
  end
286
530
  end
287
531
 
288
- describe "Lambda with Arguments to MergeEnumerable:" do
289
- describe "option_first" do
290
- it "limited at first" do
291
- arg1, arg2 = nil, nil
292
- enum = MergeEnum::MergeEnumerable.new(
293
- -> (c) { arg1 = c; 0...100 },
294
- -> (c) { raise "unexpect"; 200...250 },
295
- first: 50
296
- )
297
- expect(enum.count).to be 50
298
- expect(arg1).to be 50
299
- expect(arg2).to be_nil
300
- end
301
- it "over" do
302
- arg1, arg2 = nil, nil
303
- enum = MergeEnum::MergeEnumerable.new(
304
- -> (c) { arg1 = c; 0...100 },
305
- -> (c) { arg2 = c; 200...250 },
306
- first: 200
307
- )
308
- expect(enum.count).to be 150
309
- expect(arg1).to be 200
310
- expect(arg2).to be 100
532
+ describe ".new" do
533
+ let(:enum) { Target.new ary, compact: compact, select: select }
534
+ describe "(0...100).map { |e| e.odd? ? e : nil }," do
535
+ let(:ary) { (0...100).map { |e| e.odd? ? e : nil } }
536
+ describe "compact:" do
537
+ describe "true," do
538
+ let(:compact) { true }
539
+
540
+ describe "select:" do
541
+ describe "Proc.new { |e| e.to_i < 30 }" do
542
+ let(:select) { Proc.new{ |e| e.to_i < 30 } }
543
+ test_all self, :enum, (1...30).step(2), line: __LINE__
544
+ end
545
+ end
546
+ end
311
547
  end
312
548
  end
313
549
  end
314
550
 
315
- describe "Proc to MergeEnumerable:" do
316
- describe "option_first" do
317
- it "limited at first" do
318
- enum = MergeEnum::MergeEnumerable.new(
319
- Proc.new { 0...100 },
320
- Proc.new { 200...250 },
321
- first: 50
322
- )
323
- expect(enum.count).to be 50
324
- end
325
- it "over" do
326
- enum = MergeEnum::MergeEnumerable.new(
327
- Proc.new { 0...100 },
328
- Proc.new { 200...250 },
329
- first: 200
330
- )
331
- expect(enum.count).to be 150
551
+ describe ".new" do
552
+ let(:enum) { Target.new ary1, ary2 }
553
+ describe "0...100, 200...250" do
554
+ let(:ary1) { 0...100 }
555
+ let(:ary2) { 200...250 }
556
+ test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
557
+ end
558
+ end
559
+
560
+ describe ".new" do
561
+ let(:enum) { Target.new ary1, ary2, first: first }
562
+ describe "0...100, 200...250," do
563
+ let(:ary1) { 0...100 }
564
+ let(:ary2) { 200...250 }
565
+
566
+ describe "first:" do
567
+ describe "50" do
568
+ let(:first) { 50 }
569
+ test_all self, :enum, 0...50, line: __LINE__
570
+ end
571
+
572
+ describe "130" do
573
+ let(:first) { 130 }
574
+ test_all self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
575
+ end
576
+
577
+ describe "200" do
578
+ let(:first) { 200 }
579
+ test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
580
+ end
581
+ end
582
+ end
583
+
584
+ describe "Proc.new { 0...100 }, Proc.new { 200...250 }," do
585
+ let(:ary1) { Proc.new { 0...100 } }
586
+ let(:ary2) { Proc.new { 200...250 } }
587
+
588
+ describe "first:" do
589
+ describe "50" do
590
+ let(:first) { 50 }
591
+ test_all self, :enum, 0...50, line: __LINE__
592
+ end
593
+
594
+ describe "130" do
595
+ let(:first) { 130 }
596
+ test_all self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
597
+ end
598
+
599
+ describe "200" do
600
+ let(:first) { 200 }
601
+ test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
602
+ end
603
+ end
604
+ end
605
+
606
+ describe "Proc.new { |c| 0...100 }, Proc.new { |c| 200...250 }," do
607
+ describe "first:" do
608
+ describe "50" do
609
+ let(:ary1) {
610
+ ary = Proc.new { |c| 0...100 }
611
+ expect(ary).to receive(:call).once.with(50).and_return(0...100)
612
+ ary
613
+ }
614
+ let(:ary2) {
615
+ ary = Proc.new { |c| 200...250 }
616
+ expect(ary).to receive(:call).never
617
+ ary
618
+ }
619
+ let(:first) { 50 }
620
+ test_all self, :enum, 0...50, line: __LINE__
621
+ end
622
+
623
+ describe "130" do
624
+ let(:ary1) {
625
+ ary = Proc.new { |c| 0...100 }
626
+ expect(ary).to receive(:call).once.with(130).and_return(0...100)
627
+ ary
628
+ }
629
+ let(:first) { 130 }
630
+
631
+ context "<all>" do
632
+ let(:ary2) {
633
+ ary = Proc.new { |c| 200...250 }
634
+ expect(ary).to receive(:call).once.with(30).and_return(200...250)
635
+ ary
636
+ }
637
+ test_equal self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
638
+ end
639
+
640
+ context "<interrupt>" do
641
+ let(:ary2) {
642
+ ary = Proc.new { |c| 200...250 }
643
+ expect(ary).to receive(:call).never
644
+ ary
645
+ }
646
+ test_interrupt self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
647
+ end
648
+ end
649
+
650
+ describe "200" do
651
+ let(:ary1) {
652
+ ary = Proc.new { |c| 0...100 }
653
+ expect(ary).to receive(:call).once.with(200).and_return(0...100)
654
+ ary
655
+ }
656
+ let(:ary2) { Proc.new { |c| 200...250 } }
657
+ let(:first) { 200 }
658
+ test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
659
+ end
660
+ end
661
+ end
662
+
663
+ describe "-> { 0...100 }, -> { 200...250 }," do
664
+ let(:ary1) { -> { 0...100 } }
665
+ let(:ary2) { -> { 200...250 } }
666
+
667
+ describe "first:" do
668
+ describe "50" do
669
+ let(:first) { 50 }
670
+ test_all self, :enum, 0...50, line: __LINE__
671
+ end
672
+
673
+ describe "130" do
674
+ let(:first) { 130 }
675
+ test_all self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
676
+ end
677
+
678
+ describe "200" do
679
+ let(:first) { 200 }
680
+ test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
681
+ end
682
+ end
683
+ end
684
+
685
+ describe "-> (c) { 0...100 }, -> (c) { 200...250 }," do
686
+ describe "first:" do
687
+ describe "50" do
688
+ let(:ary1) {
689
+ ary = -> (c) { 0...100 }
690
+ expect(ary).to receive(:call).once.with(50).and_return(0...100)
691
+ ary
692
+ }
693
+ let(:ary2) {
694
+ ary = -> (c) { 200...250 }
695
+ expect(ary).to receive(:call).never
696
+ ary
697
+ }
698
+ let(:first) { 50 }
699
+ test_all self, :enum, 0...50, line: __LINE__
700
+ end
701
+
702
+ describe "130" do
703
+ let(:ary1) {
704
+ ary = -> (c) { 0...100 }
705
+ expect(ary).to receive(:call).once.with(130).and_return(0...100)
706
+ ary
707
+ }
708
+ let(:first) { 130 }
709
+
710
+ context "<all>" do
711
+ let(:ary2) {
712
+ ary = -> (c) { 200...250 }
713
+ expect(ary).to receive(:call).once.with(30).and_return(200...250)
714
+ ary
715
+ }
716
+ test_equal self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
717
+ end
718
+
719
+ context "<interrupt>" do
720
+ let(:ary2) {
721
+ ary = -> (c) { 200...250 }
722
+ expect(ary).to receive(:call).never
723
+ ary
724
+ }
725
+ test_interrupt self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
726
+ end
727
+ end
728
+
729
+ describe "200" do
730
+ let(:ary1) {
731
+ ary = -> (c) { 0...100 }
732
+ expect(ary).to receive(:call).once.with(200).and_return(0...100)
733
+ ary
734
+ }
735
+ let(:ary2) { -> (c) { 200...250 } }
736
+ let(:first) { 200 }
737
+ test_all self, :enum, (0...100).to_a + (200...250).to_a, line: __LINE__
738
+ end
332
739
  end
333
740
  end
334
741
  end
335
742
 
336
- describe "Proc with Arguments to MergeEnumerable:" do
337
- describe "option_first" do
338
- it "limited at first" do
339
- arg1, arg2 = nil, nil
340
- enum = MergeEnum::MergeEnumerable.new(
341
- Proc.new { |c| arg1 = c; 0...100 },
342
- Proc.new { |c| raise "unexpect"; 200...250 },
343
- first: 50
344
- )
345
- expect(enum.count).to be 50
346
- expect(arg1).to be 50
347
- expect(arg2).to be_nil
348
- end
349
- it "over" do
350
- arg1, arg2 = nil, nil
351
- enum = MergeEnum::MergeEnumerable.new(
352
- Proc.new { |c| arg1 = c; 0...100 },
353
- Proc.new { |c| arg2 = c; 200...250 },
354
- first: 200
355
- )
356
- expect(enum.count).to be 150
357
- expect(arg1).to be 200
358
- expect(arg2).to be 100
743
+ describe ".new" do
744
+ let(:enum) { Target.new ary1, ary2, ary3 }
745
+ describe "0...100, 200...250, 300...330" do
746
+ let(:ary1) { 0...100 }
747
+ let(:ary2) { 200...250 }
748
+ let(:ary3) { 300...330 }
749
+ test_all self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
750
+ end
751
+ end
752
+
753
+ describe ".new" do
754
+ let(:enum) { Target.new ary1, ary2, ary3, first: first }
755
+ describe "0...100, 200...250, 300...330," do
756
+ let(:ary1) { 0...100 }
757
+ let(:ary2) { 200...250 }
758
+ let(:ary3) { 300...330 }
759
+
760
+ describe "first:" do
761
+ describe "50" do
762
+ let(:first) { 50 }
763
+ test_all self, :enum, 0...50, line: __LINE__
764
+ end
765
+
766
+ describe "130" do
767
+ let(:first) { 130 }
768
+ test_all self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
769
+ end
770
+
771
+ describe "170" do
772
+ let(:first) { 170 }
773
+ test_all self, :enum, (0...100).to_a + (200...250).to_a + (300...320).to_a, line: __LINE__
774
+ end
775
+
776
+ describe "200" do
777
+ let(:first) { 200 }
778
+ test_all self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
779
+ end
359
780
  end
360
781
  end
361
782
  end
362
783
 
363
- describe "Complex Enumerables to MergeEnumerable:" do
364
- it "Enumerable, Proc, Lambda" do
365
- arg1, arg2 = nil, nil
366
- enum = MergeEnum::MergeEnumerable.new(
367
- 0...100,
368
- -> (c) { arg1 = c; 200...250 },
369
- Proc.new { |c| arg2 = c; 300...330 },
370
- first: 200
371
- )
372
- expect(enum.count).to be 180
373
- expect(arg1).to be 100
374
- expect(arg2).to be 50
375
- end
376
- it "Proc, Lambda, Enumerable" do
377
- arg1, arg2 = nil, nil
378
- enum = MergeEnum::MergeEnumerable.new(
379
- -> (c) { arg1 = c; 0...100 },
380
- Proc.new { |c| arg2 = c; 200...250 },
381
- 300...330,
382
- first: 200
383
- )
384
- expect(enum.count).to be 180
385
- expect(arg1).to be 200
386
- expect(arg2).to be 100
784
+ describe ".new" do
785
+ let(:enum) { Target.new ary1, ary2, ary3, first: first }
786
+ describe "Proc.new { |c| 0...100 }, Proc.new { |c| 200...250 }, Proc.new { |c| 300...330 }," do
787
+ describe "first:" do
788
+ describe "50" do
789
+ let(:ary1) {
790
+ ary = Proc.new { |c| 0...100 }
791
+ expect(ary).to receive(:call).once.with(50).and_return(0...100)
792
+ ary
793
+ }
794
+ let(:ary2) {
795
+ ary = Proc.new { |c| 200...250 }
796
+ expect(ary).to receive(:call).never
797
+ ary
798
+ }
799
+ let(:ary3) {
800
+ ary = Proc.new { |c| 300...330 }
801
+ expect(ary).to receive(:call).never
802
+ ary
803
+ }
804
+ let(:first) { 50 }
805
+ test_all self, :enum, 0...50, line: __LINE__
806
+ end
807
+
808
+ describe "130" do
809
+ let(:ary1) {
810
+ ary = Proc.new { |c| 0...100 }
811
+ allow(ary).to receive(:call).once.with(130).and_return 0...100
812
+ ary
813
+ }
814
+ let(:first) { 130 }
815
+
816
+ context "<all>" do
817
+ let(:ary2) {
818
+ ary = Proc.new { |c| 200...250 }
819
+ allow(ary).to receive(:call).once.with(30).and_return 200...250
820
+ ary
821
+ }
822
+ let(:ary3) {
823
+ ary = Proc.new { |c| 300...330 }
824
+ allow(ary).to receive(:call).never
825
+ ary
826
+ }
827
+ test_equal self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
828
+ end
829
+
830
+ context "<interrupt>" do
831
+ let(:ary2) {
832
+ ary = Proc.new { |c| 200...250 }
833
+ allow(ary).to receive(:call).never
834
+ ary
835
+ }
836
+ let(:ary3) {
837
+ ary = Proc.new { |c| 300...330 }
838
+ allow(ary).to receive(:call).never
839
+ ary
840
+ }
841
+ test_interrupt self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
842
+ end
843
+ end
844
+
845
+ describe "200" do
846
+ let(:ary1) {
847
+ ary = Proc.new { |c| 0...100 }
848
+ allow(ary).to receive(:call).once.with(200).and_return 0...100
849
+ ary
850
+ }
851
+ let(:first) { 200 }
852
+
853
+ context "<all>" do
854
+ let(:ary2) {
855
+ ary = Proc.new { |c| 200...250 }
856
+ allow(ary).to receive(:call).once.with(100).and_return 200...250
857
+ ary
858
+ }
859
+ let(:ary3) {
860
+ ary = Proc.new { |c| 300...330 }
861
+ allow(ary).to receive(:call).once.with(50).and_return 300...330
862
+ ary
863
+ }
864
+ test_equal self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
865
+ end
866
+
867
+ context "<interrupt>" do
868
+ let(:ary2) {
869
+ ary = Proc.new { |c| 200...250 }
870
+ allow(ary).to receive(:call).never
871
+ ary
872
+ }
873
+ let(:ary3) {
874
+ ary = Proc.new { |c| 300...330 }
875
+ allow(ary).to receive(:call).never
876
+ ary
877
+ }
878
+ test_interrupt self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
879
+ end
880
+ end
881
+ end
387
882
  end
388
883
  end
389
884
 
390
- describe "Equality Enumerator:" do
391
- it "equality enumerator" do
392
- enum = MergeEnum::MergeEnumerable.new(
393
- 0...100,
394
- -> (c) { 200...250 },
395
- Proc.new { |c| 300...330 },
396
- first: 200
397
- )
398
- enum_sub = enum.each
399
- expect(enum).to be_a(Enumerable)
400
- expect(enum_sub).to be_a(Enumerable)
401
- expect(enum_sub).not_to be(enum)
402
- expect(enum_sub.to_a).to eq(enum.to_a)
885
+ describe ".new" do
886
+ let(:enum) { Target.new ary1, ary2, ary3, first: first }
887
+ describe "0...100, Proc.new { 200...250 }, -> (c) { 300...330 }," do
888
+ describe "first:" do
889
+ describe "50" do
890
+ let(:ary1) { 0...100 }
891
+ let(:ary2) {
892
+ ary = Proc.new { |c| 200...250 }
893
+ allow(ary).to receive(:call).never
894
+ ary
895
+ }
896
+ let(:ary3) {
897
+ ary = -> (c) { 300...330 }
898
+ allow(ary).to receive(:call).never
899
+ ary
900
+ }
901
+ let (:first) { 50 }
902
+ test_all self, :enum, 0...50, line: __LINE__
903
+ end
904
+
905
+ describe "130" do
906
+ let(:ary1) { 0...100 }
907
+ let (:first) { 130 }
908
+
909
+ context "<all>" do
910
+ let(:ary2) {
911
+ ary = Proc.new { |c| 200...250 }
912
+ allow(ary).to receive(:call).once.with(30).and_return 200...250
913
+ ary
914
+ }
915
+ let(:ary3) {
916
+ ary = -> (c) { 300...330 }
917
+ allow(ary).to receive(:call).never
918
+ ary
919
+ }
920
+ test_equal self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
921
+ end
922
+
923
+ context "<interrupt>" do
924
+ let(:ary2) {
925
+ ary = Proc.new { |c| 200...250 }
926
+ allow(ary).to receive(:call).never
927
+ ary
928
+ }
929
+ let(:ary3) {
930
+ ary = -> (c) { 300...330 }
931
+ allow(ary).to receive(:call).never
932
+ ary
933
+ }
934
+ test_interrupt self, :enum, (0...100).to_a + (200...230).to_a, line: __LINE__
935
+ end
936
+ end
937
+
938
+ describe "200" do
939
+ let(:ary1) { 0...100 }
940
+ let (:first) { 200 }
941
+
942
+ context "<all>" do
943
+ let(:ary2) {
944
+ ary = Proc.new { |c| 200...250 }
945
+ allow(ary).to receive(:call).once.with(100).and_return 200...250
946
+ ary
947
+ }
948
+ let(:ary3) {
949
+ ary = -> (c) { 300...330 }
950
+ allow(ary).to receive(:call).once.with(50).and_return 300...330
951
+ ary
952
+ }
953
+ test_equal self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
954
+ end
955
+
956
+ context "<interrupt>" do
957
+ let(:ary2) {
958
+ ary = Proc.new { |c| 200...250 }
959
+ allow(ary).to receive(:call).never
960
+ ary
961
+ }
962
+ let(:ary3) {
963
+ ary = -> (c) { 300...330 }
964
+ allow(ary).to receive(:call).never
965
+ ary
966
+ }
967
+ test_interrupt self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
968
+ end
969
+ end
970
+ end
403
971
  end
404
972
  end
405
973
 
406
- describe "Whitebox:" do
407
- it "call `first` method" do
408
- ary_1 = 0...100
409
- ary_2 = 200...250
410
- ary_3 = 300...330
411
- enum = MergeEnum::MergeEnumerable.new(
412
- ary_1,
413
- -> (c) { ary_2 },
414
- Proc.new { ary_3 },
415
- first: 200
416
- )
417
- expect(ary_1).to receive(:first).with(200).and_return(ary_1)
418
- allow(ary_2).to receive(:first).and_raise("unexpected")
419
- expect(ary_3).to receive(:first).with(50).and_return(ary_3)
420
- expect(enum.count).to be 180
421
- end
422
- it "not call `first` method" do
423
- ary = 0...100
424
- allow(ary).to receive(:first).and_raise("unexpect")
425
- enum = MergeEnum::MergeEnumerable.new ary, first: 10, compact: true
426
- expect(enum.count).to be 10
974
+ describe ".new" do
975
+ describe "0...100, Proc.new { 200...250 }, -> (c) { 300...330 }, first: 200" do
976
+ let(:enum) { Target.new 0...100, Proc.new { 200...250 }, -> (c) { 300...330 }, first: 200 }
977
+ context "<is_a?>" do
978
+ it { expect(enum).to be_a Enumerable }
979
+ end
980
+ context "#each <is_a?>" do
981
+ subject { enum.each }
982
+ it { is_expected.to be_a Enumerable }
983
+ it { is_expected.not_to be_a Array }
984
+ it { is_expected.not_to be enum }
985
+ end
986
+ context "#each#to_a <is_a?>" do
987
+ subject { enum.each.to_a }
988
+ it { is_expected.to be_a Array }
989
+ it { is_expected.to eq enum.to_a }
990
+ end
427
991
  end
428
992
  end
429
993
 
430
- describe "`concat` Method:" do
431
- it "equality enumerator" do
432
- enm_1 = 0...100
433
- enm_2 = -> (c) { 200...250 }
434
- enm_3 = Proc.new { |c| 300...330 }
435
- enum = MergeEnum::MergeEnumerable.new(
436
- enm_1, enm_2,
437
- first: 130
438
- )
439
- expect(enum.concat enm_3).not_to be(enum)
440
-
441
- enum_2 = MergeEnum::MergeEnumerable.new(
442
- enm_1, enm_2, enm_3,
443
- first: 130
444
- )
445
- expect(enum.concat(enm_3).to_a).to eq(enum_2.to_a)
994
+ describe ".new" do
995
+ let(:enum) { Target.new ary1, ary2, ary3, first: 200 }
996
+ describe "0...100, Proc.new { 200...250 }, -> { 300...330 }, first: 200" do
997
+ let(:ary1) {
998
+ ary = 0...100
999
+ allow(ary).to receive(:first).with(200) { |c| (0...100).first c }
1000
+ ary
1001
+ }
1002
+ let(:ary2) {
1003
+ ary = 200...250
1004
+ _proc = Proc.new { ary }
1005
+ allow(_proc).to receive(:call).with(no_args).and_return ary
1006
+ allow(ary).to receive(:first).with(100) { |c| (200...250).first c }
1007
+ _proc
1008
+ }
1009
+ let(:ary3) {
1010
+ ary = 300...330
1011
+ _proc = -> { ary }
1012
+ allow(_proc).to receive(:call).with(no_args).and_return ary
1013
+ allow(ary).to receive(:first).with(50) { |c| (300...330).first c }
1014
+ _proc
1015
+ }
1016
+
1017
+ context "<whitebox>" do
1018
+ test_equal self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
1019
+ end
1020
+ end
1021
+
1022
+ describe "0...100, Proc.new { |c| 200...250 }, -> (c) { 300...330 }, first: 200" do
1023
+ let(:ary1) {
1024
+ ary = 0...100
1025
+ allow(ary).to receive(:first).with(200).and_return 0...100
1026
+ ary
1027
+ }
1028
+ let(:ary2) {
1029
+ ary = 200...250
1030
+ _proc = Proc.new { |c| ary }
1031
+ allow(_proc).to receive(:call).with(100).and_return ary
1032
+ allow(ary).to receive(:first).never
1033
+ _proc
1034
+ }
1035
+ let(:ary3) {
1036
+ ary = 300...330
1037
+ _proc = -> (c) { ary }
1038
+ allow(_proc).to receive(:call).with(50).and_return ary
1039
+ allow(ary).to receive(:first).never
1040
+ _proc
1041
+ }
1042
+
1043
+ context "<whitebox>" do
1044
+ test_equal self, :enum, (0...100).to_a + (200...250).to_a + (300...330).to_a, line: __LINE__
1045
+ end
446
1046
  end
447
1047
  end
448
1048
 
449
- describe "`concat!` Method:" do
450
- it "equality enumerator" do
451
- enm_1 = 0...100
452
- enm_2 = -> (c) { 200...250 }
453
- enm_3 = Proc.new { |c| 300...330 }
454
- enum = MergeEnum::MergeEnumerable.new(
455
- enm_1, enm_2,
456
- first: 130
457
- )
458
- expect(enum.concat! enm_3).to be(enum)
459
-
460
- enum = MergeEnum::MergeEnumerable.new(
461
- enm_1, enm_2,
462
- first: 130
463
- )
464
-
465
- enum_2 = MergeEnum::MergeEnumerable.new(
466
- enm_1, enm_2, enm_3,
467
- first: 130
468
- )
469
- expect(enum.concat!(enm_3).to_a).to eq(enum_2.to_a)
1049
+ describe ".new" do
1050
+ describe "0...100, Proc.new { |c| 200...250 }, first: 160" do
1051
+ let(:enum) { Target.new 0...100, Proc.new { |c| 200...250 }, first: 160 }
1052
+ it { expect(enum).to be enum }
1053
+
1054
+ context "#concat -> (c) { 300...330 }" do
1055
+ it { expect(enum.concat []).not_to be enum }
1056
+ it { expect(enum.concat([]).to_a).to eq enum.to_a }
1057
+
1058
+ let(:ary) { -> (c) { 300...330 } }
1059
+
1060
+ subject { enum.concat(ary).to_a }
1061
+ it { is_expected.to eq (0...100).to_a + (200...250).to_a + (300...310).to_a }
1062
+ end
1063
+
1064
+ context "#concat! -> (c) { 300...330 }" do
1065
+ it { expect(enum.concat! [1, 2, 3]).to eq enum }
1066
+
1067
+ let(:ary) { -> (c) { 300...330 } }
1068
+
1069
+ subject { enum.concat!(ary).to_a }
1070
+ it { is_expected.to eq (0...100).to_a + (200...250).to_a + (300...310).to_a }
1071
+ end
470
1072
  end
471
1073
  end
472
1074