summaryrefslogtreecommitdiff
path: root/spec/ruby/core/enumerable
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-28 19:50:06 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-28 19:50:06 +0000
commit4fbb9aa3cb6c31ec128bfb31f59efa66d66adba4 (patch)
tree84a654b260261fe172f2584f60b3ba93e59f841d /spec/ruby/core/enumerable
parentb864bd05bff2a61d55b08deb92e969f9fa55e07c (diff)
Update to ruby/spec@6f38a82
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/enumerable')
-rw-r--r--spec/ruby/core/enumerable/chunk_spec.rb33
-rw-r--r--spec/ruby/core/enumerable/chunk_while_spec.rb60
-rw-r--r--spec/ruby/core/enumerable/grep_v_spec.rb56
-rw-r--r--spec/ruby/core/enumerable/slice_before_spec.rb31
4 files changed, 65 insertions, 115 deletions
diff --git a/spec/ruby/core/enumerable/chunk_spec.rb b/spec/ruby/core/enumerable/chunk_spec.rb
index 9215d97fef..34fa651b33 100644
--- a/spec/ruby/core/enumerable/chunk_spec.rb
+++ b/spec/ruby/core/enumerable/chunk_spec.rb
@@ -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
diff --git a/spec/ruby/core/enumerable/chunk_while_spec.rb b/spec/ruby/core/enumerable/chunk_while_spec.rb
index 29645da1fe..88d6d2983f 100644
--- a/spec/ruby/core/enumerable/chunk_while_spec.rb
+++ b/spec/ruby/core/enumerable/chunk_while_spec.rb
@@ -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
- end
+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 "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 "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 "when not given a block" do
- it "raises an ArgumentError" do
- lambda { @enum.chunk_while }.should raise_error(ArgumentError)
- 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
+ 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
diff --git a/spec/ruby/core/enumerable/grep_v_spec.rb b/spec/ruby/core/enumerable/grep_v_spec.rb
index 8d8bc28d5e..2268005dee 100644
--- a/spec/ruby/core/enumerable/grep_v_spec.rb
+++ b/spec/ruby/core/enumerable/grep_v_spec.rb
@@ -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 "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 "raises an ArgumentError when not given a pattern" do
+ -> { @numerous.grep_v }.should raise_error(ArgumentError)
end
+ 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
+ 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 "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 "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
+ it "raises an ArgumentError when not given a pattern" do
+ -> { @numerous.grep_v { |e| e } }.should raise_error(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/enumerable/slice_before_spec.rb b/spec/ruby/core/enumerable/slice_before_spec.rb
index 932d06072a..ad730be245 100644
--- a/spec/ruby/core/enumerable/slice_before_spec.rb
+++ b/spec/ruby/core/enumerable/slice_before_spec.rb
@@ -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