mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@875a09e
This commit is contained in:
parent
a06301b103
commit
5c276e1cc9
1247 changed files with 5316 additions and 5028 deletions
|
@ -3,7 +3,7 @@ require_relative '../../../spec_helper'
|
|||
ruby_version_is "2.6" do
|
||||
describe "Enumerator::ArithmeticSequence.new" do
|
||||
it "is not defined" do
|
||||
lambda {
|
||||
-> {
|
||||
Enumerator::ArithmeticSequence.new
|
||||
}.should raise_error(NoMethodError)
|
||||
end
|
||||
|
@ -11,7 +11,7 @@ ruby_version_is "2.6" do
|
|||
|
||||
describe "Enumerator::ArithmeticSequence.allocate" do
|
||||
it "is not defined" do
|
||||
lambda {
|
||||
-> {
|
||||
Enumerator::ArithmeticSequence.allocate
|
||||
}.should raise_error(TypeError, 'allocator undefined for Enumerator::ArithmeticSequence')
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ ruby_version_is "2.6" do
|
|||
|
||||
describe "on frozen instance" do
|
||||
it "raises a RuntimeError" do
|
||||
lambda {
|
||||
-> {
|
||||
@uninitialized.freeze.send(:initialize)
|
||||
}.should raise_error(RuntimeError)
|
||||
end
|
||||
|
|
|
@ -36,7 +36,7 @@ ruby_version_is "2.6" do
|
|||
@obj.should_not_receive(:rewind)
|
||||
@second.should_receive(:rewind).and_raise(RuntimeError)
|
||||
@enum.each {}
|
||||
lambda { @enum.rewind }.should raise_error(RuntimeError)
|
||||
-> { @enum.rewind }.should raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
it "calls rewind only for objects that have actually been iterated on" do
|
||||
|
@ -46,7 +46,7 @@ ruby_version_is "2.6" do
|
|||
|
||||
@obj.should_receive(:rewind)
|
||||
@second.should_not_receive(:rewind)
|
||||
lambda { @enum.each {} }.should raise_error(RuntimeError)
|
||||
-> { @enum.each {} }.should raise_error(RuntimeError)
|
||||
@enum.rewind
|
||||
end
|
||||
end
|
||||
|
|
|
@ -49,7 +49,7 @@ describe "Enumerator#each" do
|
|||
|
||||
it "raises a NoMethodError if the object doesn't respond to #each" do
|
||||
enum = Object.new.to_enum
|
||||
lambda do
|
||||
-> do
|
||||
enum.each { |e| e }
|
||||
end.should raise_error(NoMethodError)
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ describe "Enumerator#each_with_index" do
|
|||
end
|
||||
|
||||
it "raises an ArgumentError if passed extra arguments" do
|
||||
lambda do
|
||||
-> do
|
||||
[1].to_enum.each_with_index(:glark)
|
||||
end.should raise_error(ArgumentError)
|
||||
end
|
||||
|
|
|
@ -39,14 +39,14 @@ describe "Enumerator#feed" do
|
|||
it "raises a TypeError if called more than once without advancing the enumerator" do
|
||||
@enum.feed :a
|
||||
@enum.next
|
||||
lambda { @enum.feed :b }.should raise_error(TypeError)
|
||||
-> { @enum.feed :b }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "sets the return value of Yielder#yield" do
|
||||
enum = Enumerator.new { |y| ScratchPad << y.yield }
|
||||
enum.next
|
||||
enum.feed :a
|
||||
lambda { enum.next }.should raise_error(StopIteration)
|
||||
-> { enum.next }.should raise_error(StopIteration)
|
||||
ScratchPad.recorded.should == [:a]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,7 +21,7 @@ describe "Enumerator::Generator#each" do
|
|||
end
|
||||
|
||||
it "raises a LocalJumpError if no block given" do
|
||||
lambda { @generator.each }.should raise_error(LocalJumpError)
|
||||
-> { @generator.each }.should raise_error(LocalJumpError)
|
||||
end
|
||||
|
||||
it "returns the block returned value" do
|
||||
|
|
|
@ -18,7 +18,7 @@ describe "Enumerator::Generator#initialize" do
|
|||
|
||||
describe "on frozen instance" do
|
||||
it "raises a RuntimeError" do
|
||||
lambda {
|
||||
-> {
|
||||
@uninitialized.freeze.send(:initialize) {}
|
||||
}.should raise_error(RuntimeError)
|
||||
end
|
||||
|
|
|
@ -48,12 +48,12 @@ describe "Enumerator#initialize" do
|
|||
end
|
||||
|
||||
it "sets size to the given size if the given size is a Proc" do
|
||||
@uninitialized.send(:initialize, lambda { 200 }) {}.size.should == 200
|
||||
@uninitialized.send(:initialize, -> { 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
|
||||
|
|
|
@ -40,7 +40,7 @@ describe "Enumerator::Lazy#drop_while" do
|
|||
end
|
||||
|
||||
it "raises an ArgumentError when not given a block" do
|
||||
lambda { @yieldsmixed.drop_while }.should raise_error(ArgumentError)
|
||||
-> { @yieldsmixed.drop_while }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
describe "on a nested Lazy" do
|
||||
|
|
|
@ -33,6 +33,39 @@ describe "Enumerator::Lazy#grep" do
|
|||
Enumerator::Lazy.new(Object.new, 100) {}.grep(Object).size.should == nil
|
||||
end
|
||||
|
||||
it "sets $~ in the block" do
|
||||
"z" =~ /z/ # Reset $~
|
||||
["abc", "def"].lazy.grep(/b/) { |e|
|
||||
e.should == "abc"
|
||||
$&.should == "b"
|
||||
}.force
|
||||
|
||||
# Set by the failed match of "def"
|
||||
$~.should == nil
|
||||
end
|
||||
|
||||
it "sets $~ in the next block with each" do
|
||||
"z" =~ /z/ # Reset $~
|
||||
["abc", "def"].lazy.grep(/b/).each { |e|
|
||||
e.should == "abc"
|
||||
$&.should == "b"
|
||||
}
|
||||
|
||||
# Set by the failed match of "def"
|
||||
$~.should == nil
|
||||
end
|
||||
|
||||
it "sets $~ in the next block with map" do
|
||||
"z" =~ /z/ # Reset $~
|
||||
["abc", "def"].lazy.grep(/b/).map { |e|
|
||||
e.should == "abc"
|
||||
$&.should == "b"
|
||||
}.force
|
||||
|
||||
# Set by the failed match of "def"
|
||||
$~.should == nil
|
||||
end
|
||||
|
||||
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
|
||||
it "stops after specified times when not given a block" do
|
||||
(0..Float::INFINITY).lazy.grep(Integer).first(3).should == [0, 1, 2]
|
||||
|
|
|
@ -31,6 +31,39 @@ describe "Enumerator::Lazy#grep_v" do
|
|||
Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).size.should == nil
|
||||
end
|
||||
|
||||
it "sets $~ in the block" do
|
||||
"z" =~ /z/ # Reset $~
|
||||
["abc", "def"].lazy.grep_v(/e/) { |e|
|
||||
e.should == "abc"
|
||||
$~.should == nil
|
||||
}.force
|
||||
|
||||
# Set by the match of "def"
|
||||
$&.should == "e"
|
||||
end
|
||||
|
||||
it "sets $~ in the next block with each" do
|
||||
"z" =~ /z/ # Reset $~
|
||||
["abc", "def"].lazy.grep_v(/e/).each { |e|
|
||||
e.should == "abc"
|
||||
$~.should == nil
|
||||
}
|
||||
|
||||
# Set by the match of "def"
|
||||
$&.should == "e"
|
||||
end
|
||||
|
||||
it "sets $~ in the next block with map" do
|
||||
"z" =~ /z/ # Reset $~
|
||||
["abc", "def"].lazy.grep_v(/e/).map { |e|
|
||||
e.should == "abc"
|
||||
$~.should == nil
|
||||
}.force
|
||||
|
||||
# Set by the match of "def"
|
||||
$&.should == "e"
|
||||
end
|
||||
|
||||
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
|
||||
it "stops after specified times when not given a block" do
|
||||
(0..Float::INFINITY).lazy.grep_v(3..5).first(3).should == [0, 1, 2]
|
||||
|
|
|
@ -48,16 +48,16 @@ describe "Enumerator::Lazy#initialize" do
|
|||
end
|
||||
|
||||
it "sets given size to own size if the given size is a Proc" do
|
||||
@uninitialized.send(:initialize, @receiver, lambda { 200 }) {}.size.should == 200
|
||||
@uninitialized.send(:initialize, @receiver, -> { 200 }) {}.size.should == 200
|
||||
end
|
||||
|
||||
it "raises an ArgumentError when block is not given" do
|
||||
lambda { @uninitialized.send :initialize, @receiver }.should raise_error(ArgumentError)
|
||||
-> { @uninitialized.send :initialize, @receiver }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
describe "on frozen instance" do
|
||||
it "raises a RuntimeError" do
|
||||
lambda { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(RuntimeError)
|
||||
-> { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(RuntimeError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -52,7 +52,7 @@ describe "Enumerator::Lazy#reject" do
|
|||
end
|
||||
|
||||
it "raises an ArgumentError when not given a block" do
|
||||
lambda { @yieldsmixed.reject }.should raise_error(ArgumentError)
|
||||
-> { @yieldsmixed.reject }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
describe "on a nested Lazy" do
|
||||
|
|
|
@ -46,7 +46,7 @@ describe :enumerator_lazy_collect_concat, shared: true do
|
|||
end
|
||||
|
||||
it "raises an ArgumentError when not given a block" do
|
||||
lambda { @yieldsmixed.send(@method) }.should raise_error(ArgumentError)
|
||||
-> { @yieldsmixed.send(@method) }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
describe "on a nested Lazy" do
|
||||
|
|
|
@ -40,7 +40,7 @@ describe :enumerator_lazy_select, shared: true do
|
|||
end
|
||||
|
||||
it "raises an ArgumentError when not given a block" do
|
||||
lambda { @yieldsmixed.send(@method) }.should raise_error(ArgumentError)
|
||||
-> { @yieldsmixed.send(@method) }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
describe "on a nested Lazy" do
|
||||
|
|
|
@ -40,7 +40,7 @@ describe "Enumerator::Lazy#take_while" do
|
|||
end
|
||||
|
||||
it "raises an ArgumentError when not given a block" do
|
||||
lambda { @yieldsmixed.take_while }.should raise_error(ArgumentError)
|
||||
-> { @yieldsmixed.take_while }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
describe "on a nested Lazy" do
|
||||
|
|
|
@ -44,7 +44,7 @@ describe "Enumerator::Lazy#zip" do
|
|||
end
|
||||
|
||||
it "raises a TypeError if arguments contain non-list object" do
|
||||
lambda { @yieldsmixed.zip [], Object.new, [] }.should raise_error(TypeError)
|
||||
-> { @yieldsmixed.zip [], Object.new, [] }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
describe "on a nested Lazy" do
|
||||
|
|
|
@ -13,14 +13,14 @@ describe "Enumerator#next" do
|
|||
|
||||
it "raises a StopIteration exception at the end of the stream" do
|
||||
3.times { @enum.next }
|
||||
lambda { @enum.next }.should raise_error(StopIteration)
|
||||
-> { @enum.next }.should raise_error(StopIteration)
|
||||
end
|
||||
|
||||
it "cannot be called again until the enumerator is rewound" do
|
||||
3.times { @enum.next }
|
||||
lambda { @enum.next }.should raise_error(StopIteration)
|
||||
lambda { @enum.next }.should raise_error(StopIteration)
|
||||
lambda { @enum.next }.should raise_error(StopIteration)
|
||||
-> { @enum.next }.should raise_error(StopIteration)
|
||||
-> { @enum.next }.should raise_error(StopIteration)
|
||||
-> { @enum.next }.should raise_error(StopIteration)
|
||||
@enum.rewind
|
||||
@enum.next.should == 1
|
||||
end
|
||||
|
|
|
@ -50,6 +50,6 @@ describe "Enumerator#next_values" do
|
|||
|
||||
it "raises StopIteration if called on a finished enumerator" do
|
||||
7.times { @e.next }
|
||||
lambda { @e.next_values }.should raise_error(StopIteration)
|
||||
-> { @e.next_values }.should raise_error(StopIteration)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,6 +31,6 @@ describe "Enumerator#peek" do
|
|||
|
||||
it "raises StopIteration if called on a finished enumerator" do
|
||||
5.times { @e.next }
|
||||
lambda { @e.peek }.should raise_error(StopIteration)
|
||||
-> { @e.peek }.should raise_error(StopIteration)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -52,6 +52,6 @@ describe "Enumerator#peek_values" do
|
|||
|
||||
it "raises StopIteration if called on a finished enumerator" do
|
||||
7.times { @e.next }
|
||||
lambda { @e.peek_values }.should raise_error(StopIteration)
|
||||
-> { @e.peek_values }.should raise_error(StopIteration)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -49,7 +49,7 @@ describe "Enumerator#rewind" do
|
|||
obj = mock('rewinder')
|
||||
enum = obj.to_enum
|
||||
obj.should_receive(:each).at_most(1)
|
||||
lambda { enum.rewind.should == enum }.should_not raise_error
|
||||
-> { enum.rewind.should == enum }.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ describe "Enumerator#size" do
|
|||
|
||||
it "returns returning value from size.call if set size is a Proc" do
|
||||
base_size = 100
|
||||
enum = Enumerator.new(lambda { base_size + 1 }) {}
|
||||
enum = Enumerator.new(-> { base_size + 1 }) {}
|
||||
base_size = 200
|
||||
enum.size.should == 201
|
||||
base_size = 300
|
||||
|
|
|
@ -14,13 +14,13 @@ describe "Enumerator#with_index" do
|
|||
end
|
||||
|
||||
it "accepts an optional argument when given a block" do
|
||||
lambda do
|
||||
-> do
|
||||
@enum.with_index(1) { |f| f}
|
||||
end.should_not raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "accepts an optional argument when not given a block" do
|
||||
lambda do
|
||||
-> do
|
||||
@enum.with_index(1)
|
||||
end.should_not raise_error(ArgumentError)
|
||||
end
|
||||
|
@ -36,7 +36,7 @@ describe "Enumerator#with_index" do
|
|||
end
|
||||
|
||||
it "raises a TypeError when the argument cannot be converted to numeric" do
|
||||
lambda do
|
||||
-> do
|
||||
@enum.with_index('1') {|*i| i}
|
||||
end.should raise_error(TypeError)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue