blob: a43805dd16f3108bb7f3e4b0296950b872c29b07 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
require_relative '../../../spec_helper'
describe "Enumerator::Generator#each" do
before :each do
@generator = Enumerator::Generator.new do |y, *args|
y << 3 << 2 << 1
y << args unless args.empty?
:block_returned
end
end
it "is an enumerable" do
@generator.should be_kind_of(Enumerable)
end
it "supports enumeration with a block" do
r = []
@generator.each { |v| r << v }
r.should == [3, 2, 1]
end
it "raises a LocalJumpError if no block given" do
-> { @generator.each }.should raise_error(LocalJumpError)
end
it "returns the block returned value" do
@generator.each {}.should equal(:block_returned)
end
it "requires multiple arguments" do
Enumerator::Generator.instance_method(:each).arity.should < 0
end
it "appends given arguments to receiver.each" do
yields = []
@generator.each(:each0, :each1) { |yielded| yields << yielded }
yields.should == [3, 2, 1, [:each0, :each1]]
end
end
|