diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/core/enumerator/initialize_spec.rb | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) |
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
[Misc #13792] [ruby-core:82287]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/enumerator/initialize_spec.rb')
-rw-r--r-- | spec/ruby/core/enumerator/initialize_spec.rb | 61 |
1 files changed, 61 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..58f8a5e865 --- /dev/null +++ b/spec/ruby/core/enumerator/initialize_spec.rb @@ -0,0 +1,61 @@ +# -*- encoding: us-ascii -*- + +require File.expand_path('../../../spec_helper', __FILE__) + +describe "Enumerator#initialize" do + before :each do + @uninitialized = Enumerator.allocate + end + + it "is a private method" do + Enumerator.should have_private_instance_method(:initialize, false) + end + + it "returns self when given an object" do + @uninitialized.send(:initialize, Object.new).should equal(@uninitialized) + 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 be_an_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 be_nil + end + + it "sets size to nil if the given size is nil" do + @uninitialized.send(:initialize, nil) {}.size.should be_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 a Fixnum" 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, lambda { 200 }) {}.size.should == 200 + end + + describe "on frozen instance" do + it "raises a RuntimeError" do + lambda { + @uninitialized.freeze.send(:initialize) {} + }.should raise_error(RuntimeError) + end + end +end |