aboutsummaryrefslogtreecommitdiffstats
path: root/spec/rubyspec/core/enumerator
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubyspec/core/enumerator')
-rw-r--r--spec/rubyspec/core/enumerator/inspect_spec.rb14
-rw-r--r--spec/rubyspec/core/enumerator/lazy/grep_spec.rb2
-rw-r--r--spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb2
-rw-r--r--spec/rubyspec/core/enumerator/lazy/uniq_spec.rb39
4 files changed, 54 insertions, 3 deletions
diff --git a/spec/rubyspec/core/enumerator/inspect_spec.rb b/spec/rubyspec/core/enumerator/inspect_spec.rb
index e89d3b7f3a..b708256247 100644
--- a/spec/rubyspec/core/enumerator/inspect_spec.rb
+++ b/spec/rubyspec/core/enumerator/inspect_spec.rb
@@ -1,5 +1,17 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "Enumerator#inspect" do
- it "needs to be reviewed for spec completeness"
+ describe "shows a representation of the Enumerator" do
+ it "including receiver and method" do
+ (1..3).each.inspect.should == "#<Enumerator: 1..3:each>"
+ end
+
+ it "including receiver and method and arguments" do
+ (1..3).each_slice(2).inspect.should == "#<Enumerator: 1..3:each_slice(2)>"
+ end
+
+ it "including the nested Enumerator" do
+ (1..3).each.each_slice(2).inspect.should == "#<Enumerator: #<Enumerator: 1..3:each>:each_slice(2)>"
+ end
+ end
end
diff --git a/spec/rubyspec/core/enumerator/lazy/grep_spec.rb b/spec/rubyspec/core/enumerator/lazy/grep_spec.rb
index c5fbfcf1dd..372be80d61 100644
--- a/spec/rubyspec/core/enumerator/lazy/grep_spec.rb
+++ b/spec/rubyspec/core/enumerator/lazy/grep_spec.rb
@@ -64,7 +64,7 @@ describe "Enumerator::Lazy#grep" do
end
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
- it "stops after specified times when not given a block" do
+ it "stops after specified times when not given a block" do
(0..Float::INFINITY).lazy.grep(Integer).grep(Object).first(3).should == [0, 1, 2]
@eventsmixed.grep(BasicObject).grep(Object).first(1)
diff --git a/spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb b/spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb
index 06dd42213c..123cbae58c 100644
--- a/spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb
+++ b/spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb
@@ -63,7 +63,7 @@ ruby_version_is "2.3" do
end
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
- it "stops after specified times when not given a block" do
+ it "stops after specified times when not given a block" do
(0..Float::INFINITY).lazy.grep_v(3..5).grep_v(6..10).first(3).should == [0, 1, 2]
@eventsmixed.grep_v(Symbol).grep_v(String).first(1)
diff --git a/spec/rubyspec/core/enumerator/lazy/uniq_spec.rb b/spec/rubyspec/core/enumerator/lazy/uniq_spec.rb
new file mode 100644
index 0000000000..6220c7ba34
--- /dev/null
+++ b/spec/rubyspec/core/enumerator/lazy/uniq_spec.rb
@@ -0,0 +1,39 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+
+ruby_version_is '2.4' do
+ describe 'Enumerator::Lazy#uniq' do
+ context 'when yielded with an argument' do
+ before :each do
+ @lazy = [0, 1, 2, 3].to_enum.lazy.uniq(&:even?)
+ end
+
+ it 'returns a lazy enumerator' do
+ @lazy.should be_an_instance_of(Enumerator::Lazy)
+ @lazy.force.should == [0, 1]
+ end
+
+ it 'sets the size to nil' do
+ @lazy.size.should == nil
+ end
+ end
+
+ context 'when yielded with multiple arguments' do
+ before :each do
+ enum = Object.new.to_enum
+ class << enum
+ def each
+ yield 0, 'foo'
+ yield 1, 'FOO'
+ yield 2, 'bar'
+ end
+ end
+ @lazy = enum.lazy
+ end
+
+ it 'returns all yield arguments as an array' do
+ @lazy.uniq { |_, label| label.downcase }.force.should == [[0, 'foo'], [2, 'bar']]
+ end
+ end
+ end
+end