Skip to content

Commit 8a6da41

Browse files
committed
Remove implementation detail specs for Enumerator
`Enumerator::Yielder`, `Enumerator::Generator` and `Enumerator::Producer` are not supposed to be exposed to the user. Instead they will interact with them trough other means, like for example `Enumerator.new { |yielder| }`. Some specs I ported, others I removed, and some were already present.
1 parent 448cb34 commit 8a6da41

7 files changed

Lines changed: 49 additions & 178 deletions

File tree

core/enumerator/generator/each_spec.rb

Lines changed: 0 additions & 40 deletions
This file was deleted.

core/enumerator/generator/initialize_spec.rb

Lines changed: 0 additions & 26 deletions
This file was deleted.

core/enumerator/new_spec.rb

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,74 @@
4242
enum.to_a.should == ["a\n", "b\n", "c"]
4343
end
4444

45-
describe 'yielded values' do
46-
it 'handles yield arguments properly' do
45+
describe '#yield' do
46+
it 'accepts a single argument' do
4747
Enumerator.new { |y| y.yield(1) }.to_a.should == [1]
4848
Enumerator.new { |y| y.yield(1) }.first.should == 1
49+
end
4950

50-
Enumerator.new { |y| y.yield([1]) }.to_a.should == [[1]]
51-
Enumerator.new { |y| y.yield([1]) }.first.should == [1]
52-
51+
it 'accepts multiple arguments' do
5352
Enumerator.new { |y| y.yield(1, 2) }.to_a.should == [[1, 2]]
5453
Enumerator.new { |y| y.yield(1, 2) }.first.should == [1, 2]
54+
end
55+
56+
it "doesn't double-wrap arrays" do
57+
Enumerator.new { |y| y.yield([1]) }.to_a.should == [[1]]
58+
Enumerator.new { |y| y.yield([1]) }.first.should == [1]
5559

5660
Enumerator.new { |y| y.yield([1, 2]) }.to_a.should == [[1, 2]]
5761
Enumerator.new { |y| y.yield([1, 2]) }.first.should == [1, 2]
5862
end
5963

60-
it 'handles << arguments properly' do
64+
it 'returns nil' do
65+
ScratchPad.record []
66+
Enumerator.new do |y|
67+
ScratchPad << y.yield(1)
68+
end.to_a
69+
70+
ScratchPad.recorded.should == [nil]
71+
end
72+
73+
it 'accepts keyword arguments and treats them as a positional hash' do
74+
Enumerator.new { |y| y.yield(foo: 42) }.to_a.should == [{ foo: 42 }]
75+
Enumerator.new { |y| y.yield(foo: 42) }.first.should == { foo: 42 }
76+
77+
Enumerator.new { |y| y.yield(123, foo: 42) }.to_a.should == [[123, { foo: 42 }]]
78+
Enumerator.new { |y| y.yield(123, foo: 42) }.first.should == [123, { foo: 42 }]
79+
end
80+
end
81+
82+
describe '#<<' do
83+
it 'accepts a single argument' do
6184
Enumerator.new { |y| y.<<(1) }.to_a.should == [1]
6285
Enumerator.new { |y| y.<<(1) }.first.should == 1
86+
end
6387

88+
it "doesn't double-wrap arrays" do
6489
Enumerator.new { |y| y.<<([1]) }.to_a.should == [[1]]
6590
Enumerator.new { |y| y.<<([1]) }.first.should == [1]
6691

67-
# << doesn't accept multiple arguments
68-
# Enumerator.new { |y| y.<<(1, 2) }.to_a.should == [[1, 2]]
69-
# Enumerator.new { |y| y.<<(1, 2) }.first.should == [1, 2]
70-
7192
Enumerator.new { |y| y.<<([1, 2]) }.to_a.should == [[1, 2]]
7293
Enumerator.new { |y| y.<<([1, 2]) }.first.should == [1, 2]
7394
end
95+
96+
it 'accepts keyword arguments and treats them as a positional hash' do
97+
Enumerator.new { |y| y.<<(foo: 42) }.to_a.should == [{ foo: 42 }]
98+
Enumerator.new { |y| y.<<(foo: 42) }.first.should == { foo: 42 }
99+
end
100+
101+
it 'can be chained' do
102+
enum = Enumerator.new do |y|
103+
y << 1 << 2
104+
end
105+
enum.to_a.should == [1, 2]
106+
end
107+
108+
it 'raises ArgumentError when given more than one argument' do
109+
-> {
110+
Enumerator.new { |y| y.<<(1, 2) }.to_a
111+
}.should.raise(ArgumentError, "wrong number of arguments (given 2, expected 1)")
112+
end
74113
end
75114
end
76115
end

core/enumerator/yielder/append_spec.rb

Lines changed: 0 additions & 35 deletions
This file was deleted.

core/enumerator/yielder/initialize_spec.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

core/enumerator/yielder/to_proc_spec.rb

Lines changed: 0 additions & 16 deletions
This file was deleted.

core/enumerator/yielder/yield_spec.rb

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)