summaryrefslogtreecommitdiff
path: root/spec/ruby/shared
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2024-02-05 16:29:57 +0100
committerBenoit Daloze <eregontp@gmail.com>2024-02-05 16:29:57 +0100
commit40642cd3bc581d3bb402ea5e8e61cdfb868b4f68 (patch)
tree077cc3ac94f880ce3c8c98322331c01cb1cc9cb8 /spec/ruby/shared
parentabe07d4bf5f2f848b22e511a647a85c878066adb (diff)
Update to ruby/spec@3fc4444
Diffstat (limited to 'spec/ruby/shared')
-rw-r--r--spec/ruby/shared/kernel/at_exit.rb5
-rw-r--r--spec/ruby/shared/queue/deque.rb34
-rw-r--r--spec/ruby/shared/rational/coerce.rb46
-rw-r--r--spec/ruby/shared/sizedqueue/enque.rb34
4 files changed, 56 insertions, 63 deletions
diff --git a/spec/ruby/shared/kernel/at_exit.rb b/spec/ruby/shared/kernel/at_exit.rb
index 26ad361a5b..16d41cb01c 100644
--- a/spec/ruby/shared/kernel/at_exit.rb
+++ b/spec/ruby/shared/kernel/at_exit.rb
@@ -54,7 +54,10 @@ describe :kernel_at_exit, shared: true do
result = ruby_exe('{', options: "-r#{script}", args: "2>&1", exit_status: 1)
$?.should_not.success?
result.should.include?("handler ran\n")
- result.should.include?("syntax error")
+
+ # it's tempting not to rely on error message and rely only on exception class name,
+ # but CRuby before 3.2 doesn't print class name for syntax error
+ result.should include_any_of("syntax error", "SyntaxError")
end
it "calls the nested handler right after the outer one if a handler is nested into another handler" do
diff --git a/spec/ruby/shared/queue/deque.rb b/spec/ruby/shared/queue/deque.rb
index 9e6b45009d..0abba5301e 100644
--- a/spec/ruby/shared/queue/deque.rb
+++ b/spec/ruby/shared/queue/deque.rb
@@ -70,7 +70,7 @@ describe :queue_deq, shared: true do
q = @object.call
t = Thread.new {
- q.send(@method, timeout: 1).should == 1
+ q.send(@method, timeout: TIME_TOLERANCE).should == 1
}
Thread.pass until t.status == "sleep" && q.num_waiting == 1
q << 1
@@ -80,10 +80,9 @@ describe :queue_deq, shared: true do
it "returns nil if no item is available in time" do
q = @object.call
- t = Thread.new {
- q.send(@method, timeout: 0.1).should == nil
- }
- t.join
+ Thread.new {
+ q.send(@method, timeout: 0.001).should == nil
+ }.join
end
it "does nothing if the timeout is nil" do
@@ -91,7 +90,7 @@ describe :queue_deq, shared: true do
t = Thread.new {
q.send(@method, timeout: nil).should == 1
}
- t.join(0.2).should == nil
+ Thread.pass until t.status == "sleep" && q.num_waiting == 1
q << 1
t.join
end
@@ -105,23 +104,20 @@ describe :queue_deq, shared: true do
it "raise TypeError if timeout is not a valid numeric" do
q = @object.call
- -> { q.send(@method, timeout: "1") }.should raise_error(
- TypeError,
- "no implicit conversion to float from string",
- )
-
- -> { q.send(@method, timeout: false) }.should raise_error(
- TypeError,
- "no implicit conversion to float from false",
- )
+ -> {
+ q.send(@method, timeout: "1")
+ }.should raise_error(TypeError, "no implicit conversion to float from string")
+
+ -> {
+ q.send(@method, timeout: false)
+ }.should raise_error(TypeError, "no implicit conversion to float from false")
end
it "raise ArgumentError if non_block = true is passed too" do
q = @object.call
- -> { q.send(@method, true, timeout: 1) }.should raise_error(
- ArgumentError,
- "can't set a timeout if non_block is enabled",
- )
+ -> {
+ q.send(@method, true, timeout: 1)
+ }.should raise_error(ArgumentError, "can't set a timeout if non_block is enabled")
end
it "returns nil for a closed empty queue" do
diff --git a/spec/ruby/shared/rational/coerce.rb b/spec/ruby/shared/rational/coerce.rb
index 1650668fe6..38925721ed 100644
--- a/spec/ruby/shared/rational/coerce.rb
+++ b/spec/ruby/shared/rational/coerce.rb
@@ -1,33 +1,31 @@
require_relative '../../spec_helper'
-ruby_version_is ""..."3.4" do
-
- require 'bigdecimal'
-
- describe :rational_coerce, shared: true do
- it "returns the passed argument, self as Float, when given a Float" do
- result = Rational(3, 4).coerce(1.0)
- result.should == [1.0, 0.75]
- result.first.is_a?(Float).should be_true
- result.last.is_a?(Float).should be_true
- end
+describe :rational_coerce, shared: true do
+ it "returns the passed argument, self as Float, when given a Float" do
+ result = Rational(3, 4).coerce(1.0)
+ result.should == [1.0, 0.75]
+ result.first.is_a?(Float).should be_true
+ result.last.is_a?(Float).should be_true
+ end
- it "returns the passed argument, self as Rational, when given an Integer" do
- result = Rational(3, 4).coerce(10)
- result.should == [Rational(10, 1), Rational(3, 4)]
- result.first.is_a?(Rational).should be_true
- result.last.is_a?(Rational).should be_true
- end
+ it "returns the passed argument, self as Rational, when given an Integer" do
+ result = Rational(3, 4).coerce(10)
+ result.should == [Rational(10, 1), Rational(3, 4)]
+ result.first.is_a?(Rational).should be_true
+ result.last.is_a?(Rational).should be_true
+ end
- it "coerces to Rational, when given a Complex" do
- Rational(3, 4).coerce(Complex(5)).should == [Rational(5, 1), Rational(3, 4)]
- Rational(12, 4).coerce(Complex(5, 1)).should == [Complex(5, 1), Complex(3)]
- end
+ it "coerces to Rational, when given a Complex" do
+ Rational(3, 4).coerce(Complex(5)).should == [Rational(5, 1), Rational(3, 4)]
+ Rational(12, 4).coerce(Complex(5, 1)).should == [Complex(5, 1), Complex(3)]
+ end
- it "returns [argument, self] when given a Rational" do
- Rational(3, 7).coerce(Rational(9, 2)).should == [Rational(9, 2), Rational(3, 7)]
- end
+ it "returns [argument, self] when given a Rational" do
+ Rational(3, 7).coerce(Rational(9, 2)).should == [Rational(9, 2), Rational(3, 7)]
+ end
+ ruby_version_is ""..."3.4" do
+ require 'bigdecimal'
it "raises an error when passed a BigDecimal" do
-> {
Rational(500, 3).coerce(BigDecimal('166.666666666'))
diff --git a/spec/ruby/shared/sizedqueue/enque.rb b/spec/ruby/shared/sizedqueue/enque.rb
index 6307f3c3ca..2f25517675 100644
--- a/spec/ruby/shared/sizedqueue/enque.rb
+++ b/spec/ruby/shared/sizedqueue/enque.rb
@@ -55,7 +55,7 @@ describe :sizedqueue_enq, shared: true do
q << 1
t = Thread.new {
- q.send(@method, 2, timeout: 1).should == q
+ q.send(@method, 2, timeout: TIME_TOLERANCE).should == q
}
Thread.pass until t.status == "sleep" && q.num_waiting == 1
q.pop
@@ -82,31 +82,27 @@ describe :sizedqueue_enq, shared: true do
it "returns nil if no space is available in time" do
q = @object.call(1)
q << 1
- t = Thread.new {
- q.send(@method, 2, timeout: 0.1).should == nil
- }
- t.join
+ Thread.new {
+ q.send(@method, 2, timeout: 0.001).should == nil
+ }.join
end
it "raise TypeError if timeout is not a valid numeric" do
q = @object.call(1)
- -> { q.send(@method, 2, timeout: "1") }.should raise_error(
- TypeError,
- "no implicit conversion to float from string",
- )
-
- -> { q.send(@method, 2, timeout: false) }.should raise_error(
- TypeError,
- "no implicit conversion to float from false",
- )
+ -> {
+ q.send(@method, 2, timeout: "1")
+ }.should raise_error(TypeError, "no implicit conversion to float from string")
+
+ -> {
+ q.send(@method, 2, timeout: false)
+ }.should raise_error(TypeError, "no implicit conversion to float from false")
end
it "raise ArgumentError if non_block = true is passed too" do
q = @object.call(1)
- -> { q.send(@method, 2, true, timeout: 1) }.should raise_error(
- ArgumentError,
- "can't set a timeout if non_block is enabled",
- )
+ -> {
+ q.send(@method, 2, true, timeout: 1)
+ }.should raise_error(ArgumentError, "can't set a timeout if non_block is enabled")
end
it "raise ClosedQueueError when closed before enqueued" do
@@ -120,7 +116,7 @@ describe :sizedqueue_enq, shared: true do
q << 1
t = Thread.new {
- -> { q.send(@method, 1, timeout: 10) }.should raise_error(ClosedQueueError, "queue closed")
+ -> { q.send(@method, 1, timeout: TIME_TOLERANCE) }.should raise_error(ClosedQueueError, "queue closed")
}
Thread.pass until q.num_waiting == 1