diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-08-13 11:44:15 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-12-22 13:52:03 +0900 |
commit | fa356a798aefc20725467d4fad02df8325d63e71 (patch) | |
tree | 9150cab2aaa1fbb14e5461d0166f8a09da2a5209 /spec | |
parent | 7204b81bcb13f84ca3cc34384d205565fd5ad381 (diff) | |
download | ruby-fa356a798aefc20725467d4fad02df8325d63e71.tar.gz |
Enumerator.new: raise unless block given
Has been deprecated since c73b6bd7ebd01133538c645566944132dbde4d13.
[Feature #17116] [ruby-dev:50945]
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/core/enumerator/initialize_spec.rb | 6 | ||||
-rw-r--r-- | spec/ruby/core/enumerator/new_spec.rb | 66 |
2 files changed, 42 insertions, 30 deletions
diff --git a/spec/ruby/core/enumerator/initialize_spec.rb b/spec/ruby/core/enumerator/initialize_spec.rb index 45bd650d7f..113bbf9957 100644 --- a/spec/ruby/core/enumerator/initialize_spec.rb +++ b/spec/ruby/core/enumerator/initialize_spec.rb @@ -11,8 +11,10 @@ describe "Enumerator#initialize" 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) + ruby_version_is ''...'3.0' do + it "returns self when given an object" do + @uninitialized.send(:initialize, Object.new).should equal(@uninitialized) + end end it "returns self when given a block" do diff --git a/spec/ruby/core/enumerator/new_spec.rb b/spec/ruby/core/enumerator/new_spec.rb index 100edc8455..9aea9fdd17 100644 --- a/spec/ruby/core/enumerator/new_spec.rb +++ b/spec/ruby/core/enumerator/new_spec.rb @@ -1,42 +1,52 @@ require_relative '../../spec_helper' describe "Enumerator.new" do - it "creates a new custom enumerator with the given object, iterator and arguments" do - enum = Enumerator.new(1, :upto, 3) - enum.should be_an_instance_of(Enumerator) - end + context "no block given" do + ruby_version_is '3.0' do + it "raises" do + -> { Enumerator.new(1, :upto, 3) }.should raise_error(ArgumentError) + end + end - it "creates a new custom enumerator that responds to #each" do - enum = Enumerator.new(1, :upto, 3) - enum.respond_to?(:each).should == true - end + ruby_version_is ''...'3.0' do + it "creates a new custom enumerator with the given object, iterator and arguments" do + enum = Enumerator.new(1, :upto, 3) + enum.should be_an_instance_of(Enumerator) + end - it "creates a new custom enumerator that runs correctly" do - Enumerator.new(1, :upto, 3).map{|x|x}.should == [1,2,3] - end + it "creates a new custom enumerator that responds to #each" do + enum = Enumerator.new(1, :upto, 3) + enum.respond_to?(:each).should == true + end - it "aliases the second argument to :each" do - Enumerator.new(1..2).to_a.should == Enumerator.new(1..2, :each).to_a - end + it "creates a new custom enumerator that runs correctly" do + Enumerator.new(1, :upto, 3).map{|x|x}.should == [1,2,3] + end - it "doesn't check for the presence of the iterator method" do - Enumerator.new(nil).should be_an_instance_of(Enumerator) - end + it "aliases the second argument to :each" do + Enumerator.new(1..2).to_a.should == Enumerator.new(1..2, :each).to_a + end - it "uses the latest define iterator method" do - class StrangeEach - def each - yield :foo + it "doesn't check for the presence of the iterator method" do + Enumerator.new(nil).should be_an_instance_of(Enumerator) end - end - enum = Enumerator.new(StrangeEach.new) - enum.to_a.should == [:foo] - class StrangeEach - def each - yield :bar + + it "uses the latest define iterator method" do + class StrangeEach + def each + yield :foo + end + end + enum = Enumerator.new(StrangeEach.new) + enum.to_a.should == [:foo] + class StrangeEach + def each + yield :bar + end + end + enum.to_a.should == [:bar] end end - enum.to_a.should == [:bar] end context "when passed a block" do |