mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@6f38a82
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b864bd05bf
commit
4fbb9aa3cb
145 changed files with 2847 additions and 2596 deletions
|
@ -62,34 +62,11 @@ describe "Enumerable#chunk" do
|
|||
lambda { e.chunk { |x| :_arbitrary }.to_a }.should raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
ruby_version_is ""..."2.3" do
|
||||
describe "with [initial_state]" do
|
||||
it "yields an element and an object value-equal but not identical to the object passed to #chunk" do
|
||||
e = EnumerableSpecs::Numerous.new(1)
|
||||
value = "value"
|
||||
|
||||
e.chunk(value) do |x, v|
|
||||
x.should == 1
|
||||
v.should == value
|
||||
v.should_not equal(value)
|
||||
end.to_a
|
||||
end
|
||||
|
||||
it "does not yield the object passed to #chunk if it is nil" do
|
||||
e = EnumerableSpecs::Numerous.new(1)
|
||||
e.chunk(nil) { |*x| ScratchPad << x }.to_a
|
||||
ScratchPad.recorded.should == [[1]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.3" do
|
||||
it "does not accept arguments" do
|
||||
e = EnumerableSpecs::Numerous.new(1, 2, 3)
|
||||
lambda {
|
||||
e.chunk(1) {}
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
it "does not accept arguments" do
|
||||
e = EnumerableSpecs::Numerous.new(1, 2, 3)
|
||||
lambda {
|
||||
e.chunk(1) {}
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it 'returned Enumerator size returns nil' do
|
||||
|
|
|
@ -1,44 +1,42 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative 'fixtures/classes'
|
||||
|
||||
ruby_version_is "2.3" do
|
||||
describe "Enumerable#chunk_while" do
|
||||
before :each do
|
||||
ary = [10, 9, 7, 6, 4, 3, 2, 1]
|
||||
@enum = EnumerableSpecs::Numerous.new(*ary)
|
||||
@result = @enum.chunk_while { |i, j| i - 1 == j }
|
||||
@enum_length = ary.length
|
||||
describe "Enumerable#chunk_while" do
|
||||
before :each do
|
||||
ary = [10, 9, 7, 6, 4, 3, 2, 1]
|
||||
@enum = EnumerableSpecs::Numerous.new(*ary)
|
||||
@result = @enum.chunk_while { |i, j| i - 1 == j }
|
||||
@enum_length = ary.length
|
||||
end
|
||||
|
||||
context "when given a block" do
|
||||
it "returns an enumerator" do
|
||||
@result.should be_an_instance_of(Enumerator)
|
||||
end
|
||||
|
||||
context "when given a block" do
|
||||
it "returns an enumerator" do
|
||||
@result.should be_an_instance_of(Enumerator)
|
||||
end
|
||||
|
||||
it "splits chunks between adjacent elements i and j where the block returns false" do
|
||||
@result.to_a.should == [[10, 9], [7, 6], [4, 3, 2, 1]]
|
||||
end
|
||||
|
||||
it "calls the block for length of the receiver enumerable minus one times" do
|
||||
times_called = 0
|
||||
@enum.chunk_while do |i, j|
|
||||
times_called += 1
|
||||
i - 1 == j
|
||||
end.to_a
|
||||
times_called.should == (@enum_length - 1)
|
||||
end
|
||||
it "splits chunks between adjacent elements i and j where the block returns false" do
|
||||
@result.to_a.should == [[10, 9], [7, 6], [4, 3, 2, 1]]
|
||||
end
|
||||
|
||||
context "when not given a block" do
|
||||
it "raises an ArgumentError" do
|
||||
lambda { @enum.chunk_while }.should raise_error(ArgumentError)
|
||||
end
|
||||
it "calls the block for length of the receiver enumerable minus one times" do
|
||||
times_called = 0
|
||||
@enum.chunk_while do |i, j|
|
||||
times_called += 1
|
||||
i - 1 == j
|
||||
end.to_a
|
||||
times_called.should == (@enum_length - 1)
|
||||
end
|
||||
end
|
||||
|
||||
context "on a single-element array" do
|
||||
it "ignores the block and returns an enumerator that yields [element]" do
|
||||
[1].chunk_while {|x| x.even?}.to_a.should == [[1]]
|
||||
end
|
||||
context "when not given a block" do
|
||||
it "raises an ArgumentError" do
|
||||
lambda { @enum.chunk_while }.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
context "on a single-element array" do
|
||||
it "ignores the block and returns an enumerator that yields [element]" do
|
||||
[1].chunk_while {|x| x.even?}.to_a.should == [[1]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,43 +1,41 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative 'fixtures/classes'
|
||||
|
||||
ruby_version_is "2.3" do
|
||||
describe "Enumerable#grep_v" do
|
||||
before :each do
|
||||
@numerous = EnumerableSpecs::Numerous.new(*(0..9).to_a)
|
||||
def (@odd_matcher = BasicObject.new).===(obj)
|
||||
obj.odd?
|
||||
end
|
||||
describe "Enumerable#grep_v" do
|
||||
before :each do
|
||||
@numerous = EnumerableSpecs::Numerous.new(*(0..9).to_a)
|
||||
def (@odd_matcher = BasicObject.new).===(obj)
|
||||
obj.odd?
|
||||
end
|
||||
end
|
||||
|
||||
describe "without block" do
|
||||
it "returns an Array of matched elements" do
|
||||
@numerous.grep_v(@odd_matcher).should == [0, 2, 4, 6, 8]
|
||||
end
|
||||
|
||||
describe "without block" do
|
||||
it "returns an Array of matched elements" do
|
||||
@numerous.grep_v(@odd_matcher).should == [0, 2, 4, 6, 8]
|
||||
end
|
||||
|
||||
it "compares pattern with gathered array when yielded with multiple arguments" do
|
||||
(unmatcher = Object.new).stub!(:===).and_return(false)
|
||||
EnumerableSpecs::YieldsMixed2.new.grep_v(unmatcher).should == EnumerableSpecs::YieldsMixed2.gathered_yields
|
||||
end
|
||||
|
||||
it "raises an ArgumentError when not given a pattern" do
|
||||
-> { @numerous.grep_v }.should raise_error(ArgumentError)
|
||||
end
|
||||
it "compares pattern with gathered array when yielded with multiple arguments" do
|
||||
(unmatcher = Object.new).stub!(:===).and_return(false)
|
||||
EnumerableSpecs::YieldsMixed2.new.grep_v(unmatcher).should == EnumerableSpecs::YieldsMixed2.gathered_yields
|
||||
end
|
||||
|
||||
describe "with block" do
|
||||
it "returns an Array of matched elements that mapped by the block" do
|
||||
@numerous.grep_v(@odd_matcher) { |n| n * 2 }.should == [0, 4, 8, 12, 16]
|
||||
end
|
||||
it "raises an ArgumentError when not given a pattern" do
|
||||
-> { @numerous.grep_v }.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
it "calls the block with gathered array when yielded with multiple arguments" do
|
||||
(unmatcher = Object.new).stub!(:===).and_return(false)
|
||||
EnumerableSpecs::YieldsMixed2.new.grep_v(unmatcher){ |e| e }.should == EnumerableSpecs::YieldsMixed2.gathered_yields
|
||||
end
|
||||
describe "with block" do
|
||||
it "returns an Array of matched elements that mapped by the block" do
|
||||
@numerous.grep_v(@odd_matcher) { |n| n * 2 }.should == [0, 4, 8, 12, 16]
|
||||
end
|
||||
|
||||
it "raises an ArgumentError when not given a pattern" do
|
||||
-> { @numerous.grep_v { |e| e } }.should raise_error(ArgumentError)
|
||||
end
|
||||
it "calls the block with gathered array when yielded with multiple arguments" do
|
||||
(unmatcher = Object.new).stub!(:===).and_return(false)
|
||||
EnumerableSpecs::YieldsMixed2.new.grep_v(unmatcher){ |e| e }.should == EnumerableSpecs::YieldsMixed2.gathered_yields
|
||||
end
|
||||
|
||||
it "raises an ArgumentError when not given a pattern" do
|
||||
-> { @numerous.grep_v { |e| e } }.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,33 +40,10 @@ describe "Enumerable#slice_before" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is ""..."2.3" do
|
||||
describe "and an argument" do
|
||||
it "calls the block with a copy of that argument" do
|
||||
arg = [:foo]
|
||||
first = nil
|
||||
e = @enum.slice_before(arg) do |i, init|
|
||||
init.should == arg
|
||||
init.should_not equal(arg)
|
||||
first = init
|
||||
i == 6 || i == 2
|
||||
end
|
||||
e.should be_an_instance_of(Enumerator)
|
||||
e.to_a.should == [[7], [6, 5, 4, 3], [2, 1]]
|
||||
e = @enum.slice_before(arg) do |i, init|
|
||||
init.should_not equal(first)
|
||||
end
|
||||
e.to_a
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.3" do
|
||||
it "does not accept arguments" do
|
||||
lambda {
|
||||
@enum.slice_before(1) {}
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
it "does not accept arguments" do
|
||||
lambda {
|
||||
@enum.slice_before(1) {}
|
||||
}.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue