summaryrefslogtreecommitdiff
path: root/spec/ruby/shared
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/shared')
-rw-r--r--spec/ruby/shared/basicobject/method_missing.rb18
-rw-r--r--spec/ruby/shared/basicobject/send.rb10
-rw-r--r--spec/ruby/shared/enumerable/minmax.rb24
-rw-r--r--spec/ruby/shared/enumerator/enum_for.rb7
-rw-r--r--spec/ruby/shared/enumerator/with_index.rb11
-rw-r--r--spec/ruby/shared/fiber/resume.rb29
-rw-r--r--spec/ruby/shared/file/directory.rb6
-rw-r--r--spec/ruby/shared/file/executable.rb45
-rw-r--r--spec/ruby/shared/file/executable_real.rb43
-rw-r--r--spec/ruby/shared/file/exist.rb6
-rw-r--r--spec/ruby/shared/file/file.rb8
-rw-r--r--spec/ruby/shared/file/grpowned.rb3
-rw-r--r--spec/ruby/shared/file/identical.rb12
-rw-r--r--spec/ruby/shared/file/readable.rb21
-rw-r--r--spec/ruby/shared/file/readable_real.rb16
-rw-r--r--spec/ruby/shared/file/size.rb2
-rw-r--r--spec/ruby/shared/file/world_readable.rb14
-rw-r--r--spec/ruby/shared/file/world_writable.rb14
-rw-r--r--spec/ruby/shared/file/writable.rb18
-rw-r--r--spec/ruby/shared/file/writable_real.rb24
-rw-r--r--spec/ruby/shared/file/zero.rb8
-rw-r--r--spec/ruby/shared/hash/key_error.rb28
-rw-r--r--spec/ruby/shared/io/putc.rb12
-rw-r--r--spec/ruby/shared/kernel/complex.rb133
-rw-r--r--spec/ruby/shared/kernel/raise.rb138
-rw-r--r--spec/ruby/shared/math/atanh.rb8
-rw-r--r--spec/ruby/shared/process/abort.rb12
-rw-r--r--spec/ruby/shared/process/exit.rb52
-rw-r--r--spec/ruby/shared/process/fork.rb6
-rw-r--r--spec/ruby/shared/queue/deque.rb66
-rw-r--r--spec/ruby/shared/queue/enque.rb2
-rw-r--r--spec/ruby/shared/rational/Rational.rb104
-rw-r--r--spec/ruby/shared/rational/arithmetic_exception_in_coerce.rb32
-rw-r--r--spec/ruby/shared/rational/coerce.rb13
-rw-r--r--spec/ruby/shared/rational/comparison.rb30
-rw-r--r--spec/ruby/shared/rational/div.rb12
-rw-r--r--spec/ruby/shared/rational/divide.rb4
-rw-r--r--spec/ruby/shared/rational/divmod.rb12
-rw-r--r--spec/ruby/shared/rational/exponent.rb52
-rw-r--r--spec/ruby/shared/rational/minus.rb48
-rw-r--r--spec/ruby/shared/rational/modulo.rb8
-rw-r--r--spec/ruby/shared/rational/round.rb49
-rw-r--r--spec/ruby/shared/rational/to_f.rb6
-rw-r--r--spec/ruby/shared/sizedqueue/enque.rb67
-rw-r--r--spec/ruby/shared/sizedqueue/max.rb8
-rw-r--r--spec/ruby/shared/sizedqueue/new.rb17
-rw-r--r--spec/ruby/shared/string/end_with.rb61
-rw-r--r--spec/ruby/shared/string/start_with.rb76
-rw-r--r--spec/ruby/shared/string/times.rb46
-rw-r--r--spec/ruby/shared/time/strftime_for_date.rb10
-rw-r--r--spec/ruby/shared/time/strftime_for_time.rb8
51 files changed, 1028 insertions, 431 deletions
diff --git a/spec/ruby/shared/basicobject/method_missing.rb b/spec/ruby/shared/basicobject/method_missing.rb
index 0759dd9606..4871603dce 100644
--- a/spec/ruby/shared/basicobject/method_missing.rb
+++ b/spec/ruby/shared/basicobject/method_missing.rb
@@ -24,15 +24,15 @@ end
describe :method_missing_module, shared: true do
describe "for a Module" do
it "raises a NoMethodError when an undefined method is called" do
- lambda { @object.no_such_method }.should raise_error(NoMethodError)
+ -> { @object.no_such_method }.should raise_error(NoMethodError)
end
it "raises a NoMethodError when a protected method is called" do
- lambda { @object.method_protected }.should raise_error(NoMethodError)
+ -> { @object.method_protected }.should raise_error(NoMethodError)
end
it "raises a NoMethodError when a private method is called" do
- lambda { @object.method_private }.should raise_error(NoMethodError)
+ -> { @object.method_private }.should raise_error(NoMethodError)
end
end
end
@@ -60,15 +60,15 @@ end
describe :method_missing_class, shared: true do
describe "for a Class" do
it "raises a NoMethodError when an undefined method is called" do
- lambda { @object.no_such_method }.should raise_error(NoMethodError)
+ -> { @object.no_such_method }.should raise_error(NoMethodError)
end
it "raises a NoMethodError when a protected method is called" do
- lambda { @object.method_protected }.should raise_error(NoMethodError)
+ -> { @object.method_protected }.should raise_error(NoMethodError)
end
it "raises a NoMethodError when a private method is called" do
- lambda { @object.method_private }.should raise_error(NoMethodError)
+ -> { @object.method_private }.should raise_error(NoMethodError)
end
end
end
@@ -100,15 +100,15 @@ end
describe :method_missing_instance, shared: true do
describe "for an instance" do
it "raises a NoMethodError when an undefined method is called" do
- lambda { @object.new.no_such_method }.should raise_error(NoMethodError)
+ -> { @object.new.no_such_method }.should raise_error(NoMethodError)
end
it "raises a NoMethodError when a protected method is called" do
- lambda { @object.new.method_protected }.should raise_error(NoMethodError)
+ -> { @object.new.method_protected }.should raise_error(NoMethodError)
end
it "raises a NoMethodError when a private method is called" do
- lambda { @object.new.method_private }.should raise_error(NoMethodError)
+ -> { @object.new.method_private }.should raise_error(NoMethodError)
end
it 'sets the receiver of the raised NoMethodError' do
diff --git a/spec/ruby/shared/basicobject/send.rb b/spec/ruby/shared/basicobject/send.rb
index f96a3593bd..625aaa2917 100644
--- a/spec/ruby/shared/basicobject/send.rb
+++ b/spec/ruby/shared/basicobject/send.rb
@@ -42,7 +42,7 @@ describe :basicobject_send, shared: true do
'done'
end
end
- lambda { SendSpecs::Foo.new.send(@method, :syegsywhwua) }.should raise_error(NameError)
+ -> { SendSpecs::Foo.new.send(@method, :syegsywhwua) }.should raise_error(NameError)
end
it "raises a NameError if the corresponding singleton method can't be found" do
@@ -51,12 +51,12 @@ describe :basicobject_send, shared: true do
'done'
end
end
- lambda { SendSpecs::Foo.send(@method, :baz) }.should raise_error(NameError)
+ -> { SendSpecs::Foo.send(@method, :baz) }.should raise_error(NameError)
end
it "raises an ArgumentError if no arguments are given" do
class SendSpecs::Foo; end
- lambda { SendSpecs::Foo.new.send @method }.should raise_error(ArgumentError)
+ -> { SendSpecs::Foo.new.send @method }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if called with more arguments than available parameters" do
@@ -64,7 +64,7 @@ describe :basicobject_send, shared: true do
def bar; end
end
- lambda { SendSpecs::Foo.new.send(@method, :bar, :arg) }.should raise_error(ArgumentError)
+ -> { SendSpecs::Foo.new.send(@method, :bar, :arg) }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if called with fewer arguments than required parameters" do
@@ -72,7 +72,7 @@ describe :basicobject_send, shared: true do
def foo(arg); end
end
- lambda { SendSpecs::Foo.new.send(@method, :foo) }.should raise_error(ArgumentError)
+ -> { SendSpecs::Foo.new.send(@method, :foo) }.should raise_error(ArgumentError)
end
it "succeeds if passed an arbitrary number of arguments as a splat parameter" do
diff --git a/spec/ruby/shared/enumerable/minmax.rb b/spec/ruby/shared/enumerable/minmax.rb
new file mode 100644
index 0000000000..8af2626d2a
--- /dev/null
+++ b/spec/ruby/shared/enumerable/minmax.rb
@@ -0,0 +1,24 @@
+describe :enumerable_minmax, shared: true do
+ it "min should return the minimum element" do
+ @enum.minmax.should == [4, 10]
+ @strs.minmax.should == ["1010", "60"]
+ end
+
+ it "returns the minimum when using a block rule" do
+ @enum.minmax {|a,b| b <=> a }.should == [10, 4]
+ @strs.minmax {|a,b| a.length <=> b.length }.should == ["2", "55555"]
+ end
+
+ it "returns [nil, nil] for an empty Enumerable" do
+ @empty_enum.minmax.should == [nil, nil]
+ end
+
+ it "raises a NoMethodError for elements without #<=>" do
+ -> { @incomparable_enum.minmax }.should raise_error(NoMethodError)
+ end
+
+ it "raises an ArgumentError when elements are incompatible" do
+ -> { @incompatible_enum.minmax }.should raise_error(ArgumentError)
+ -> { @enum.minmax{ |a, b| nil } }.should raise_error(ArgumentError)
+ end
+end
diff --git a/spec/ruby/shared/enumerator/enum_for.rb b/spec/ruby/shared/enumerator/enum_for.rb
index 9030ffbd7d..a67a76c461 100644
--- a/spec/ruby/shared/enumerator/enum_for.rb
+++ b/spec/ruby/shared/enumerator/enum_for.rb
@@ -12,6 +12,13 @@ describe :enum_for, shared: true do
enum.map { |v| v }.should == [1,2].each { |v| v }
end
+ it "sets regexp matches in the caller" do
+ "wawa".send(@method, :scan, /./).map {|o| $& }.should == ["w", "a", "w", "a"]
+ a = []
+ "wawa".send(@method, :scan, /./).each {|o| a << $& }
+ a.should == ["w", "a", "w", "a"]
+ end
+
it "exposes multi-arg yields as an array" do
o = Object.new
def o.each
diff --git a/spec/ruby/shared/enumerator/with_index.rb b/spec/ruby/shared/enumerator/with_index.rb
index 4f459bd9a8..89f40070e0 100644
--- a/spec/ruby/shared/enumerator/with_index.rb
+++ b/spec/ruby/shared/enumerator/with_index.rb
@@ -5,17 +5,18 @@ describe :enum_with_index, shared: true do
require_relative '../../fixtures/enumerator/classes'
before :each do
- @enum = [1, 2, 3, 4].to_enum
+ @origin = [1, 2, 3, 4]
+ @enum = @origin.to_enum
end
it "passes each element and its index to block" do
- @a = []
- @enum.send(@method) { |o, i| @a << [o, i] }
- @a.should == [[1, 0], [2, 1], [3, 2], [4, 3]]
+ a = []
+ @enum.send(@method) { |o, i| a << [o, i] }
+ a.should == [[1, 0], [2, 1], [3, 2], [4, 3]]
end
it "returns the object being enumerated when given a block" do
- [1, 2, 3, 4].should == @enum.send(@method) { |o, i| :glark }
+ @enum.send(@method) { |o, i| :glark }.should equal(@origin)
end
it "binds splat arguments properly" do
diff --git a/spec/ruby/shared/fiber/resume.rb b/spec/ruby/shared/fiber/resume.rb
index e2d30d781b..f3477804ad 100644
--- a/spec/ruby/shared/fiber/resume.rb
+++ b/spec/ruby/shared/fiber/resume.rb
@@ -35,45 +35,24 @@ describe :fiber_resume, shared: true do
fiber.send(@method)
end
- it "runs until Fiber.yield" do
- obj = mock('obj')
- obj.should_not_receive(:do)
- fiber = Fiber.new { 1 + 2; Fiber.yield; obj.do }
- fiber.send(@method)
- end
-
- it "resumes from the last call to Fiber.yield on subsequent invocations" do
- fiber = Fiber.new { Fiber.yield :first; :second }
- fiber.send(@method).should == :first
- fiber.send(@method).should == :second
- end
-
it "accepts any number of arguments" do
fiber = Fiber.new { |a| }
- lambda { fiber.send(@method, *(1..10).to_a) }.should_not raise_error
- end
-
- it "sets the block parameters to its arguments on the first invocation" do
- first = mock('first')
- first.should_receive(:arg).with(:first).twice
- fiber = Fiber.new { |arg| first.arg arg; Fiber.yield; first.arg arg; }
- fiber.send(@method, :first)
- fiber.send(@method, :second)
+ -> { fiber.send(@method, *(1..10).to_a) }.should_not raise_error
end
it "raises a FiberError if the Fiber is dead" do
fiber = Fiber.new { true }
fiber.send(@method)
- lambda { fiber.send(@method) }.should raise_error(FiberError)
+ -> { fiber.send(@method) }.should raise_error(FiberError)
end
it "raises a LocalJumpError if the block includes a return statement" do
fiber = Fiber.new { return; }
- lambda { fiber.send(@method) }.should raise_error(LocalJumpError)
+ -> { fiber.send(@method) }.should raise_error(LocalJumpError)
end
it "raises a LocalJumpError if the block includes a break statement" do
fiber = Fiber.new { break; }
- lambda { fiber.send(@method) }.should raise_error(LocalJumpError)
+ -> { fiber.send(@method) }.should raise_error(LocalJumpError)
end
end
diff --git a/spec/ruby/shared/file/directory.rb b/spec/ruby/shared/file/directory.rb
index 67e939bf16..8ba933a601 100644
--- a/spec/ruby/shared/file/directory.rb
+++ b/spec/ruby/shared/file/directory.rb
@@ -24,12 +24,12 @@ describe :file_directory, shared: true do
end
it "raises a TypeError when passed an Integer" do
- lambda { @object.send(@method, 1) }.should raise_error(TypeError)
- lambda { @object.send(@method, bignum_value) }.should raise_error(TypeError)
+ -> { @object.send(@method, 1) }.should raise_error(TypeError)
+ -> { @object.send(@method, bignum_value) }.should raise_error(TypeError)
end
it "raises a TypeError when passed nil" do
- lambda { @object.send(@method, nil) }.should raise_error(TypeError)
+ -> { @object.send(@method, nil) }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/shared/file/executable.rb b/spec/ruby/shared/file/executable.rb
index 5b21fb0d97..baa156de98 100644
--- a/spec/ruby/shared/file/executable.rb
+++ b/spec/ruby/shared/file/executable.rb
@@ -13,7 +13,7 @@ describe :file_executable, shared: true do
rm_r @file1, @file2
end
- platform_is_not :windows do
+ platform_is_not :windows, :android do
it "returns true if named file is executable by the effective user id of the process, otherwise false" do
@object.send(@method, '/etc/passwd').should == false
@object.send(@method, @file1).should == true
@@ -31,13 +31,48 @@ describe :file_executable, shared: true do
end
it "raises an ArgumentError if not passed one argument" do
- lambda { @object.send(@method) }.should raise_error(ArgumentError)
+ -> { @object.send(@method) }.should raise_error(ArgumentError)
end
it "raises a TypeError if not passed a String type" do
- lambda { @object.send(@method, 1) }.should raise_error(TypeError)
- lambda { @object.send(@method, nil) }.should raise_error(TypeError)
- lambda { @object.send(@method, false) }.should raise_error(TypeError)
+ -> { @object.send(@method, 1) }.should raise_error(TypeError)
+ -> { @object.send(@method, nil) }.should raise_error(TypeError)
+ -> { @object.send(@method, false) }.should raise_error(TypeError)
+ end
+
+ platform_is_not :windows do
+ as_superuser do
+ context "when run by a superuser" do
+ before :each do
+ @file = tmp('temp3.txt')
+ touch @file
+ end
+
+ after :each do
+ rm_r @file
+ end
+
+ it "returns true if file owner has permission to execute" do
+ File.chmod(0766, @file)
+ @object.send(@method, @file).should == true
+ end
+
+ it "returns true if group has permission to execute" do
+ File.chmod(0676, @file)
+ @object.send(@method, @file).should == true
+ end
+
+ it "returns true if other have permission to execute" do
+ File.chmod(0667, @file)
+ @object.send(@method, @file).should == true
+ end
+
+ it "return false if nobody has permission to execute" do
+ File.chmod(0666, @file)
+ @object.send(@method, @file).should == false
+ end
+ end
+ end
end
end
diff --git a/spec/ruby/shared/file/executable_real.rb b/spec/ruby/shared/file/executable_real.rb
index 2b1bf8f585..bf2734ea07 100644
--- a/spec/ruby/shared/file/executable_real.rb
+++ b/spec/ruby/shared/file/executable_real.rb
@@ -29,13 +29,48 @@ describe :file_executable_real, shared: true do
end
it "raises an ArgumentError if not passed one argument" do
- lambda { @object.send(@method) }.should raise_error(ArgumentError)
+ -> { @object.send(@method) }.should raise_error(ArgumentError)
end
it "raises a TypeError if not passed a String type" do
- lambda { @object.send(@method, 1) }.should raise_error(TypeError)
- lambda { @object.send(@method, nil) }.should raise_error(TypeError)
- lambda { @object.send(@method, false) }.should raise_error(TypeError)
+ -> { @object.send(@method, 1) }.should raise_error(TypeError)
+ -> { @object.send(@method, nil) }.should raise_error(TypeError)
+ -> { @object.send(@method, false) }.should raise_error(TypeError)
+ end
+
+ platform_is_not :windows do
+ as_real_superuser do
+ context "when run by a real superuser" do
+ before :each do
+ @file = tmp('temp3.txt')
+ touch @file
+ end
+
+ after :each do
+ rm_r @file
+ end
+
+ it "returns true if file owner has permission to execute" do
+ File.chmod(0766, @file)
+ @object.send(@method, @file).should == true
+ end
+
+ it "returns true if group has permission to execute" do
+ File.chmod(0676, @file)
+ @object.send(@method, @file).should == true
+ end
+
+ it "returns true if other have permission to execute" do
+ File.chmod(0667, @file)
+ @object.send(@method, @file).should == true
+ end
+
+ it "return false if nobody has permission to execute" do
+ File.chmod(0666, @file)
+ @object.send(@method, @file).should == false
+ end
+ end
+ end
end
end
diff --git a/spec/ruby/shared/file/exist.rb b/spec/ruby/shared/file/exist.rb
index 1557f01a82..3bd97711b4 100644
--- a/spec/ruby/shared/file/exist.rb
+++ b/spec/ruby/shared/file/exist.rb
@@ -10,12 +10,12 @@ describe :file_exist, shared: true do
end
it "raises an ArgumentError if not passed one argument" do
- lambda { @object.send(@method) }.should raise_error(ArgumentError)
- lambda { @object.send(@method, __FILE__, __FILE__) }.should raise_error(ArgumentError)
+ -> { @object.send(@method) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, __FILE__, __FILE__) }.should raise_error(ArgumentError)
end
it "raises a TypeError if not passed a String type" do
- lambda { @object.send(@method, nil) }.should raise_error(TypeError)
+ -> { @object.send(@method, nil) }.should raise_error(TypeError)
end
it "accepts an object that has a #to_path method" do
diff --git a/spec/ruby/shared/file/file.rb b/spec/ruby/shared/file/file.rb
index 095bd63fff..c1748a88b3 100644
--- a/spec/ruby/shared/file/file.rb
+++ b/spec/ruby/shared/file/file.rb
@@ -34,12 +34,12 @@ describe :file_file, shared: true do
end
it "raises an ArgumentError if not passed one argument" do
- lambda { @object.send(@method) }.should raise_error(ArgumentError)
- lambda { @object.send(@method, @null, @file) }.should raise_error(ArgumentError)
+ -> { @object.send(@method) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, @null, @file) }.should raise_error(ArgumentError)
end
it "raises a TypeError if not passed a String type" do
- lambda { @object.send(@method, nil) }.should raise_error(TypeError)
- lambda { @object.send(@method, 1) }.should raise_error(TypeError)
+ -> { @object.send(@method, nil) }.should raise_error(TypeError)
+ -> { @object.send(@method, 1) }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/shared/file/grpowned.rb b/spec/ruby/shared/file/grpowned.rb
index 91a6483030..24e84c28e3 100644
--- a/spec/ruby/shared/file/grpowned.rb
+++ b/spec/ruby/shared/file/grpowned.rb
@@ -26,8 +26,7 @@ describe :file_grpowned, shared: true do
@object.send(@method, @file).should == true
else
- # No supplementary groups
- 1.should == 1
+ skip "No supplementary groups"
end
end
end
diff --git a/spec/ruby/shared/file/identical.rb b/spec/ruby/shared/file/identical.rb
index e89cd309ea..b7a2904839 100644
--- a/spec/ruby/shared/file/identical.rb
+++ b/spec/ruby/shared/file/identical.rb
@@ -9,7 +9,11 @@ describe :file_identical, shared: true do
touch(@file2) { |f| f.puts "file2" }
rm_r @link
- File.link(@file1, @link)
+ begin
+ File.link(@file1, @link)
+ rescue Errno::EACCES
+ File.symlink(@file1, @link)
+ end
end
after :each do
@@ -31,12 +35,12 @@ describe :file_identical, shared: true do
end
it "raises an ArgumentError if not passed two arguments" do
- lambda { @object.send(@method, @file1, @file2, @link) }.should raise_error(ArgumentError)
- lambda { @object.send(@method, @file1) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, @file1, @file2, @link) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, @file1) }.should raise_error(ArgumentError)
end
it "raises a TypeError if not passed String types" do
- lambda { @object.send(@method, 1,1) }.should raise_error(TypeError)
+ -> { @object.send(@method, 1,1) }.should raise_error(TypeError)
end
it "returns true if both named files are identical" do
diff --git a/spec/ruby/shared/file/readable.rb b/spec/ruby/shared/file/readable.rb
index 74f58caaff..7b45e23e36 100644
--- a/spec/ruby/shared/file/readable.rb
+++ b/spec/ruby/shared/file/readable.rb
@@ -4,9 +4,12 @@ describe :file_readable, shared: true do
platform_is :windows do
@file2 = File.join(ENV["WINDIR"], "system32/drivers/etc/services").tr(File::SEPARATOR, File::ALT_SEPARATOR)
end
- platform_is_not :windows do
+ platform_is_not :windows, :android do
@file2 = "/etc/passwd"
end
+ platform_is :android do
+ @file2 = "/system/bin/sh"
+ end
end
after :each do
@@ -21,6 +24,22 @@ describe :file_readable, shared: true do
it "accepts an object that has a #to_path method" do
@object.send(@method, mock_to_path(@file2)).should == true
end
+
+ platform_is_not :windows do
+ as_superuser do
+ context "when run by a superuser" do
+ it "returns true unconditionally" do
+ file = tmp('temp.txt')
+ touch file
+
+ File.chmod(0333, file)
+ @object.send(@method, file).should == true
+
+ rm_r file
+ end
+ end
+ end
+ end
end
describe :file_readable_missing, shared: true do
diff --git a/spec/ruby/shared/file/readable_real.rb b/spec/ruby/shared/file/readable_real.rb
index b6e53ac76d..32d38bc7a2 100644
--- a/spec/ruby/shared/file/readable_real.rb
+++ b/spec/ruby/shared/file/readable_real.rb
@@ -14,6 +14,22 @@ describe :file_readable_real, shared: true do
it "accepts an object that has a #to_path method" do
File.open(@file,'w') { @object.send(@method, mock_to_path(@file)).should == true }
end
+
+ platform_is_not :windows do
+ as_real_superuser do
+ context "when run by a real superuser" do
+ it "returns true unconditionally" do
+ file = tmp('temp.txt')
+ touch file
+
+ File.chmod(0333, file)
+ @object.send(@method, file).should == true
+
+ rm_r file
+ end
+ end
+ end
+ end
end
describe :file_readable_real_missing, shared: true do
diff --git a/spec/ruby/shared/file/size.rb b/spec/ruby/shared/file/size.rb
index bb95190fc0..880dfbb612 100644
--- a/spec/ruby/shared/file/size.rb
+++ b/spec/ruby/shared/file/size.rb
@@ -56,7 +56,7 @@ describe :file_size_raise_when_missing, shared: true do
end
it "raises an error if file_name doesn't exist" do
- lambda {@object.send(@method, @missing)}.should raise_error(Errno::ENOENT)
+ -> {@object.send(@method, @missing)}.should raise_error(Errno::ENOENT)
end
end
diff --git a/spec/ruby/shared/file/world_readable.rb b/spec/ruby/shared/file/world_readable.rb
index 0fd5a28397..1dce7a580f 100644
--- a/spec/ruby/shared/file/world_readable.rb
+++ b/spec/ruby/shared/file/world_readable.rb
@@ -28,18 +28,18 @@ describe :file_world_readable, shared: true do
end
end
- # We don't specify what the Fixnum is because it's system dependent
- it "returns a Fixnum if the file is chmod 644" do
+ # We don't specify what the Integer is because it's system dependent
+ it "returns an Integer if the file is chmod 644" do
File.chmod(0644, @file)
- @object.world_readable?(@file).should be_an_instance_of(Fixnum)
+ @object.world_readable?(@file).should be_an_instance_of(Integer)
end
- it "returns a Fixnum if the file is a directory and chmod 644" do
- dir = rand().to_s + '-ww'
+ it "returns an Integer if the file is a directory and chmod 644" do
+ dir = tmp(rand().to_s + '-ww')
Dir.mkdir(dir)
- Dir.exist?(dir).should be_true
+ Dir.should.exist?(dir)
File.chmod(0644, dir)
- @object.world_readable?(dir).should be_an_instance_of(Fixnum)
+ @object.world_readable?(dir).should be_an_instance_of(Integer)
Dir.rmdir(dir)
end
diff --git a/spec/ruby/shared/file/world_writable.rb b/spec/ruby/shared/file/world_writable.rb
index da8af0bc2a..7ed252dcf3 100644
--- a/spec/ruby/shared/file/world_writable.rb
+++ b/spec/ruby/shared/file/world_writable.rb
@@ -27,18 +27,18 @@ describe :file_world_writable, shared: true do
@object.world_writable?(@file).should be_nil
end
- # We don't specify what the Fixnum is because it's system dependent
- it "returns a Fixnum if the file is chmod 777" do
+ # We don't specify what the Integer is because it's system dependent
+ it "returns an Integer if the file is chmod 777" do
File.chmod(0777, @file)
- @object.world_writable?(@file).should be_an_instance_of(Fixnum)
+ @object.world_writable?(@file).should be_an_instance_of(Integer)
end
- it "returns a Fixnum if the file is a directory and chmod 777" do
- dir = rand().to_s + '-ww'
+ it "returns an Integer if the file is a directory and chmod 777" do
+ dir = tmp(rand().to_s + '-ww')
Dir.mkdir(dir)
- Dir.exist?(dir).should be_true
+ Dir.should.exist?(dir)
File.chmod(0777, dir)
- @object.world_writable?(dir).should be_an_instance_of(Fixnum)
+ @object.world_writable?(dir).should be_an_instance_of(Integer)
Dir.rmdir(dir)
end
end
diff --git a/spec/ruby/shared/file/writable.rb b/spec/ruby/shared/file/writable.rb
index 902d545da1..65ea2c1781 100644
--- a/spec/ruby/shared/file/writable.rb
+++ b/spec/ruby/shared/file/writable.rb
@@ -8,7 +8,7 @@ describe :file_writable, shared: true do
end
it "returns true if named file is writable by the effective user id of the process, otherwise false" do
- platform_is_not :windows do
+ platform_is_not :windows, :android do
as_user do
@object.send(@method, "/etc/passwd").should == false
end
@@ -19,6 +19,22 @@ describe :file_writable, shared: true do
it "accepts an object that has a #to_path method" do
File.open(@file,'w') { @object.send(@method, mock_to_path(@file)).should == true }
end
+
+ platform_is_not :windows do
+ as_superuser do
+ context "when run by a superuser" do
+ it "returns true unconditionally" do
+ file = tmp('temp.txt')
+ touch file
+
+ File.chmod(0555, file)
+ @object.send(@method, file).should == true
+
+ rm_r file
+ end
+ end
+ end
+ end
end
describe :file_writable_missing, shared: true do
diff --git a/spec/ruby/shared/file/writable_real.rb b/spec/ruby/shared/file/writable_real.rb
index 3730befb7a..b4a0a58c6e 100644
--- a/spec/ruby/shared/file/writable_real.rb
+++ b/spec/ruby/shared/file/writable_real.rb
@@ -16,13 +16,29 @@ describe :file_writable_real, shared: true do
end
it "raises an ArgumentError if not passed one argument" do
- lambda { File.writable_real? }.should raise_error(ArgumentError)
+ -> { File.writable_real? }.should raise_error(ArgumentError)
end
it "raises a TypeError if not passed a String type" do
- lambda { @object.send(@method, 1) }.should raise_error(TypeError)
- lambda { @object.send(@method, nil) }.should raise_error(TypeError)
- lambda { @object.send(@method, false) }.should raise_error(TypeError)
+ -> { @object.send(@method, 1) }.should raise_error(TypeError)
+ -> { @object.send(@method, nil) }.should raise_error(TypeError)
+ -> { @object.send(@method, false) }.should raise_error(TypeError)
+ end
+
+ platform_is_not :windows do
+ as_real_superuser do
+ context "when run by a real superuser" do
+ it "returns true unconditionally" do
+ file = tmp('temp.txt')
+ touch file
+
+ File.chmod(0555, file)
+ @object.send(@method, file).should == true
+
+ rm_r file
+ end
+ end
+ end
end
end
diff --git a/spec/ruby/shared/file/zero.rb b/spec/ruby/shared/file/zero.rb
index cf014d4722..6a9399a021 100644
--- a/spec/ruby/shared/file/zero.rb
+++ b/spec/ruby/shared/file/zero.rb
@@ -40,13 +40,13 @@ describe :file_zero, shared: true do
end
it "raises an ArgumentError if not passed one argument" do
- lambda { File.zero? }.should raise_error(ArgumentError)
+ -> { File.zero? }.should raise_error(ArgumentError)
end
it "raises a TypeError if not passed a String type" do
- lambda { @object.send(@method, nil) }.should raise_error(TypeError)
- lambda { @object.send(@method, true) }.should raise_error(TypeError)
- lambda { @object.send(@method, false) }.should raise_error(TypeError)
+ -> { @object.send(@method, nil) }.should raise_error(TypeError)
+ -> { @object.send(@method, true) }.should raise_error(TypeError)
+ -> { @object.send(@method, false) }.should raise_error(TypeError)
end
it "returns true inside a block opening a file if it is empty" do
diff --git a/spec/ruby/shared/hash/key_error.rb b/spec/ruby/shared/hash/key_error.rb
index 061c88c483..54dcb89e91 100644
--- a/spec/ruby/shared/hash/key_error.rb
+++ b/spec/ruby/shared/hash/key_error.rb
@@ -5,21 +5,19 @@ describe :key_error, shared: true do
}.should raise_error(KeyError)
end
- ruby_version_is "2.5" do
- it "sets the Hash as the receiver of KeyError" do
- -> {
- @method.call(@object, 'foo')
- }.should raise_error(KeyError) { |err|
- err.receiver.should equal(@object)
- }
- end
+ it "sets the Hash as the receiver of KeyError" do
+ -> {
+ @method.call(@object, 'foo')
+ }.should raise_error(KeyError) { |err|
+ err.receiver.should equal(@object)
+ }
+ end
- it "sets the unmatched key as the key of KeyError" do
- -> {
- @method.call(@object, 'foo')
- }.should raise_error(KeyError) { |err|
- err.key.to_s.should == 'foo'
- }
- end
+ it "sets the unmatched key as the key of KeyError" do
+ -> {
+ @method.call(@object, 'foo')
+ }.should raise_error(KeyError) { |err|
+ err.key.to_s.should == 'foo'
+ }
end
end
diff --git a/spec/ruby/shared/io/putc.rb b/spec/ruby/shared/io/putc.rb
index 5f620f183f..e6012c0098 100644
--- a/spec/ruby/shared/io/putc.rb
+++ b/spec/ruby/shared/io/putc.rb
@@ -1,4 +1,4 @@
-# -*- encoding: ascii-8bit -*-
+# -*- encoding: binary -*-
describe :io_putc, shared: true do
after :each do
@io.close if @io && !@io.closed?
@@ -6,7 +6,7 @@ describe :io_putc, shared: true do
rm_r @name
end
- describe "with a Fixnum argument" do
+ describe "with an Integer argument" do
it "writes one character as a String" do
@io.should_receive(:write).with("A")
@io_object.send(@method, 65).should == 65
@@ -40,18 +40,18 @@ describe :io_putc, shared: true do
it "raises IOError on a closed stream" do
@io.close
- lambda { @io_object.send(@method, "a") }.should raise_error(IOError)
+ -> { @io_object.send(@method, "a") }.should raise_error(IOError)
end
it "raises a TypeError when passed nil" do
- lambda { @io_object.send(@method, nil) }.should raise_error(TypeError)
+ -> { @io_object.send(@method, nil) }.should raise_error(TypeError)
end
it "raises a TypeError when passed false" do
- lambda { @io_object.send(@method, false) }.should raise_error(TypeError)
+ -> { @io_object.send(@method, false) }.should raise_error(TypeError)
end
it "raises a TypeError when passed true" do
- lambda { @io_object.send(@method, true) }.should raise_error(TypeError)
+ -> { @io_object.send(@method, true) }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/shared/kernel/complex.rb b/spec/ruby/shared/kernel/complex.rb
new file mode 100644
index 0000000000..98ee0b2b3f
--- /dev/null
+++ b/spec/ruby/shared/kernel/complex.rb
@@ -0,0 +1,133 @@
+# Specs shared by Kernel#Complex() and String#to_c()
+describe :kernel_complex, shared: true do
+
+ it "returns a Complex object" do
+ @object.send(@method, '9').should be_an_instance_of(Complex)
+ end
+
+ it "understands integers" do
+ @object.send(@method, '20').should == Complex(20)
+ end
+
+ it "understands negative integers" do
+ @object.send(@method, '-3').should == Complex(-3)
+ end
+
+ it "understands fractions (numerator/denominator) for the real part" do
+ @object.send(@method, '2/3').should == Complex(Rational(2, 3))
+ end
+
+ it "understands fractions (numerator/denominator) for the imaginary part" do
+ @object.send(@method, '4+2/3i').should == Complex(4, Rational(2, 3))
+ end
+
+ it "understands negative fractions (-numerator/denominator) for the real part" do
+ @object.send(@method, '-2/3').should == Complex(Rational(-2, 3))
+ end
+
+ it "understands negative fractions (-numerator/denominator) for the imaginary part" do
+ @object.send(@method, '7-2/3i').should == Complex(7, Rational(-2, 3))
+ end
+
+ it "understands floats (a.b) for the real part" do
+ @object.send(@method, '2.3').should == Complex(2.3)
+ end
+
+ it "understands floats (a.b) for the imaginary part" do
+ @object.send(@method, '4+2.3i').should == Complex(4, 2.3)
+ end
+
+ it "understands negative floats (-a.b) for the real part" do
+ @object.send(@method, '-2.33').should == Complex(-2.33)
+ end
+
+ it "understands negative floats (-a.b) for the imaginary part" do
+ @object.send(@method, '7-28.771i').should == Complex(7, -28.771)
+ end
+
+ it "understands an integer followed by 'i' to mean that integer is the imaginary part" do
+ @object.send(@method, '35i').should == Complex(0,35)
+ end
+
+ it "understands a negative integer followed by 'i' to mean that negative integer is the imaginary part" do
+ @object.send(@method, '-29i').should == Complex(0,-29)
+ end
+
+ it "understands an 'i' by itself as denoting a complex number with an imaginary part of 1" do
+ @object.send(@method, 'i').should == Complex(0,1)
+ end
+
+ it "understands a '-i' by itself as denoting a complex number with an imaginary part of -1" do
+ @object.send(@method, '-i').should == Complex(0,-1)
+ end
+
+ it "understands 'a+bi' to mean a complex number with 'a' as the real part, 'b' as the imaginary" do
+ @object.send(@method, '79+4i').should == Complex(79,4)
+ end
+
+ it "understands 'a-bi' to mean a complex number with 'a' as the real part, '-b' as the imaginary" do
+ @object.send(@method, '79-4i').should == Complex(79,-4)
+ end
+
+ it "understands 'a+i' to mean a complex number with 'a' as the real part, 1i as the imaginary" do
+ @object.send(@method, '79+i').should == Complex(79, 1)
+ end
+
+ it "understands 'a-i' to mean a complex number with 'a' as the real part, -1i as the imaginary" do
+ @object.send(@method, '79-i').should == Complex(79, -1)
+ end
+
+ it "understands i, I, j, and J imaginary units" do
+ @object.send(@method, '79+4i').should == Complex(79, 4)
+ @object.send(@method, '79+4I').should == Complex(79, 4)
+ @object.send(@method, '79+4j').should == Complex(79, 4)
+ @object.send(@method, '79+4J').should == Complex(79, 4)
+ end
+
+ it "understands scientific notation for the real part" do
+ @object.send(@method, '2e3+4i').should == Complex(2e3,4)
+ end
+
+ it "understands negative scientific notation for the real part" do
+ @object.send(@method, '-2e3+4i').should == Complex(-2e3,4)
+ end
+
+ it "understands scientific notation for the imaginary part" do
+ @object.send(@method, '4+2e3i').should == Complex(4, 2e3)
+ end
+
+ it "understands negative scientific notation for the imaginary part" do
+ @object.send(@method, '4-2e3i').should == Complex(4, -2e3)
+ end
+
+ it "understands scientific notation for the real and imaginary part in the same String" do
+ @object.send(@method, '2e3+2e4i').should == Complex(2e3,2e4)
+ end
+
+ it "understands negative scientific notation for the real and imaginary part in the same String" do
+ @object.send(@method, '-2e3-2e4i').should == Complex(-2e3,-2e4)
+ end
+
+ it "understands scientific notation with e and E" do
+ @object.send(@method, '2e3+2e4i').should == Complex(2e3, 2e4)
+ @object.send(@method, '2E3+2E4i').should == Complex(2e3, 2e4)
+ end
+
+ it "understands 'm@a' to mean a complex number in polar form with 'm' as the modulus, 'a' as the argument" do
+ @object.send(@method, '79@4').should == Complex.polar(79, 4)
+ @object.send(@method, '-79@4').should == Complex.polar(-79, 4)
+ @object.send(@method, '79@-4').should == Complex.polar(79, -4)
+ end
+
+ it "ignores leading whitespaces" do
+ @object.send(@method, ' 79+4i').should == Complex(79, 4)
+ end
+
+ it "ignores trailing whitespaces" do
+ @object.send(@method, '79+4i ').should == Complex(79, 4)
+ end
+
+ it "understands _" do
+ @object.send(@method, '7_9+4_0i').should == Complex(79, 40)
+ end
+end
diff --git a/spec/ruby/shared/kernel/raise.rb b/spec/ruby/shared/kernel/raise.rb
index 7b9a29ca3f..82fb0333c8 100644
--- a/spec/ruby/shared/kernel/raise.rb
+++ b/spec/ruby/shared/kernel/raise.rb
@@ -4,7 +4,7 @@ describe :kernel_raise, shared: true do
end
it "aborts execution" do
- lambda do
+ -> do
@object.raise Exception, "abort"
ScratchPad.record :no_abort
end.should raise_error(Exception, "abort")
@@ -12,73 +12,137 @@ describe :kernel_raise, shared: true do
ScratchPad.recorded.should be_nil
end
+ it "accepts an exception that implements to_hash" do
+ custom_error = Class.new(StandardError) do
+ def to_hash
+ {}
+ end
+ end
+ error = custom_error.new
+ -> { @object.raise(error) }.should raise_error(custom_error)
+ end
+
+ it "allows the message parameter to be a hash" do
+ data_error = Class.new(StandardError) do
+ attr_reader :data
+ def initialize(data)
+ @data = data
+ end
+ end
+
+ -> { @object.raise(data_error, {data: 42}) }.should raise_error(data_error) do |ex|
+ ex.data.should == {data: 42}
+ end
+ end
+
+ # https://bugs.ruby-lang.org/issues/8257#note-36
+ it "allows extra keyword arguments for compatibility" do
+ data_error = Class.new(StandardError) do
+ attr_reader :data
+ def initialize(data)
+ @data = data
+ end
+ end
+
+ -> { @object.raise(data_error, data: 42) }.should raise_error(data_error) do |ex|
+ ex.data.should == {data: 42}
+ end
+ end
+
+ it "does not allow message and extra keyword arguments" do
+ data_error = Class.new(StandardError) do
+ attr_reader :data
+ def initialize(data)
+ @data = data
+ end
+ end
+
+ -> { @object.raise(data_error, {a: 1}, b: 2) }.should raise_error(StandardError) do |e|
+ [TypeError, ArgumentError].should.include?(e.class)
+ end
+
+ -> { @object.raise(data_error, {a: 1}, [], b: 2) }.should raise_error(ArgumentError)
+ end
+
it "raises RuntimeError if no exception class is given" do
- lambda { @object.raise }.should raise_error(RuntimeError, "")
+ -> { @object.raise }.should raise_error(RuntimeError, "")
end
it "raises a given Exception instance" do
error = RuntimeError.new
- lambda { @object.raise(error) }.should raise_error(error)
+ -> { @object.raise(error) }.should raise_error(error)
end
it "raises a RuntimeError if string given" do
- lambda { @object.raise("a bad thing") }.should raise_error(RuntimeError)
+ -> { @object.raise("a bad thing") }.should raise_error(RuntimeError)
+ end
+
+ it "passes no arguments to the constructor when given only an exception class" do
+ klass = Class.new(Exception) do
+ def initialize
+ end
+ end
+ -> { @object.raise(klass) }.should raise_error(klass) { |e| e.message.should == klass.to_s }
end
it "raises a TypeError when passed a non-Exception object" do
- lambda { @object.raise(Object.new) }.should raise_error(TypeError)
+ -> { @object.raise(Object.new) }.should raise_error(TypeError)
end
it "raises a TypeError when passed true" do
- lambda { @object.raise(true) }.should raise_error(TypeError)
+ -> { @object.raise(true) }.should raise_error(TypeError)
end
it "raises a TypeError when passed false" do
- lambda { @object.raise(false) }.should raise_error(TypeError)
+ -> { @object.raise(false) }.should raise_error(TypeError)
end
it "raises a TypeError when passed nil" do
- lambda { @object.raise(nil) }.should raise_error(TypeError)
+ -> { @object.raise(nil) }.should raise_error(TypeError)
end
- it "re-raises the previously rescued exception if no exception is specified" do
- lambda do
- begin
- @object.raise Exception, "outer"
- ScratchPad.record :no_abort
- rescue
+ it "re-raises a previously rescued exception without overwriting the backtrace" do
+ # This spec is written using #backtrace and matching the line number
+ # from the string, as backtrace_locations is a more advanced
+ # method that is not always supported by implementations.
+ #
+ initial_raise_line = nil
+ raise_again_line = nil
+ raised_again = nil
+
+ if defined?(FiberSpecs::NewFiberToRaise) and @object == FiberSpecs::NewFiberToRaise
+ fiber = Fiber.new do
begin
- @object.raise StandardError, "inner"
- rescue
+ initial_raise_line = __LINE__; Fiber.yield
+ rescue => raised
+ begin
+ raise_again_line = __LINE__; Fiber.yield raised
+ rescue => raised_again
+ raised_again
+ end
end
-
- @object.raise
- ScratchPad.record :no_reraise
end
- end.should raise_error(Exception, "outer")
-
- ScratchPad.recorded.should be_nil
- end
-
- it "re-raises a previously rescued exception without overwriting the backtrace" do
- begin
- initial_raise_line = __LINE__; @object.raise 'raised'
- rescue => raised
+ fiber.resume
+ raised = fiber.raise 'raised'
+ raised_again = fiber.raise raised
+ else
begin
- raise_again_line = __LINE__; @object.raise raised
- rescue => raised_again
- # This spec is written using #backtrace and matching the line number
- # from the string, as backtrace_locations is a more advanced
- # method that is not always supported by implementations.
-
- raised_again.backtrace.first.should include("#{__FILE__}:#{initial_raise_line}:")
- raised_again.backtrace.first.should_not include("#{__FILE__}:#{raise_again_line}:")
+ initial_raise_line = __LINE__; @object.raise 'raised'
+ rescue => raised
+ begin
+ raise_again_line = __LINE__; @object.raise raised
+ rescue => raised_again
+ raised_again
+ end
end
end
+
+ raised_again.backtrace.first.should include("#{__FILE__}:#{initial_raise_line}:")
+ raised_again.backtrace.first.should_not include("#{__FILE__}:#{raise_again_line}:")
end
it "allows Exception, message, and backtrace parameters" do
- lambda do
+ -> do
@object.raise(ArgumentError, "message", caller)
end.should raise_error(ArgumentError, "message")
end
diff --git a/spec/ruby/shared/math/atanh.rb b/spec/ruby/shared/math/atanh.rb
index 1d1a6ebd74..3fb64153a0 100644
--- a/spec/ruby/shared/math/atanh.rb
+++ b/spec/ruby/shared/math/atanh.rb
@@ -11,11 +11,11 @@ describe :math_atanh_base, shared: true do
end
it "raises a TypeError if the argument is nil" do
- lambda { @object.send(@method, nil) }.should raise_error(TypeError)
+ -> { @object.send(@method, nil) }.should raise_error(TypeError)
end
it "raises a TypeError if the argument is not a Numeric" do
- lambda { @object.send(@method, "test") }.should raise_error(TypeError)
+ -> { @object.send(@method, "test") }.should raise_error(TypeError)
end
it "returns Infinity if x == 1.0" do
@@ -35,10 +35,10 @@ end
describe :math_atanh_no_complex, shared: true do
it "raises a Math::DomainError for arguments greater than 1.0" do
- lambda { @object.send(@method, 1.0 + Float::EPSILON) }.should raise_error(Math::DomainError)
+ -> { @object.send(@method, 1.0 + Float::EPSILON) }.should raise_error(Math::DomainError)
end
it "raises a Math::DomainError for arguments less than -1.0" do
- lambda { @object.send(@method, -1.0 - Float::EPSILON) }.should raise_error(Math::DomainError)
+ -> { @object.send(@method, -1.0 - Float::EPSILON) }.should raise_error(Math::DomainError)
end
end
diff --git a/spec/ruby/shared/process/abort.rb b/spec/ruby/shared/process/abort.rb
index 1a25aeffc2..935637e1c2 100644
--- a/spec/ruby/shared/process/abort.rb
+++ b/spec/ruby/shared/process/abort.rb
@@ -8,29 +8,29 @@ describe :process_abort, shared: true do
end
it "raises a SystemExit exception" do
- lambda { @object.abort }.should raise_error(SystemExit)
+ -> { @object.abort }.should raise_error(SystemExit)
end
it "sets the exception message to the given message" do
- lambda { @object.abort "message" }.should raise_error { |e| e.message.should == "message" }
+ -> { @object.abort "message" }.should raise_error { |e| e.message.should == "message" }
end
it "sets the exception status code of 1" do
- lambda { @object.abort }.should raise_error { |e| e.status.should == 1 }
+ -> { @object.abort }.should raise_error { |e| e.status.should == 1 }
end
it "prints the specified message to STDERR" do
- lambda { @object.abort "a message" }.should raise_error(SystemExit)
+ -> { @object.abort "a message" }.should raise_error(SystemExit)
$stderr.should =~ /a message/
end
it "coerces the argument with #to_str" do
str = mock('to_str')
str.should_receive(:to_str).any_number_of_times.and_return("message")
- lambda { @object.abort str }.should raise_error(SystemExit, "message")
+ -> { @object.abort str }.should raise_error(SystemExit, "message")
end
it "raises TypeError when given a non-String object" do
- lambda { @object.abort 123 }.should raise_error(TypeError)
+ -> { @object.abort 123 }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/shared/process/exit.rb b/spec/ruby/shared/process/exit.rb
index 7d567c8195..7d901f1f1e 100644
--- a/spec/ruby/shared/process/exit.rb
+++ b/spec/ruby/shared/process/exit.rb
@@ -1,13 +1,13 @@
describe :process_exit, shared: true do
it "raises a SystemExit with status 0" do
- lambda { @object.exit }.should raise_error(SystemExit) { |e|
+ -> { @object.exit }.should raise_error(SystemExit) { |e|
e.status.should == 0
}
end
it "raises a SystemExit with the specified status" do
[-2**16, -2**8, -8, -1, 0, 1 , 8, 2**8, 2**16].each do |value|
- lambda { @object.exit(value) }.should raise_error(SystemExit) { |e|
+ -> { @object.exit(value) }.should raise_error(SystemExit) { |e|
e.status.should == value
}
end
@@ -15,33 +15,39 @@ describe :process_exit, shared: true do
it "raises a SystemExit with the specified boolean status" do
{ true => 0, false => 1 }.each do |value, status|
- lambda { @object.exit(value) }.should raise_error(SystemExit) { |e|
+ -> { @object.exit(value) }.should raise_error(SystemExit) { |e|
e.status.should == status
}
end
end
+ it "raises a SystemExit with message 'exit'" do
+ -> { @object.exit }.should raise_error(SystemExit) { |e|
+ e.message.should == "exit"
+ }
+ end
+
it "tries to convert the passed argument to an Integer using #to_int" do
obj = mock('5')
obj.should_receive(:to_int).and_return(5)
- lambda { @object.exit(obj) }.should raise_error(SystemExit) { |e|
+ -> { @object.exit(obj) }.should raise_error(SystemExit) { |e|
e.status.should == 5
}
end
it "converts the passed Float argument to an Integer" do
{ -2.2 => -2, -0.1 => 0, 5.5 => 5, 827.999 => 827 }.each do |value, status|
- lambda { @object.exit(value) }.should raise_error(SystemExit) { |e|
+ -> { @object.exit(value) }.should raise_error(SystemExit) { |e|
e.status.should == status
}
end
end
it "raises TypeError if can't convert the argument to an Integer" do
- lambda { @object.exit(Object.new) }.should raise_error(TypeError)
- lambda { @object.exit('0') }.should raise_error(TypeError)
- lambda { @object.exit([0]) }.should raise_error(TypeError)
- lambda { @object.exit(nil) }.should raise_error(TypeError)
+ -> { @object.exit(Object.new) }.should raise_error(TypeError)
+ -> { @object.exit('0') }.should raise_error(TypeError)
+ -> { @object.exit([0]) }.should raise_error(TypeError)
+ -> { @object.exit(nil) }.should raise_error(TypeError)
end
it "raises the SystemExit in the main thread if it reaches the top-level handler of another thread" do
@@ -69,26 +75,46 @@ describe :process_exit, shared: true do
ScratchPad.recorded.should == [:in_thread, :in_main]
# the thread also keeps the exception as its value
- lambda { t.value }.should raise_error(SystemExit)
+ -> { t.value }.should raise_error(SystemExit)
end
end
describe :process_exit!, shared: true do
it "exits with the given status" do
- out = ruby_exe("#{@object}.send(:exit!, 21)", args: '2>&1')
+ out = ruby_exe("#{@object}.send(:exit!, 21)", args: '2>&1', exit_status: 21)
out.should == ""
$?.exitstatus.should == 21
end
it "exits when called from a thread" do
- out = ruby_exe("Thread.new { #{@object}.send(:exit!, 21) }.join; sleep", args: '2>&1')
+ out = ruby_exe("Thread.new { #{@object}.send(:exit!, 21) }.join; sleep", args: '2>&1', exit_status: 21)
out.should == ""
$?.exitstatus.should == 21
end
it "exits when called from a fiber" do
- out = ruby_exe("Fiber.new { #{@object}.send(:exit!, 21) }.resume", args: '2>&1')
+ out = ruby_exe("Fiber.new { #{@object}.send(:exit!, 21) }.resume", args: '2>&1', exit_status: 21)
out.should == ""
$?.exitstatus.should == 21
end
+
+ it "skips at_exit handlers" do
+ out = ruby_exe("at_exit { STDERR.puts 'at_exit' }; #{@object}.send(:exit!, 21)", args: '2>&1', exit_status: 21)
+ out.should == ""
+ $?.exitstatus.should == 21
+ end
+
+ it "overrides the original exception and exit status when called from #at_exit" do
+ code = <<-RUBY
+ at_exit do
+ STDERR.puts 'in at_exit'
+ STDERR.puts "$! is \#{$!.class}:\#{$!.message}"
+ #{@object}.send(:exit!, 21)
+ end
+ raise 'original error'
+ RUBY
+ out = ruby_exe(code, args: '2>&1', exit_status: 21)
+ out.should == "in at_exit\n$! is RuntimeError:original error\n"
+ $?.exitstatus.should == 21
+ end
end
diff --git a/spec/ruby/shared/process/fork.rb b/spec/ruby/shared/process/fork.rb
index c2c2aee9bf..11e18d7b1c 100644
--- a/spec/ruby/shared/process/fork.rb
+++ b/spec/ruby/shared/process/fork.rb
@@ -8,7 +8,7 @@ describe :process_fork, shared: true do
end
it "raises a NotImplementedError when called" do
- lambda { @object.fork }.should raise_error(NotImplementedError)
+ -> { @object.fork }.should raise_error(NotImplementedError)
end
end
@@ -60,7 +60,7 @@ describe :process_fork, shared: true do
else
Process.waitpid(child_id)
end
- File.exist?(@file).should == true
+ File.should.exist?(@file)
end
it "runs a block in a child process" do
@@ -69,7 +69,7 @@ describe :process_fork, shared: true do
Process.exit!
}
Process.waitpid(pid)
- File.exist?(@file).should == true
+ File.should.exist?(@file)
end
it "marks threads from the parent as killed" do
diff --git a/spec/ruby/shared/queue/deque.rb b/spec/ruby/shared/queue/deque.rb
index 3590f367ba..616e56ec8a 100644
--- a/spec/ruby/shared/queue/deque.rb
+++ b/spec/ruby/shared/queue/deque.rb
@@ -55,6 +55,68 @@ describe :queue_deq, shared: true do
t.join
end
+ describe "with a timeout" do
+ ruby_version_is "3.2" do
+ it "returns an item if one is available in time" do
+ q = @object.call
+
+ t = Thread.new {
+ q.send(@method, timeout: 1).should == 1
+ }
+ Thread.pass until t.status == "sleep" && q.num_waiting == 1
+ q << 1
+ t.join
+ end
+
+ 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
+ end
+
+ it "does nothing if the timeout is nil" do
+ q = @object.call
+ t = Thread.new {
+ q.send(@method, timeout: nil).should == 1
+ }
+ t.join(0.2).should == nil
+ q << 1
+ t.join
+ end
+
+ it "immediately returns nil if no item is available and the timeout is 0" do
+ q = @object.call
+ q << 1
+ q.send(@method, timeout: 0).should == 1
+ q.send(@method, timeout: 0).should == nil
+ end
+
+ 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",
+ )
+ 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",
+ )
+ end
+ end
+ end
+
describe "in non-blocking mode" do
it "removes an item from the queue" do
q = @object.call
@@ -66,7 +128,7 @@ describe :queue_deq, shared: true do
it "raises a ThreadError if the queue is empty" do
q = @object.call
- lambda { q.send(@method, true) }.should raise_error(ThreadError)
+ -> { q.send(@method, true) }.should raise_error(ThreadError)
end
it "removes an item from a closed queue" do
@@ -79,7 +141,7 @@ describe :queue_deq, shared: true do
it "raises a ThreadError for a closed empty queue" do
q = @object.call
q.close
- lambda { q.send(@method, true) }.should raise_error(ThreadError)
+ -> { q.send(@method, true) }.should raise_error(ThreadError)
end
end
end
diff --git a/spec/ruby/shared/queue/enque.rb b/spec/ruby/shared/queue/enque.rb
index ad413e1f46..8aba02e544 100644
--- a/spec/ruby/shared/queue/enque.rb
+++ b/spec/ruby/shared/queue/enque.rb
@@ -11,7 +11,7 @@ describe :queue_enq, shared: true do
it "is an error for a closed queue" do
q = @object.call
q.close
- lambda {
+ -> {
q.send @method, Object.new
}.should raise_error(ClosedQueueError)
end
diff --git a/spec/ruby/shared/rational/Rational.rb b/spec/ruby/shared/rational/Rational.rb
index 30425775d6..2dc49c869c 100644
--- a/spec/ruby/shared/rational/Rational.rb
+++ b/spec/ruby/shared/rational/Rational.rb
@@ -65,80 +65,76 @@ describe :kernel_Rational, shared: true do
r_s.should == r
r_s.should_not == f_r
end
+ end
- describe "when passed a Numeric" do
- it "calls #to_r to convert the first argument to a Rational" do
- num = RationalSpecs::SubNumeric.new(2)
+ describe "when passed a Numeric" do
+ it "calls #to_r to convert the first argument to a Rational" do
+ num = RationalSpecs::SubNumeric.new(2)
- Rational(num).should == Rational(2)
- end
+ Rational(num).should == Rational(2)
end
+ end
- describe "when passed a Complex" do
- it "returns a Rational from the real part if the imaginary part is 0" do
- Rational(Complex(1, 0)).should == Rational(1)
- end
-
- it "raises a RangeError if the imaginary part is not 0" do
- lambda { Rational(Complex(1, 2)) }.should raise_error(RangeError)
- end
+ describe "when passed a Complex" do
+ it "returns a Rational from the real part if the imaginary part is 0" do
+ Rational(Complex(1, 0)).should == Rational(1)
end
- it "raises a TypeError if the first argument is nil" do
- lambda { Rational(nil) }.should raise_error(TypeError)
+ it "raises a RangeError if the imaginary part is not 0" do
+ -> { Rational(Complex(1, 2)) }.should raise_error(RangeError)
end
+ end
- it "raises a TypeError if the second argument is nil" do
- lambda { Rational(1, nil) }.should raise_error(TypeError)
- end
+ it "raises a TypeError if the first argument is nil" do
+ -> { Rational(nil) }.should raise_error(TypeError)
+ end
- it "raises a TypeError if the first argument is a Symbol" do
- lambda { Rational(:sym) }.should raise_error(TypeError)
- end
+ it "raises a TypeError if the second argument is nil" do
+ -> { Rational(1, nil) }.should raise_error(TypeError)
+ end
- it "raises a TypeError if the second argument is a Symbol" do
- lambda { Rational(1, :sym) }.should raise_error(TypeError)
- end
+ it "raises a TypeError if the first argument is a Symbol" do
+ -> { Rational(:sym) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError if the second argument is a Symbol" do
+ -> { Rational(1, :sym) }.should raise_error(TypeError)
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
+ 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
+ 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
+ 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
+ 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
+ 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
diff --git a/spec/ruby/shared/rational/arithmetic_exception_in_coerce.rb b/spec/ruby/shared/rational/arithmetic_exception_in_coerce.rb
index 9377814732..0dff91d522 100644
--- a/spec/ruby/shared/rational/arithmetic_exception_in_coerce.rb
+++ b/spec/ruby/shared/rational/arithmetic_exception_in_coerce.rb
@@ -1,33 +1,11 @@
require_relative '../../fixtures/rational'
describe :rational_arithmetic_exception_in_coerce, shared: true do
- ruby_version_is ""..."2.5" do
- it "rescues exception (StandardError and subclasses) raised in other#coerce and raises TypeError" do
- b = mock("numeric with failed #coerce")
- b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError)
+ it "does not rescue exception raised in other#coerce" do
+ b = mock("numeric with failed #coerce")
+ b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError)
- # e.g. Rational(3, 4) + b
- -> { Rational(3, 4).send(@method, b) }.should raise_error(TypeError, /MockObject can't be coerced into Rational/)
- end
-
- it "does not rescue Exception and StandardError siblings raised in other#coerce" do
- [Exception, NoMemoryError].each do |exception|
- b = mock("numeric with failed #coerce")
- b.should_receive(:coerce).and_raise(exception)
-
- # e.g. Rational(3, 4) + b
- -> { Rational(3, 4).send(@method, b) }.should raise_error(exception)
- end
- end
- end
-
- ruby_version_is "2.5" do
- it "does not rescue exception raised in other#coerce" do
- b = mock("numeric with failed #coerce")
- b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError)
-
- # e.g. Rational(3, 4) + b
- -> { Rational(3, 4).send(@method, b) }.should raise_error(RationalSpecs::CoerceError)
- end
+ # e.g. Rational(3, 4) + b
+ -> { Rational(3, 4).send(@method, b) }.should raise_error(RationalSpecs::CoerceError)
end
end
diff --git a/spec/ruby/shared/rational/coerce.rb b/spec/ruby/shared/rational/coerce.rb
index 0d6c440993..ccc8901ba0 100644
--- a/spec/ruby/shared/rational/coerce.rb
+++ b/spec/ruby/shared/rational/coerce.rb
@@ -1,5 +1,7 @@
require_relative '../../spec_helper'
+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)
@@ -15,7 +17,18 @@ describe :rational_coerce, shared: true do
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 "returns [argument, self] when given a Rational" do
Rational(3, 7).coerce(Rational(9, 2)).should == [Rational(9, 2), Rational(3, 7)]
end
+
+ it "raises an error when passed a BigDecimal" do
+ -> {
+ Rational(500, 3).coerce(BigDecimal('166.666666666'))
+ }.should raise_error(TypeError, /BigDecimal can't be coerced into Rational/)
+ end
end
diff --git a/spec/ruby/shared/rational/comparison.rb b/spec/ruby/shared/rational/comparison.rb
index 0c8b3d0ac1..860462f579 100644
--- a/spec/ruby/shared/rational/comparison.rb
+++ b/spec/ruby/shared/rational/comparison.rb
@@ -80,33 +80,11 @@ describe :rational_cmp_coerce, shared: true do
end
describe :rational_cmp_coerce_exception, shared: true do
- ruby_version_is ""..."2.5" do
- it "rescues exception (StandardError and subclasses) raised in other#coerce and returns nil" do
- b = mock("numeric with failed #coerce")
- b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError)
-
- -> {
- (Rational(3, 4) <=> b).should == nil
- }.should complain(/Numerical comparison operators will no more rescue exceptions of #coerce/)
- end
-
- it "does not rescue Exception and StandardError siblings raised in other#coerce" do
- [Exception, NoMemoryError].each do |exception|
- b = mock("numeric with failed #coerce")
- b.should_receive(:coerce).and_raise(exception)
-
- -> { Rational(3, 4) <=> b }.should raise_error(exception)
- end
- end
- end
-
- ruby_version_is "2.5" do
- it "does not rescue exception raised in other#coerce" do
- b = mock("numeric with failed #coerce")
- b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError)
+ it "does not rescue exception raised in other#coerce" do
+ b = mock("numeric with failed #coerce")
+ b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError)
- -> { Rational(3, 4) <=> b }.should raise_error(RationalSpecs::CoerceError)
- end
+ -> { Rational(3, 4) <=> b }.should raise_error(RationalSpecs::CoerceError)
end
end
diff --git a/spec/ruby/shared/rational/div.rb b/spec/ruby/shared/rational/div.rb
index 2bf9b80eb5..d5bd9e6644 100644
--- a/spec/ruby/shared/rational/div.rb
+++ b/spec/ruby/shared/rational/div.rb
@@ -7,11 +7,11 @@ describe :rational_div_rat, shared: true do
end
it "raises a ZeroDivisionError when the argument has a numerator of 0" do
- lambda { Rational(3, 4).div(Rational(0, 3)) }.should raise_error(ZeroDivisionError)
+ -> { Rational(3, 4).div(Rational(0, 3)) }.should raise_error(ZeroDivisionError)
end
it "raises a ZeroDivisionError when the argument has a numerator of 0.0" do
- lambda { Rational(3, 4).div(Rational(0.0, 3)) }.should raise_error(ZeroDivisionError)
+ -> { Rational(3, 4).div(Rational(0.0, 3)) }.should raise_error(ZeroDivisionError)
end
end
@@ -23,7 +23,7 @@ describe :rational_div_float, shared: true do
end
it "raises a ZeroDivisionError when the argument is 0.0" do
- lambda { Rational(3, 4).div(0.0) }.should raise_error(ZeroDivisionError)
+ -> { Rational(3, 4).div(0.0) }.should raise_error(ZeroDivisionError)
end
end
@@ -34,7 +34,7 @@ describe :rational_div_int, shared: true do
end
it "raises a ZeroDivisionError when the argument is 0" do
- lambda { Rational(3, 4).div(0) }.should raise_error(ZeroDivisionError)
+ -> { Rational(3, 4).div(0) }.should raise_error(ZeroDivisionError)
end
end
@@ -44,11 +44,11 @@ describe :rational_div, shared: true do
end
it "raises an ArgumentError if passed more than one argument" do
- lambda { Rational(3, 4).div(2,3) }.should raise_error(ArgumentError)
+ -> { Rational(3, 4).div(2,3) }.should raise_error(ArgumentError)
end
# See http://redmine.ruby-lang.org/issues/show/1648
it "raises a TypeError if passed a non-numeric argument" do
- lambda { Rational(3, 4).div([]) }.should raise_error(TypeError)
+ -> { Rational(3, 4).div([]) }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/shared/rational/divide.rb b/spec/ruby/shared/rational/divide.rb
index 86d30c39d8..7d6d66390f 100644
--- a/spec/ruby/shared/rational/divide.rb
+++ b/spec/ruby/shared/rational/divide.rb
@@ -10,7 +10,7 @@ describe :rational_divide_rat, shared: true do
end
it "raises a ZeroDivisionError when passed a Rational with a numerator of 0" do
- lambda { Rational(3, 4).send(@method, Rational(0, 1)) }.should raise_error(ZeroDivisionError)
+ -> { Rational(3, 4).send(@method, Rational(0, 1)) }.should raise_error(ZeroDivisionError)
end
end
@@ -22,7 +22,7 @@ describe :rational_divide_int, shared: true do
end
it "raises a ZeroDivisionError when passed 0" do
- lambda { Rational(3, 4).send(@method, 0) }.should raise_error(ZeroDivisionError)
+ -> { Rational(3, 4).send(@method, 0) }.should raise_error(ZeroDivisionError)
end
end
diff --git a/spec/ruby/shared/rational/divmod.rb b/spec/ruby/shared/rational/divmod.rb
index 9433674007..9e23a18186 100644
--- a/spec/ruby/shared/rational/divmod.rb
+++ b/spec/ruby/shared/rational/divmod.rb
@@ -6,11 +6,11 @@ describe :rational_divmod_rat, shared: true do
Rational(7, 4).divmod(Rational(-1, 2)).should eql([-4, Rational(-1, 4)])
Rational(0, 4).divmod(Rational(4, 3)).should eql([0, Rational(0, 1)])
- Rational(bignum_value, 4).divmod(Rational(4, 3)).should eql([1729382256910270464, Rational(0, 1)])
+ Rational(bignum_value, 4).divmod(Rational(4, 3)).should eql([3458764513820540928, Rational(0, 1)])
end
- it "raises a ZeroDivisonError when passed a Rational with a numerator of 0" do
- lambda { Rational(7, 4).divmod(Rational(0, 3)) }.should raise_error(ZeroDivisionError)
+ it "raises a ZeroDivisionError when passed a Rational with a numerator of 0" do
+ -> { Rational(7, 4).divmod(Rational(0, 3)) }.should raise_error(ZeroDivisionError)
end
end
@@ -19,11 +19,11 @@ describe :rational_divmod_int, shared: true do
Rational(7, 4).divmod(2).should eql([0, Rational(7, 4)])
Rational(7, 4).divmod(-2).should eql([-1, Rational(-1, 4)])
- Rational(bignum_value, 4).divmod(3).should == [768614336404564650, Rational(2, 1)]
+ Rational(bignum_value, 4).divmod(3).should eql([1537228672809129301, Rational(1, 1)])
end
it "raises a ZeroDivisionError when passed 0" do
- lambda { Rational(7, 4).divmod(0) }.should raise_error(ZeroDivisionError)
+ -> { Rational(7, 4).divmod(0) }.should raise_error(ZeroDivisionError)
end
end
@@ -37,6 +37,6 @@ describe :rational_divmod_float, shared: true do
end
it "raises a ZeroDivisionError when passed 0" do
- lambda { Rational(7, 4).divmod(0.0) }.should raise_error(ZeroDivisionError)
+ -> { Rational(7, 4).divmod(0.0) }.should raise_error(ZeroDivisionError)
end
end
diff --git a/spec/ruby/shared/rational/exponent.rb b/spec/ruby/shared/rational/exponent.rb
index ac8237c291..b0e9b23574 100644
--- a/spec/ruby/shared/rational/exponent.rb
+++ b/spec/ruby/shared/rational/exponent.rb
@@ -40,10 +40,10 @@ describe :rational_exponent, shared: true do
(Rational(-3, 4) ** -4).should == Rational(256, 81)
(Rational(3, -4) ** -4).should == Rational(256, 81)
- (Rational(bignum_value, 4) ** 4).should == Rational(28269553036454149273332760011886696253239742350009903329945699220681916416, 1)
- (Rational(3, bignum_value) ** -4).should == Rational(7237005577332262213973186563042994240829374041602535252466099000494570602496, 81)
- (Rational(-bignum_value, 4) ** -4).should == Rational(1, 28269553036454149273332760011886696253239742350009903329945699220681916416)
- (Rational(3, -bignum_value) ** -4).should == Rational(7237005577332262213973186563042994240829374041602535252466099000494570602496, 81)
+ (Rational(bignum_value, 4) ** 4).should == Rational(452312848583266388373324160190187140051835877600158453279131187530910662656, 1)
+ (Rational(3, bignum_value) ** -4).should == Rational(115792089237316195423570985008687907853269984665640564039457584007913129639936, 81)
+ (Rational(-bignum_value, 4) ** -4).should == Rational(1, 452312848583266388373324160190187140051835877600158453279131187530910662656)
+ (Rational(3, -bignum_value) ** -4).should == Rational(115792089237316195423570985008687907853269984665640564039457584007913129639936, 81)
end
# Guard against the Mathn library
@@ -66,7 +66,7 @@ describe :rational_exponent, shared: true do
end
it "raises ZeroDivisionError when self is Rational(0) and the exponent is negative" do
- lambda { Rational(0) ** -bignum_value }.should raise_error(ZeroDivisionError)
+ -> { Rational(0) ** -bignum_value }.should raise_error(ZeroDivisionError)
end
it "returns Rational(1) when self is Rational(1)" do
@@ -85,26 +85,44 @@ describe :rational_exponent, shared: true do
end
it "returns positive Infinity when self is > 1" do
- (Rational(2) ** bignum_value).infinite?.should == 1
- (Rational(fixnum_max) ** bignum_value).infinite?.should == 1
+ -> {
+ (Rational(2) ** bignum_value).infinite?.should == 1
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ -> {
+ (Rational(fixnum_max) ** bignum_value).infinite?.should == 1
+ }.should complain(/warning: in a\*\*b, b may be too big/)
end
it "returns 0.0 when self is > 1 and the exponent is negative" do
- (Rational(2) ** -bignum_value).should eql(0.0)
- (Rational(fixnum_max) ** -bignum_value).should eql(0.0)
+ -> {
+ (Rational(2) ** -bignum_value).should eql(0.0)
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ -> {
+ (Rational(fixnum_max) ** -bignum_value).should eql(0.0)
+ }.should complain(/warning: in a\*\*b, b may be too big/)
end
# Fails on linux due to pow() bugs in glibc: http://sources.redhat.com/bugzilla/show_bug.cgi?id=3866
platform_is_not :linux do
it "returns positive Infinity when self < -1" do
- (Rational(-2) ** bignum_value).infinite?.should == 1
- (Rational(-2) ** (bignum_value + 1)).infinite?.should == 1
- (Rational(fixnum_min) ** bignum_value).infinite?.should == 1
+ -> {
+ (Rational(-2) ** bignum_value).infinite?.should == 1
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ -> {
+ (Rational(-2) ** (bignum_value + 1)).infinite?.should == 1
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ -> {
+ (Rational(fixnum_min) ** bignum_value).infinite?.should == 1
+ }.should complain(/warning: in a\*\*b, b may be too big/)
end
it "returns 0.0 when self is < -1 and the exponent is negative" do
- (Rational(-2) ** -bignum_value).should eql(0.0)
- (Rational(fixnum_min) ** -bignum_value).should eql(0.0)
+ -> {
+ (Rational(-2) ** -bignum_value).should eql(0.0)
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ -> {
+ (Rational(fixnum_min) ** -bignum_value).should eql(0.0)
+ }.should complain(/warning: in a\*\*b, b may be too big/)
end
end
end
@@ -153,19 +171,19 @@ describe :rational_exponent, shared: true do
it "raises ZeroDivisionError for Rational(0, 1) passed a negative Integer" do
[-1, -4, -9999].each do |exponent|
- lambda { Rational(0, 1) ** exponent }.should raise_error(ZeroDivisionError, "divided by 0")
+ -> { Rational(0, 1) ** exponent }.should raise_error(ZeroDivisionError, "divided by 0")
end
end
it "raises ZeroDivisionError for Rational(0, 1) passed a negative Rational with denominator 1" do
[Rational(-1, 1), Rational(-3, 1)].each do |exponent|
- lambda { Rational(0, 1) ** exponent }.should raise_error(ZeroDivisionError, "divided by 0")
+ -> { Rational(0, 1) ** exponent }.should raise_error(ZeroDivisionError, "divided by 0")
end
end
# #7513
it "raises ZeroDivisionError for Rational(0, 1) passed a negative Rational" do
- lambda { Rational(0, 1) ** Rational(-3, 2) }.should raise_error(ZeroDivisionError, "divided by 0")
+ -> { Rational(0, 1) ** Rational(-3, 2) }.should raise_error(ZeroDivisionError, "divided by 0")
end
platform_is_not :solaris do # See https://github.com/ruby/spec/issues/134
diff --git a/spec/ruby/shared/rational/minus.rb b/spec/ruby/shared/rational/minus.rb
deleted file mode 100644
index 0a0946fdb9..0000000000
--- a/spec/ruby/shared/rational/minus.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :rational_minus_rat, shared: true do
- it "returns the result of subtracting other from self as a Rational" do
- (Rational(3, 4) - Rational(0, 1)).should eql(Rational(3, 4))
- (Rational(3, 4) - Rational(1, 4)).should eql(Rational(1, 2))
-
- (Rational(3, 4) - Rational(2, 1)).should eql(Rational(-5, 4))
- end
-end
-
-describe :rational_minus_int, shared: true do
- it "returns the result of subtracting other from self as a Rational" do
- (Rational(3, 4) - 1).should eql(Rational(-1, 4))
- (Rational(3, 4) - 2).should eql(Rational(-5, 4))
- end
-end
-
-describe :rational_minus_float, shared: true do
- it "returns the result of subtracting other from self as a Float" do
- (Rational(3, 4) - 0.2).should eql(0.55)
- (Rational(3, 4) - 2.5).should eql(-1.75)
- end
-end
-
-describe :rational_minus, shared: true do
- it "calls #coerce on the passed argument with self" do
- rational = Rational(3, 4)
- obj = mock("Object")
- obj.should_receive(:coerce).with(rational).and_return([1, 2])
-
- rational - obj
- end
-
- it "calls #- on the coerced Rational with the coerced Object" do
- rational = Rational(3, 4)
-
- coerced_rational = mock("Coerced Rational")
- coerced_rational.should_receive(:-).and_return(:result)
-
- coerced_obj = mock("Coerced Object")
-
- obj = mock("Object")
- obj.should_receive(:coerce).and_return([coerced_rational, coerced_obj])
-
- (rational - obj).should == :result
- end
-end
diff --git a/spec/ruby/shared/rational/modulo.rb b/spec/ruby/shared/rational/modulo.rb
index 39abaed5fe..9e4b0c49e6 100644
--- a/spec/ruby/shared/rational/modulo.rb
+++ b/spec/ruby/shared/rational/modulo.rb
@@ -22,21 +22,21 @@ describe :rational_modulo, shared: true do
end
it "raises ZeroDivisionError on zero denominator" do
- lambda {
+ -> {
Rational(3, 5).send(@method, Rational(0, 1))
}.should raise_error(ZeroDivisionError)
- lambda {
+ -> {
Rational(0, 1).send(@method, Rational(0, 1))
}.should raise_error(ZeroDivisionError)
- lambda {
+ -> {
Rational(3, 5).send(@method, 0)
}.should raise_error(ZeroDivisionError)
end
it "raises a ZeroDivisionError when the argument is 0.0" do
- lambda {
+ -> {
Rational(3, 5).send(@method, 0.0)
}.should raise_error(ZeroDivisionError)
end
diff --git a/spec/ruby/shared/rational/round.rb b/spec/ruby/shared/rational/round.rb
index 36ed476350..5b159ee3e6 100644
--- a/spec/ruby/shared/rational/round.rb
+++ b/spec/ruby/shared/rational/round.rb
@@ -72,28 +72,35 @@ describe :rational_round, shared: true do
end
end
- ruby_version_is "2.4" do
- describe "with half option" do
- it "returns an Integer when precision is not passed" do
- Rational(10, 4).round(half: :up).should == 3
- Rational(10, 4).round(half: :down).should == 2
- Rational(10, 4).round(half: :even).should == 2
- Rational(-10, 4).round(half: :up).should == -3
- Rational(-10, 4).round(half: :down).should == -2
- Rational(-10, 4).round(half: :even).should == -2
- end
+ describe "with half option" do
+ it "returns an Integer when precision is not passed" do
+ Rational(10, 4).round(half: nil).should == 3
+ Rational(10, 4).round(half: :up).should == 3
+ Rational(10, 4).round(half: :down).should == 2
+ Rational(10, 4).round(half: :even).should == 2
+ Rational(-10, 4).round(half: nil).should == -3
+ Rational(-10, 4).round(half: :up).should == -3
+ Rational(-10, 4).round(half: :down).should == -2
+ Rational(-10, 4).round(half: :even).should == -2
+ end
- it "returns a Rational when the precision is greater than 0" do
- Rational(25, 100).round(1, half: :up).should == Rational(3, 10)
- Rational(25, 100).round(1, half: :down).should == Rational(1, 5)
- Rational(25, 100).round(1, half: :even).should == Rational(1, 5)
- Rational(35, 100).round(1, half: :up).should == Rational(2, 5)
- Rational(35, 100).round(1, half: :down).should == Rational(3, 10)
- Rational(35, 100).round(1, half: :even).should == Rational(2, 5)
- Rational(-25, 100).round(1, half: :up).should == Rational(-3, 10)
- Rational(-25, 100).round(1, half: :down).should == Rational(-1, 5)
- Rational(-25, 100).round(1, half: :even).should == Rational(-1, 5)
- end
+ it "returns a Rational when the precision is greater than 0" do
+ Rational(25, 100).round(1, half: nil).should == Rational(3, 10)
+ Rational(25, 100).round(1, half: :up).should == Rational(3, 10)
+ Rational(25, 100).round(1, half: :down).should == Rational(1, 5)
+ Rational(25, 100).round(1, half: :even).should == Rational(1, 5)
+ Rational(35, 100).round(1, half: nil).should == Rational(2, 5)
+ Rational(35, 100).round(1, half: :up).should == Rational(2, 5)
+ Rational(35, 100).round(1, half: :down).should == Rational(3, 10)
+ Rational(35, 100).round(1, half: :even).should == Rational(2, 5)
+ Rational(-25, 100).round(1, half: nil).should == Rational(-3, 10)
+ Rational(-25, 100).round(1, half: :up).should == Rational(-3, 10)
+ Rational(-25, 100).round(1, half: :down).should == Rational(-1, 5)
+ Rational(-25, 100).round(1, half: :even).should == Rational(-1, 5)
+ end
+
+ it "raise for a non-existent round mode" do
+ -> { Rational(10, 4).round(half: :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode: nonsense")
end
end
end
diff --git a/spec/ruby/shared/rational/to_f.rb b/spec/ruby/shared/rational/to_f.rb
index 56e0b61d68..472a585daa 100644
--- a/spec/ruby/shared/rational/to_f.rb
+++ b/spec/ruby/shared/rational/to_f.rb
@@ -7,4 +7,10 @@ describe :rational_to_f, shared: true do
Rational(-1, 4).to_f.should eql(-0.25)
Rational(-1, -4).to_f.should eql(0.25)
end
+
+ it "converts to a Float for large numerator and denominator" do
+ num = 1000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146009
+ den = 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+ Rational(num, den).to_f.should == 500.0
+ end
end
diff --git a/spec/ruby/shared/sizedqueue/enque.rb b/spec/ruby/shared/sizedqueue/enque.rb
index b724101269..059f1025a7 100644
--- a/spec/ruby/shared/sizedqueue/enque.rb
+++ b/spec/ruby/shared/sizedqueue/enque.rb
@@ -22,7 +22,7 @@ describe :sizedqueue_enq, shared: true do
q = @object.call(2)
non_blocking = true
- add_to_queue = lambda { q.send(@method, Object.new, non_blocking) }
+ add_to_queue = -> { q.send(@method, Object.new, non_blocking) }
q.size.should == 0
add_to_queue.call
@@ -37,7 +37,7 @@ describe :sizedqueue_enq, shared: true do
q << 1
t = Thread.new {
- lambda { q.send(@method, 2) }.should raise_error(ClosedQueueError)
+ -> { q.send(@method, 2) }.should raise_error(ClosedQueueError)
}
Thread.pass until q.num_waiting == 1
@@ -47,4 +47,67 @@ describe :sizedqueue_enq, shared: true do
t.join
q.pop.should == 1
end
+
+ describe "with a timeout" do
+ ruby_version_is "3.2" do
+ it "returns self if the item was pushed in time" do
+ q = @object.call(1)
+ q << 1
+
+ t = Thread.new {
+ q.send(@method, 2, timeout: 1).should == q
+ }
+ Thread.pass until t.status == "sleep" && q.num_waiting == 1
+ q.pop
+ t.join
+ end
+
+ it "does nothing if the timeout is nil" do
+ q = @object.call(1)
+ q << 1
+ t = Thread.new {
+ q.send(@method, 2, timeout: nil).should == q
+ }
+ t.join(0.2).should == nil
+ q.pop
+ t.join
+ end
+
+ it "returns nil if no space is avialable and timeout is 0" do
+ q = @object.call(1)
+ q.send(@method, 1, timeout: 0).should == q
+ q.send(@method, 2, timeout: 0).should == nil
+ end
+
+ 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
+ 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",
+ )
+ 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",
+ )
+ end
+ end
+ end
end
diff --git a/spec/ruby/shared/sizedqueue/max.rb b/spec/ruby/shared/sizedqueue/max.rb
index cd4b47f1c1..ea10d24be0 100644
--- a/spec/ruby/shared/sizedqueue/max.rb
+++ b/spec/ruby/shared/sizedqueue/max.rb
@@ -27,21 +27,21 @@ describe :sizedqueue_max=, shared: true do
it "raises a TypeError when given a non-numeric value" do
q = @object.call(5)
- lambda { q.max = "foo" }.should raise_error(TypeError)
- lambda { q.max = Object.new }.should raise_error(TypeError)
+ -> { q.max = "foo" }.should raise_error(TypeError)
+ -> { q.max = Object.new }.should raise_error(TypeError)
end
it "raises an argument error when set to zero" do
q = @object.call(5)
q.max.should == 5
- lambda { q.max = 0 }.should raise_error(ArgumentError)
+ -> { q.max = 0 }.should raise_error(ArgumentError)
q.max.should == 5
end
it "raises an argument error when set to a negative number" do
q = @object.call(5)
q.max.should == 5
- lambda { q.max = -1 }.should raise_error(ArgumentError)
+ -> { q.max = -1 }.should raise_error(ArgumentError)
q.max.should == 5
end
end
diff --git a/spec/ruby/shared/sizedqueue/new.rb b/spec/ruby/shared/sizedqueue/new.rb
index 4439f2a9c6..2573194efb 100644
--- a/spec/ruby/shared/sizedqueue/new.rb
+++ b/spec/ruby/shared/sizedqueue/new.rb
@@ -1,18 +1,23 @@
describe :sizedqueue_new, shared: true do
- it "raises a TypeError when the given argument is not Numeric" do
- lambda { @object.call("foo") }.should raise_error(TypeError)
- lambda { @object.call(Object.new) }.should raise_error(TypeError)
+ it "raises a TypeError when the given argument doesn't respond to #to_int" do
+ -> { @object.call("12") }.should raise_error(TypeError)
+ -> { @object.call(Object.new) }.should raise_error(TypeError)
+
+ @object.call(12.9).max.should == 12
+ object = Object.new
+ object.define_singleton_method(:to_int) { 42 }
+ @object.call(object).max.should == 42
end
it "raises an argument error when no argument is given" do
- lambda { @object.call }.should raise_error(ArgumentError)
+ -> { @object.call }.should raise_error(ArgumentError)
end
it "raises an argument error when the given argument is zero" do
- lambda { @object.call(0) }.should raise_error(ArgumentError)
+ -> { @object.call(0) }.should raise_error(ArgumentError)
end
it "raises an argument error when the given argument is negative" do
- lambda { @object.call(-1) }.should raise_error(ArgumentError)
+ -> { @object.call(-1) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/shared/string/end_with.rb b/spec/ruby/shared/string/end_with.rb
new file mode 100644
index 0000000000..0e4c1386e8
--- /dev/null
+++ b/spec/ruby/shared/string/end_with.rb
@@ -0,0 +1,61 @@
+describe :end_with, shared: true do
+ # the @method should either be :to_s or :to_sym
+
+ it "returns true only if ends match" do
+ s = "hello".send(@method)
+ s.should.end_with?('o')
+ s.should.end_with?('llo')
+ end
+
+ it 'returns false if the end does not match' do
+ s = 'hello'.send(@method)
+ s.should_not.end_with?('ll')
+ end
+
+ it "returns true if the search string is empty" do
+ "hello".send(@method).should.end_with?("")
+ "".send(@method).should.end_with?("")
+ end
+
+ it "returns true only if any ending match" do
+ "hello".send(@method).should.end_with?('x', 'y', 'llo', 'z')
+ end
+
+ it "converts its argument using :to_str" do
+ s = "hello".send(@method)
+ find = mock('o')
+ find.should_receive(:to_str).and_return("o")
+ s.should.end_with?(find)
+ end
+
+ it "ignores arguments not convertible to string" do
+ "hello".send(@method).should_not.end_with?()
+ -> { "hello".send(@method).end_with?(1) }.should raise_error(TypeError)
+ -> { "hello".send(@method).end_with?(["o"]) }.should raise_error(TypeError)
+ -> { "hello".send(@method).end_with?(1, nil, "o") }.should raise_error(TypeError)
+ end
+
+ it "uses only the needed arguments" do
+ find = mock('h')
+ find.should_not_receive(:to_str)
+ "hello".send(@method).should.end_with?("o", find)
+ end
+
+ it "works for multibyte strings" do
+ "céréale".send(@method).should.end_with?("réale")
+ end
+
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ pat = "ア".encode Encoding::EUC_JP
+ -> do
+ "あれ".send(@method).end_with?(pat)
+ end.should raise_error(Encoding::CompatibilityError)
+ end
+
+ it "checks that we are starting to match at the head of a character" do
+ "\xC3\xA9".send(@method).should_not.end_with?("\xA9")
+ "\xe3\x81\x82".send(@method).should_not.end_with?("\x82")
+ "ab".force_encoding("UTF-16BE").send(@method).should_not.end_with?(
+ "b".force_encoding("UTF-16BE"))
+ end
+end
diff --git a/spec/ruby/shared/string/start_with.rb b/spec/ruby/shared/string/start_with.rb
new file mode 100644
index 0000000000..6932a017b6
--- /dev/null
+++ b/spec/ruby/shared/string/start_with.rb
@@ -0,0 +1,76 @@
+describe :start_with, shared: true do
+ # the @method should either be :to_s or :to_sym
+
+ it "returns true only if beginning match" do
+ s = "hello".send(@method)
+ s.should.start_with?('h')
+ s.should.start_with?('hel')
+ s.should_not.start_with?('el')
+ end
+
+ it "returns true only if any beginning match" do
+ "hello".send(@method).should.start_with?('x', 'y', 'he', 'z')
+ end
+
+ it "returns true if the search string is empty" do
+ "hello".send(@method).should.start_with?("")
+ "".send(@method).should.start_with?("")
+ end
+
+ it "converts its argument using :to_str" do
+ s = "hello".send(@method)
+ find = mock('h')
+ find.should_receive(:to_str).and_return("h")
+ s.should.start_with?(find)
+ end
+
+ it "ignores arguments not convertible to string" do
+ "hello".send(@method).should_not.start_with?()
+ -> { "hello".send(@method).start_with?(1) }.should raise_error(TypeError)
+ -> { "hello".send(@method).start_with?(["h"]) }.should raise_error(TypeError)
+ -> { "hello".send(@method).start_with?(1, nil, "h") }.should raise_error(TypeError)
+ end
+
+ it "uses only the needed arguments" do
+ find = mock('h')
+ find.should_not_receive(:to_str)
+ "hello".send(@method).should.start_with?("h",find)
+ end
+
+ it "works for multibyte strings" do
+ "céréale".send(@method).should.start_with?("cér")
+ end
+
+ it "supports regexps" do
+ regexp = /[h1]/
+ "hello".send(@method).should.start_with?(regexp)
+ "1337".send(@method).should.start_with?(regexp)
+ "foxes are 1337".send(@method).should_not.start_with?(regexp)
+ "chunky\n12bacon".send(@method).should_not.start_with?(/12/)
+ end
+
+ it "supports regexps with ^ and $ modifiers" do
+ regexp1 = /^\d{2}/
+ regexp2 = /\d{2}$/
+ "12test".send(@method).should.start_with?(regexp1)
+ "test12".send(@method).should_not.start_with?(regexp1)
+ "12test".send(@method).should_not.start_with?(regexp2)
+ "test12".send(@method).should_not.start_with?(regexp2)
+ end
+
+ it "sets Regexp.last_match if it returns true" do
+ regexp = /test-(\d+)/
+ "test-1337".send(@method).start_with?(regexp).should be_true
+ Regexp.last_match.should_not be_nil
+ Regexp.last_match[1].should == "1337"
+ $1.should == "1337"
+
+ "test-asdf".send(@method).start_with?(regexp).should be_false
+ Regexp.last_match.should be_nil
+ $1.should be_nil
+ end
+
+ it "does not check that we are not matching part of a character" do
+ "\xC3\xA9".send(@method).should.start_with?("\xC3")
+ end
+end
diff --git a/spec/ruby/shared/string/times.rb b/spec/ruby/shared/string/times.rb
index c44a76c9b7..8ca9507570 100644
--- a/spec/ruby/shared/string/times.rb
+++ b/spec/ruby/shared/string/times.rb
@@ -18,47 +18,51 @@ describe :string_times, shared: true do
end
it "raises an ArgumentError when given integer is negative" do
- lambda { @object.call("cool", -3) }.should raise_error(ArgumentError)
- lambda { @object.call("cool", -3.14) }.should raise_error(ArgumentError)
+ -> { @object.call("cool", -3) }.should raise_error(ArgumentError)
+ -> { @object.call("cool", -3.14) }.should raise_error(ArgumentError)
+ -> { @object.call("cool", min_long) }.should raise_error(ArgumentError)
end
it "raises a RangeError when given integer is a Bignum" do
- lambda { @object.call("cool", 999999999999999999999) }.should raise_error(RangeError)
+ -> { @object.call("cool", 999999999999999999999) }.should raise_error(RangeError)
+ -> { @object.call("", 999999999999999999999) }.should raise_error(RangeError)
end
- it "returns subclass instances" do
- @object.call(MyString.new("cool"), 0).should be_an_instance_of(MyString)
- @object.call(MyString.new("cool"), 1).should be_an_instance_of(MyString)
- @object.call(MyString.new("cool"), 2).should be_an_instance_of(MyString)
+ it "works with huge long values when string is empty" do
+ @object.call("", max_long).should == ""
end
- it "always taints the result when self is tainted" do
- ["", "OK", MyString.new(""), MyString.new("OK")].each do |str|
- str.taint
-
- [0, 1, 2].each do |arg|
- @object.call(str, arg).tainted?.should == true
- end
+ ruby_version_is ''...'3.0' do
+ it "returns subclass instances" do
+ @object.call(MyString.new("cool"), 0).should be_an_instance_of(MyString)
+ @object.call(MyString.new("cool"), 1).should be_an_instance_of(MyString)
+ @object.call(MyString.new("cool"), 2).should be_an_instance_of(MyString)
end
end
- with_feature :encoding do
- it "returns a String in the same encoding as self" do
- str = "\xE3\x81\x82".force_encoding Encoding::UTF_8
- result = @object.call(str, 2)
- result.encoding.should equal(Encoding::UTF_8)
+ ruby_version_is '3.0' do
+ it "returns String instances" do
+ @object.call(MyString.new("cool"), 0).should be_an_instance_of(String)
+ @object.call(MyString.new("cool"), 1).should be_an_instance_of(String)
+ @object.call(MyString.new("cool"), 2).should be_an_instance_of(String)
end
end
+ it "returns a String in the same encoding as self" do
+ str = "\xE3\x81\x82".force_encoding Encoding::UTF_8
+ result = @object.call(str, 2)
+ result.encoding.should equal(Encoding::UTF_8)
+ end
+
platform_is wordsize: 32 do
it "raises an ArgumentError if the length of the resulting string doesn't fit into a long" do
- lambda { @object.call("abc", (2 ** 31) - 1) }.should raise_error(ArgumentError)
+ -> { @object.call("abc", (2 ** 31) - 1) }.should raise_error(ArgumentError)
end
end
platform_is wordsize: 64 do
it "raises an ArgumentError if the length of the resulting string doesn't fit into a long" do
- lambda { @object.call("abc", (2 ** 63) - 1) }.should raise_error(ArgumentError)
+ -> { @object.call("abc", (2 ** 63) - 1) }.should raise_error(ArgumentError)
end
end
end
diff --git a/spec/ruby/shared/time/strftime_for_date.rb b/spec/ruby/shared/time/strftime_for_date.rb
index f126c5a323..dbb124adc8 100644
--- a/spec/ruby/shared/time/strftime_for_date.rb
+++ b/spec/ruby/shared/time/strftime_for_date.rb
@@ -264,12 +264,10 @@ describe :strftime_date, shared: true do
@new_date[2001,3,22].strftime("%-m/%-d/%-y").should == "3/22/1"
end
- with_feature :encoding do
- it "passes the format string's encoding to the result string" do
- result = @new_date[2010,3,8].strftime("%d. März %Y")
+ it "passes the format string's encoding to the result string" do
+ result = @new_date[2010,3,8].strftime("%d. März %Y")
- result.encoding.should == Encoding::UTF_8
- result.should == "08. März 2010"
- end
+ result.encoding.should == Encoding::UTF_8
+ result.should == "08. März 2010"
end
end
diff --git a/spec/ruby/shared/time/strftime_for_time.rb b/spec/ruby/shared/time/strftime_for_time.rb
index 49cd09051a..9f4d08d72e 100644
--- a/spec/ruby/shared/time/strftime_for_time.rb
+++ b/spec/ruby/shared/time/strftime_for_time.rb
@@ -170,4 +170,12 @@ describe :strftime_time, shared: true do
time.strftime("%-k%p").should == "8AM"
time.strftime("%-l%p").should == "8AM"
end
+
+ it "should be able to show default Logger format" do
+ default_logger_format = "%Y-%m-%dT%H:%M:%S.%6N "
+ @new_time[2001, 2, 3, 4, 5, 6].strftime(default_logger_format).should == "2001-02-03T04:05:06.000000 "
+ @new_time[2001, 12, 3, 4, 5, 6 + 1/10r].strftime(default_logger_format).should == "2001-12-03T04:05:06.100000 "
+ @new_time[2001, 2, 13, 4, 5, 6 + 1/100r].strftime(default_logger_format).should == "2001-02-13T04:05:06.010000 "
+ @new_time[2001, 2, 3, 14, 5, 6 + 1/1000r].strftime(default_logger_format).should == "2001-02-03T14:05:06.001000 "
+ end
end