Skip to content

Commit 71bb50d

Browse files
committed
Polish Enumerator's specs
1 parent e3c91e6 commit 71bb50d

File tree

9 files changed

+36
-20
lines changed

9 files changed

+36
-20
lines changed

spec/ruby/core/enumerator/chain/initialize_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
end
2323

2424
describe "on frozen instance" do
25-
it "raises a RuntimeError" do
25+
it "raises a FrozenError" do
2626
-> {
2727
@uninitialized.freeze.send(:initialize)
28-
}.should raise_error(RuntimeError)
28+
}.should raise_error(FrozenError)
2929
end
3030
end
3131
end

spec/ruby/core/enumerator/each_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,41 @@ def object_each_with_arguments.each_with_arguments(arg, *args)
1010

1111
@enum_with_arguments = object_each_with_arguments.to_enum(:each_with_arguments, :arg0, :arg1, :arg2)
1212

13-
@enum_with_yielder = Enumerator.new {|y| y.yield :ok}
13+
@enum_with_yielder = Enumerator.new { |y| y.yield :ok }
1414
end
1515

1616
it "yields each element of self to the given block" do
1717
acc = []
18-
[1,2,3].to_enum.each {|e| acc << e }
19-
acc.should == [1,2,3]
18+
[1, 2, 3].to_enum.each { |e| acc << e }
19+
acc.should == [1, 2, 3]
2020
end
2121

2222
it "calls #each on the object given in the constructor by default" do
2323
each = mock('each')
2424
each.should_receive(:each)
25-
each.to_enum.each {|e| e }
25+
each.to_enum.each { |e| e }
2626
end
2727

2828
it "calls #each on the underlying object until it's exhausted" do
2929
each = mock('each')
3030
each.should_receive(:each).and_yield(1).and_yield(2).and_yield(3)
3131
acc = []
32-
each.to_enum.each {|e| acc << e }
33-
acc.should == [1,2,3]
32+
each.to_enum.each { |e| acc << e }
33+
acc.should == [1, 2, 3]
3434
end
3535

3636
it "calls the method given in the constructor instead of #each" do
3737
each = mock('peach')
3838
each.should_receive(:peach)
39-
each.to_enum(:peach).each {|e| e }
39+
each.to_enum(:peach).each { |e| e }
4040
end
4141

4242
it "calls the method given in the constructor until it's exhausted" do
4343
each = mock('peach')
4444
each.should_receive(:peach).and_yield(1).and_yield(2).and_yield(3)
4545
acc = []
46-
each.to_enum(:peach).each {|e| acc << e }
47-
acc.should == [1,2,3]
46+
each.to_enum(:peach).each { |e| acc << e }
47+
acc.should == [1, 2, 3]
4848
end
4949

5050
it "raises a NoMethodError if the object doesn't respond to #each" do

spec/ruby/core/enumerator/generator/initialize_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
end
1818

1919
describe "on frozen instance" do
20-
it "raises a RuntimeError" do
20+
it "raises a FrozenError" do
2121
-> {
2222
@uninitialized.freeze.send(:initialize) {}
23-
}.should raise_error(RuntimeError)
23+
}.should raise_error(FrozenError)
2424
end
2525
end
2626
end

spec/ruby/core/enumerator/initialize_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
end
4949

5050
describe "on frozen instance" do
51-
it "raises a RuntimeError" do
51+
it "raises a FrozenError" do
5252
-> {
5353
@uninitialized.freeze.send(:initialize) {}
54-
}.should raise_error(RuntimeError)
54+
}.should raise_error(FrozenError)
5555
end
5656
end
5757
end

spec/ruby/core/enumerator/lazy/initialize_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def receiver.each
5656
end
5757

5858
describe "on frozen instance" do
59-
it "raises a RuntimeError" do
60-
-> { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(RuntimeError)
59+
it "raises a FrozenError" do
60+
-> { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(FrozenError)
6161
end
6262
end
6363
end

spec/ruby/core/enumerator/product/each_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ def object2.each_entry
4545
enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
4646
end
4747

48+
it "returns self if given a block" do
49+
enum = Enumerator::Product.new([1, 2], [:a, :b])
50+
enum.each {}.should.equal?(enum)
51+
end
52+
4853
it "doesn't accept arguments" do
4954
Enumerator::Product.instance_method(:each).arity.should == 0
5055
end

spec/ruby/core/enumerator/product_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
elems.should == [[1, "X"], [1, "Y"], [2, "X"], [2, "Y"]]
4545
end
4646

47+
it "returns nil when a block passed" do
48+
Enumerator.product(1..2) {}.should == nil
49+
end
50+
4751
it "reject keyword arguments" do
4852
-> {
4953
Enumerator.product(1..3, foo: 1, bar: 2)

spec/ruby/core/enumerator/rewind_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
end
1515

1616
it "returns self" do
17-
@enum.rewind.should == @enum
17+
@enum.rewind.should.equal? @enum
1818
end
1919

2020
it "has no effect on a new enumerator" do
@@ -49,7 +49,7 @@
4949
obj = mock('rewinder')
5050
enum = obj.to_enum
5151
obj.should_receive(:each).at_most(1)
52-
-> { enum.rewind.should == enum }.should_not raise_error
52+
enum.rewind.should == enum
5353
end
5454
end
5555

spec/ruby/core/kernel/initialize_copy_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
require_relative '../../spec_helper'
22

33
describe "Kernel#initialize_copy" do
4+
it "returns self" do
5+
obj = Object.new
6+
obj.send(:initialize_copy, obj).should.equal?(obj)
7+
end
8+
49
it "does nothing if the argument is the same as the receiver" do
510
obj = Object.new
611
obj.send(:initialize_copy, obj).should.equal?(obj)
7-
obj.freeze
12+
13+
obj = Object.new.freeze
814
obj.send(:initialize_copy, obj).should.equal?(obj)
15+
916
1.send(:initialize_copy, 1).should.equal?(1)
1017
end
1118

0 commit comments

Comments
 (0)