summaryrefslogtreecommitdiff
path: root/spec/ruby/shared
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/shared')
-rw-r--r--spec/ruby/shared/enumerator/each.rb89
-rw-r--r--spec/ruby/shared/enumerator/enum_cons.rb12
-rw-r--r--spec/ruby/shared/enumerator/new.rb42
-rw-r--r--spec/ruby/shared/enumerator/next.rb28
-rw-r--r--spec/ruby/shared/enumerator/rewind.rb39
-rw-r--r--spec/ruby/shared/rational/Rational.rb42
6 files changed, 42 insertions, 210 deletions
diff --git a/spec/ruby/shared/enumerator/each.rb b/spec/ruby/shared/enumerator/each.rb
deleted file mode 100644
index bbab86fed7..0000000000
--- a/spec/ruby/shared/enumerator/each.rb
+++ /dev/null
@@ -1,89 +0,0 @@
-# -*- encoding: us-ascii -*-
-
-describe :enum_each, shared: true do
- before :each do
- object_each_with_arguments = Object.new
- def object_each_with_arguments.each_with_arguments(arg, *args)
- yield arg, *args
- :method_returned
- end
-
- @enum_with_arguments = object_each_with_arguments.to_enum(:each_with_arguments, :arg0, :arg1, :arg2)
-
- @enum_with_yielder = Enumerator.new {|y| y.yield :ok}
- end
-
- it "yields each element of self to the given block" do
- acc = []
- [1,2,3].to_enum.each {|e| acc << e }
- acc.should == [1,2,3]
- end
-
- it "calls #each on the object given in the constructor by default" do
- each = mock('each')
- each.should_receive(:each)
- each.to_enum.each {|e| e }
- end
-
- it "calls #each on the underlying object until it's exhausted" do
- each = mock('each')
- each.should_receive(:each).and_yield(1).and_yield(2).and_yield(3)
- acc = []
- each.to_enum.each {|e| acc << e }
- acc.should == [1,2,3]
- end
-
- it "calls the method given in the constructor instead of #each" do
- each = mock('peach')
- each.should_receive(:peach)
- each.to_enum(:peach).each {|e| e }
- end
-
- it "calls the method given in the constructor until it's exhausted" do
- each = mock('each')
- each.should_receive(:each).and_yield(1).and_yield(2).and_yield(3)
- acc = []
- each.to_enum.each {|e| acc << e }
- acc.should == [1,2,3]
- end
-
- it "raises a NoMethodError if the object doesn't respond to #each" do
- enum = Object.new.to_enum
- lambda do
- enum.each { |e| e }
- end.should raise_error(NoMethodError)
- end
-
- it "returns self if not given arguments and not given a block" do
- @enum_with_arguments.each.should equal(@enum_with_arguments)
-
- @enum_with_yielder.each.should equal(@enum_with_yielder)
- end
-
- it "returns the same value from receiver.each if block is given" do
- @enum_with_arguments.each {}.should equal(:method_returned)
- end
-
- it "passes given arguments at initialized to receiver.each" do
- @enum_with_arguments.each.to_a.should == [[:arg0, :arg1, :arg2]]
- end
-
- it "requires multiple arguments" do
- Enumerator.instance_method(:each).arity.should < 0
- end
-
- it "appends given arguments to receiver.each" do
- @enum_with_arguments.each(:each0, :each1).to_a.should == [[:arg0, :arg1, :arg2, :each0, :each1]]
- @enum_with_arguments.each(:each2, :each3).to_a.should == [[:arg0, :arg1, :arg2, :each2, :each3]]
- end
-
- it "returns the same value from receiver.each if block and arguments are given" do
- @enum_with_arguments.each(:each1, :each2) {}.should equal(:method_returned)
- end
-
- it "returns new Enumerator if given arguments but not given a block" do
- ret = @enum_with_arguments.each 1
- ret.should be_an_instance_of(Enumerator)
- ret.should_not equal(@enum_with_arguments)
- end
-end
diff --git a/spec/ruby/shared/enumerator/enum_cons.rb b/spec/ruby/shared/enumerator/enum_cons.rb
deleted file mode 100644
index fec0f4766e..0000000000
--- a/spec/ruby/shared/enumerator/enum_cons.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require_relative '../../spec_helper'
-require_relative '../../fixtures/enumerator/classes'
-
-describe :enum_cons, shared: true do
- it "returns an enumerator of the receiver with iteration of each_cons for each array of n concecutive elements" do
- a = []
- enum = EnumSpecs::Numerous.new.enum_cons(3)
- enum.each {|x| a << x}
- enum.should be_an_instance_of(Enumerator)
- a.should == [[2, 5, 3], [5, 3, 6], [3, 6, 1], [6, 1, 4]]
- end
-end
diff --git a/spec/ruby/shared/enumerator/new.rb b/spec/ruby/shared/enumerator/new.rb
deleted file mode 100644
index 2eb39e0abd..0000000000
--- a/spec/ruby/shared/enumerator/new.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :enum_new, shared: true 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 responds to #each" do
- enum = Enumerator.new(1, :upto, 3)
- enum.respond_to?(:each).should == true
- 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 "aliases the second argument to :each" do
- Enumerator.new(1..2).to_a.should == Enumerator.new(1..2, :each).to_a
- end
-
- it "doesn't check for the presence of the iterator method" do
- Enumerator.new(nil).should be_an_instance_of(Enumerator)
- end
-
- 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
diff --git a/spec/ruby/shared/enumerator/next.rb b/spec/ruby/shared/enumerator/next.rb
deleted file mode 100644
index dd9a2a0f81..0000000000
--- a/spec/ruby/shared/enumerator/next.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :enum_next, shared: true do
-
- before :each do
- @enum = 1.upto(3)
- end
-
- it "returns the next element of the enumeration" do
- @enum.next.should == 1
- @enum.next.should == 2
- @enum.next.should == 3
- end
-
- it "raises a StopIteration exception at the end of the stream" do
- 3.times { @enum.next }
- lambda { @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.rewind
- @enum.next.should == 1
- end
-end
diff --git a/spec/ruby/shared/enumerator/rewind.rb b/spec/ruby/shared/enumerator/rewind.rb
deleted file mode 100644
index a3c14ec496..0000000000
--- a/spec/ruby/shared/enumerator/rewind.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :enum_rewind, shared: true do
-
- before :each do
- @enum = 1.upto(3)
- end
-
- it "resets the enumerator to its initial state" do
- @enum.next.should == 1
- @enum.next.should == 2
- @enum.rewind
- @enum.next.should == 1
- end
-
- it "returns self" do
- @enum.rewind.should == @enum
- end
-
- it "has no effect on a new enumerator" do
- @enum.rewind
- @enum.next.should == 1
- end
-
- it "has no effect if called multiple, consecutive times" do
- @enum.next.should == 1
- @enum.rewind
- @enum.rewind
- @enum.next.should == 1
- end
-
- it "works with peek to reset the position" do
- @enum.next
- @enum.next
- @enum.rewind
- @enum.next
- @enum.peek.should == 2
- end
-end
diff --git a/spec/ruby/shared/rational/Rational.rb b/spec/ruby/shared/rational/Rational.rb
index 752225269e..30425775d6 100644
--- a/spec/ruby/shared/rational/Rational.rb
+++ b/spec/ruby/shared/rational/Rational.rb
@@ -100,4 +100,46 @@ describe :kernel_Rational, shared: true do
lambda { Rational(1, :sym) }.should raise_error(TypeError)
end
end
+
+ ruby_version_is "2.6" do
+ describe "when passed exception: false" do
+ describe "and [non-Numeric]" do
+ it "swallows an error" do
+ Rational(:sym, exception: false).should == nil
+ Rational("abc", exception: false).should == nil
+ end
+ end
+
+ describe "and [non-Numeric, Numeric]" do
+ it "swallows an error" do
+ Rational(:sym, 1, exception: false).should == nil
+ Rational("abc", 1, exception: false).should == nil
+ end
+ end
+
+ describe "and [anything, non-Numeric]" do
+ it "swallows an error" do
+ Rational(:sym, :sym, exception: false).should == nil
+ Rational("abc", :sym, exception: false).should == nil
+ end
+ end
+
+ describe "and non-Numeric String arguments" do
+ it "swallows an error" do
+ Rational("a", "b", exception: false).should == nil
+ Rational("a", 0, exception: false).should == nil
+ Rational(0, "b", exception: false).should == nil
+ end
+ end
+
+ ruby_bug "#15525", "2.6"..."2.6.1" do
+ describe "and nil arguments" do
+ it "swallows an error" do
+ Rational(nil, exception: false).should == nil
+ Rational(nil, nil, exception: false).should == nil
+ end
+ end
+ end
+ end
+ end
end