summaryrefslogtreecommitdiff
path: root/spec/ruby/core/enumerator/initialize_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/enumerator/initialize_spec.rb')
-rw-r--r--spec/ruby/core/enumerator/initialize_spec.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/ruby/core/enumerator/initialize_spec.rb b/spec/ruby/core/enumerator/initialize_spec.rb
new file mode 100644
index 0000000000..9929494b5a
--- /dev/null
+++ b/spec/ruby/core/enumerator/initialize_spec.rb
@@ -0,0 +1,57 @@
+# -*- encoding: us-ascii -*-
+
+require_relative '../../spec_helper'
+
+describe "Enumerator#initialize" do
+ before :each do
+ @uninitialized = Enumerator.allocate
+ end
+
+ it "is a private method" do
+ Enumerator.private_instance_methods(false).should.include?(:initialize)
+ end
+
+ it "returns self when given a block" do
+ @uninitialized.send(:initialize) {}.should.equal?(@uninitialized)
+ end
+
+ # Maybe spec should be broken up?
+ it "accepts a block" do
+ @uninitialized.send(:initialize) do |yielder|
+ r = yielder.yield 3
+ yielder << r << 2 << 1
+ end
+ @uninitialized.should.instance_of?(Enumerator)
+ r = []
+ @uninitialized.each{|x| r << x; x * 2}
+ r.should == [3, 6, 2, 1]
+ end
+
+ it "sets size to nil if size is not given" do
+ @uninitialized.send(:initialize) {}.size.should == nil
+ end
+
+ it "sets size to nil if the given size is nil" do
+ @uninitialized.send(:initialize, nil) {}.size.should == nil
+ end
+
+ it "sets size to the given size if the given size is Float::INFINITY" do
+ @uninitialized.send(:initialize, Float::INFINITY) {}.size.should.equal?(Float::INFINITY)
+ end
+
+ it "sets size to the given size if the given size is an Integer" do
+ @uninitialized.send(:initialize, 100) {}.size.should == 100
+ end
+
+ it "sets size to the given size if the given size is a Proc" do
+ @uninitialized.send(:initialize, -> { 200 }) {}.size.should == 200
+ end
+
+ describe "on frozen instance" do
+ it "raises a FrozenError" do
+ -> {
+ @uninitialized.freeze.send(:initialize) {}
+ }.should.raise(FrozenError)
+ end
+ end
+end