diff options
Diffstat (limited to 'spec/ruby/shared')
40 files changed, 643 insertions, 403 deletions
diff --git a/spec/ruby/shared/basicobject/method_missing.rb b/spec/ruby/shared/basicobject/method_missing.rb index 4871603dce..330f6a4922 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 - -> { @object.no_such_method }.should raise_error(NoMethodError) + -> { @object.no_such_method }.should.raise(NoMethodError) end it "raises a NoMethodError when a protected method is called" do - -> { @object.method_protected }.should raise_error(NoMethodError) + -> { @object.method_protected }.should.raise(NoMethodError) end it "raises a NoMethodError when a private method is called" do - -> { @object.method_private }.should raise_error(NoMethodError) + -> { @object.method_private }.should.raise(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 - -> { @object.no_such_method }.should raise_error(NoMethodError) + -> { @object.no_such_method }.should.raise(NoMethodError) end it "raises a NoMethodError when a protected method is called" do - -> { @object.method_protected }.should raise_error(NoMethodError) + -> { @object.method_protected }.should.raise(NoMethodError) end it "raises a NoMethodError when a private method is called" do - -> { @object.method_private }.should raise_error(NoMethodError) + -> { @object.method_private }.should.raise(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 - -> { @object.new.no_such_method }.should raise_error(NoMethodError) + -> { @object.new.no_such_method }.should.raise(NoMethodError) end it "raises a NoMethodError when a protected method is called" do - -> { @object.new.method_protected }.should raise_error(NoMethodError) + -> { @object.new.method_protected }.should.raise(NoMethodError) end it "raises a NoMethodError when a private method is called" do - -> { @object.new.method_private }.should raise_error(NoMethodError) + -> { @object.new.method_private }.should.raise(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 625aaa2917..d38aea975e 100644 --- a/spec/ruby/shared/basicobject/send.rb +++ b/spec/ruby/shared/basicobject/send.rb @@ -30,10 +30,10 @@ describe :basicobject_send, shared: true do end it "raises a TypeError if the method name is not a string or symbol" do - -> { SendSpecs.send(@method, nil) }.should raise_error(TypeError, /not a symbol nor a string/) - -> { SendSpecs.send(@method, 42) }.should raise_error(TypeError, /not a symbol nor a string/) - -> { SendSpecs.send(@method, 3.14) }.should raise_error(TypeError, /not a symbol nor a string/) - -> { SendSpecs.send(@method, true) }.should raise_error(TypeError, /not a symbol nor a string/) + -> { SendSpecs.send(@method, nil) }.should.raise(TypeError, /not a symbol nor a string/) + -> { SendSpecs.send(@method, 42) }.should.raise(TypeError, /not a symbol nor a string/) + -> { SendSpecs.send(@method, 3.14) }.should.raise(TypeError, /not a symbol nor a string/) + -> { SendSpecs.send(@method, true) }.should.raise(TypeError, /not a symbol nor a string/) end it "raises a NameError if the corresponding method can't be found" do @@ -42,7 +42,7 @@ describe :basicobject_send, shared: true do 'done' end end - -> { SendSpecs::Foo.new.send(@method, :syegsywhwua) }.should raise_error(NameError) + -> { SendSpecs::Foo.new.send(@method, :syegsywhwua) }.should.raise(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 - -> { SendSpecs::Foo.send(@method, :baz) }.should raise_error(NameError) + -> { SendSpecs::Foo.send(@method, :baz) }.should.raise(NameError) end it "raises an ArgumentError if no arguments are given" do class SendSpecs::Foo; end - -> { SendSpecs::Foo.new.send @method }.should raise_error(ArgumentError) + -> { SendSpecs::Foo.new.send @method }.should.raise(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 - -> { SendSpecs::Foo.new.send(@method, :bar, :arg) }.should raise_error(ArgumentError) + -> { SendSpecs::Foo.new.send(@method, :bar, :arg) }.should.raise(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 - -> { SendSpecs::Foo.new.send(@method, :foo) }.should raise_error(ArgumentError) + -> { SendSpecs::Foo.new.send(@method, :foo) }.should.raise(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 index 8af2626d2a..db95ef9c78 100644 --- a/spec/ruby/shared/enumerable/minmax.rb +++ b/spec/ruby/shared/enumerable/minmax.rb @@ -14,11 +14,11 @@ describe :enumerable_minmax, shared: true do end it "raises a NoMethodError for elements without #<=>" do - -> { @incomparable_enum.minmax }.should raise_error(NoMethodError) + -> { @incomparable_enum.minmax }.should.raise(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) + -> { @incompatible_enum.minmax }.should.raise(ArgumentError) + -> { @enum.minmax{ |a, b| nil } }.should.raise(ArgumentError) end end diff --git a/spec/ruby/shared/file/directory.rb b/spec/ruby/shared/file/directory.rb index 8ba933a601..84f8f1a958 100644 --- a/spec/ruby/shared/file/directory.rb +++ b/spec/ruby/shared/file/directory.rb @@ -12,24 +12,24 @@ describe :file_directory, shared: true do end it "returns true if the argument is a directory" do - @object.send(@method, @dir).should be_true + @object.send(@method, @dir).should == true end it "returns false if the argument is not a directory" do - @object.send(@method, @file).should be_false + @object.send(@method, @file).should == false end it "accepts an object that has a #to_path method" do - @object.send(@method, mock_to_path(@dir)).should be_true + @object.send(@method, mock_to_path(@dir)).should == true end it "raises a TypeError when passed an Integer" do - -> { @object.send(@method, 1) }.should raise_error(TypeError) - -> { @object.send(@method, bignum_value) }.should raise_error(TypeError) + -> { @object.send(@method, 1) }.should.raise(TypeError) + -> { @object.send(@method, bignum_value) }.should.raise(TypeError) end it "raises a TypeError when passed nil" do - -> { @object.send(@method, nil) }.should raise_error(TypeError) + -> { @object.send(@method, nil) }.should.raise(TypeError) end end @@ -47,13 +47,13 @@ describe :file_directory_io, shared: true do end it "returns false if the argument is an IO that's not a directory" do - @object.send(@method, STDIN).should be_false + @object.send(@method, STDIN).should == false end platform_is_not :windows do it "returns true if the argument is an IO that is a directory" do File.open(@dir, "r") do |f| - @object.send(@method, f).should be_true + @object.send(@method, f).should == true end end end @@ -61,6 +61,6 @@ describe :file_directory_io, shared: true do it "calls #to_io to convert a non-IO object" do io = mock('FileDirectoryIO') io.should_receive(:to_io).and_return(STDIN) - @object.send(@method, io).should be_false + @object.send(@method, io).should == false end end diff --git a/spec/ruby/shared/file/executable.rb b/spec/ruby/shared/file/executable.rb index baa156de98..0fc65cf866 100644 --- a/spec/ruby/shared/file/executable.rb +++ b/spec/ruby/shared/file/executable.rb @@ -31,13 +31,13 @@ describe :file_executable, shared: true do end it "raises an ArgumentError if not passed one argument" do - -> { @object.send(@method) }.should raise_error(ArgumentError) + -> { @object.send(@method) }.should.raise(ArgumentError) end it "raises a TypeError if not passed a String type" do - -> { @object.send(@method, 1) }.should raise_error(TypeError) - -> { @object.send(@method, nil) }.should raise_error(TypeError) - -> { @object.send(@method, false) }.should raise_error(TypeError) + -> { @object.send(@method, 1) }.should.raise(TypeError) + -> { @object.send(@method, nil) }.should.raise(TypeError) + -> { @object.send(@method, false) }.should.raise(TypeError) end platform_is_not :windows do diff --git a/spec/ruby/shared/file/executable_real.rb b/spec/ruby/shared/file/executable_real.rb index bf2734ea07..90b7a41ba7 100644 --- a/spec/ruby/shared/file/executable_real.rb +++ b/spec/ruby/shared/file/executable_real.rb @@ -29,13 +29,13 @@ describe :file_executable_real, shared: true do end it "raises an ArgumentError if not passed one argument" do - -> { @object.send(@method) }.should raise_error(ArgumentError) + -> { @object.send(@method) }.should.raise(ArgumentError) end it "raises a TypeError if not passed a String type" do - -> { @object.send(@method, 1) }.should raise_error(TypeError) - -> { @object.send(@method, nil) }.should raise_error(TypeError) - -> { @object.send(@method, false) }.should raise_error(TypeError) + -> { @object.send(@method, 1) }.should.raise(TypeError) + -> { @object.send(@method, nil) }.should.raise(TypeError) + -> { @object.send(@method, false) }.should.raise(TypeError) end platform_is_not :windows do diff --git a/spec/ruby/shared/file/exist.rb b/spec/ruby/shared/file/exist.rb index 67424146c5..5075fa74b9 100644 --- a/spec/ruby/shared/file/exist.rb +++ b/spec/ruby/shared/file/exist.rb @@ -5,12 +5,12 @@ describe :file_exist, shared: true do end it "raises an ArgumentError if not passed one argument" do - -> { @object.send(@method) }.should raise_error(ArgumentError) - -> { @object.send(@method, __FILE__, __FILE__) }.should raise_error(ArgumentError) + -> { @object.send(@method) }.should.raise(ArgumentError) + -> { @object.send(@method, __FILE__, __FILE__) }.should.raise(ArgumentError) end it "raises a TypeError if not passed a String type" do - -> { @object.send(@method, nil) }.should raise_error(TypeError) + -> { @object.send(@method, nil) }.should.raise(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 c1748a88b3..18477cff55 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 - -> { @object.send(@method) }.should raise_error(ArgumentError) - -> { @object.send(@method, @null, @file) }.should raise_error(ArgumentError) + -> { @object.send(@method) }.should.raise(ArgumentError) + -> { @object.send(@method, @null, @file) }.should.raise(ArgumentError) end it "raises a TypeError if not passed a String type" do - -> { @object.send(@method, nil) }.should raise_error(TypeError) - -> { @object.send(@method, 1) }.should raise_error(TypeError) + -> { @object.send(@method, nil) }.should.raise(TypeError) + -> { @object.send(@method, 1) }.should.raise(TypeError) end end diff --git a/spec/ruby/shared/file/grpowned.rb b/spec/ruby/shared/file/grpowned.rb index 24e84c28e3..07a5a69e1a 100644 --- a/spec/ruby/shared/file/grpowned.rb +++ b/spec/ruby/shared/file/grpowned.rb @@ -11,11 +11,11 @@ describe :file_grpowned, shared: true do platform_is_not :windows do it "returns true if the file exist" do - @object.send(@method, @file).should be_true + @object.send(@method, @file).should == true end it "accepts an object that has a #to_path method" do - @object.send(@method, mock_to_path(@file)).should be_true + @object.send(@method, mock_to_path(@file)).should == true end it 'takes non primary groups into account' do @@ -33,7 +33,7 @@ describe :file_grpowned, shared: true do platform_is :windows do it "returns false if the file exist" do - @object.send(@method, @file).should be_false + @object.send(@method, @file).should == false end end end diff --git a/spec/ruby/shared/file/identical.rb b/spec/ruby/shared/file/identical.rb index b7a2904839..628abd4f48 100644 --- a/spec/ruby/shared/file/identical.rb +++ b/spec/ruby/shared/file/identical.rb @@ -25,9 +25,9 @@ describe :file_identical, shared: true do end it "returns false if any of the files doesn't exist" do - @object.send(@method, @file1, @non_exist).should be_false - @object.send(@method, @non_exist, @file1).should be_false - @object.send(@method, @non_exist, @non_exist).should be_false + @object.send(@method, @file1, @non_exist).should == false + @object.send(@method, @non_exist, @file1).should == false + @object.send(@method, @non_exist, @non_exist).should == false end it "accepts an object that has a #to_path method" do @@ -35,17 +35,17 @@ describe :file_identical, shared: true do end it "raises an ArgumentError if not passed two arguments" do - -> { @object.send(@method, @file1, @file2, @link) }.should raise_error(ArgumentError) - -> { @object.send(@method, @file1) }.should raise_error(ArgumentError) + -> { @object.send(@method, @file1, @file2, @link) }.should.raise(ArgumentError) + -> { @object.send(@method, @file1) }.should.raise(ArgumentError) end it "raises a TypeError if not passed String types" do - -> { @object.send(@method, 1,1) }.should raise_error(TypeError) + -> { @object.send(@method, 1,1) }.should.raise(TypeError) end it "returns true if both named files are identical" do - @object.send(@method, @file1, @file1).should be_true - @object.send(@method, @link, @link).should be_true - @object.send(@method, @file1, @file2).should be_false + @object.send(@method, @file1, @file1).should == true + @object.send(@method, @link, @link).should == true + @object.send(@method, @file1, @file2).should == false end end diff --git a/spec/ruby/shared/file/size.rb b/spec/ruby/shared/file/size.rb index cba99fe6a5..fa198ed232 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 - -> {@object.send(@method, @missing)}.should raise_error(Errno::ENOENT) + -> {@object.send(@method, @missing)}.should.raise(Errno::ENOENT) end end diff --git a/spec/ruby/shared/file/socket.rb b/spec/ruby/shared/file/socket.rb index 55a1cfd284..ef6c482d1c 100644 --- a/spec/ruby/shared/file/socket.rb +++ b/spec/ruby/shared/file/socket.rb @@ -1,3 +1,33 @@ describe :file_socket, shared: true do - it "accepts an object that has a #to_path method" + it "returns false if the file is not a socket" do + filename = tmp("i_exist") + touch(filename) + + @object.send(@method, filename).should == false + + rm_r filename + end + + it "returns true if the file is a socket" do + require 'socket' + + # We need a really short name here. + # On Linux the path length is limited to 107, see unix(7). + name = tmp("s") + server = UNIXServer.new(name) + + @object.send(@method, name).should == true + + server.close + rm_r name + end + + it "accepts an object that has a #to_path method" do + obj = Object.new + def obj.to_path + __FILE__ + end + + @object.send(@method, obj).should == false + end end diff --git a/spec/ruby/shared/file/world_readable.rb b/spec/ruby/shared/file/world_readable.rb index 1dce7a580f..c8946366ad 100644 --- a/spec/ruby/shared/file/world_readable.rb +++ b/spec/ruby/shared/file/world_readable.rb @@ -14,24 +14,24 @@ describe :file_world_readable, shared: true do platform_is_not :windows do it "returns nil if the file is chmod 600" do File.chmod(0600, @file) - @object.world_readable?(@file).should be_nil + @object.world_readable?(@file).should == nil end it "returns nil if the file is chmod 000" do File.chmod(0000, @file) - @object.world_readable?(@file).should be_nil + @object.world_readable?(@file).should == nil end it "returns nil if the file is chmod 700" do File.chmod(0700, @file) - @object.world_readable?(@file).should be_nil + @object.world_readable?(@file).should == nil end end # 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(Integer) + @object.world_readable?(@file).should.instance_of?(Integer) end it "returns an Integer if the file is a directory and chmod 644" do @@ -39,7 +39,7 @@ describe :file_world_readable, shared: true do Dir.mkdir(dir) Dir.should.exist?(dir) File.chmod(0644, dir) - @object.world_readable?(dir).should be_an_instance_of(Integer) + @object.world_readable?(dir).should.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 7ed252dcf3..fcff09636e 100644 --- a/spec/ruby/shared/file/world_writable.rb +++ b/spec/ruby/shared/file/world_writable.rb @@ -14,23 +14,23 @@ describe :file_world_writable, shared: true do platform_is_not :windows do it "returns nil if the file is chmod 600" do File.chmod(0600, @file) - @object.world_writable?(@file).should be_nil + @object.world_writable?(@file).should == nil end it "returns nil if the file is chmod 000" do File.chmod(0000, @file) - @object.world_writable?(@file).should be_nil + @object.world_writable?(@file).should == nil end it "returns nil if the file is chmod 700" do File.chmod(0700, @file) - @object.world_writable?(@file).should be_nil + @object.world_writable?(@file).should == nil end # 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(Integer) + @object.world_writable?(@file).should.instance_of?(Integer) end it "returns an Integer if the file is a directory and chmod 777" do @@ -38,7 +38,7 @@ describe :file_world_writable, shared: true do Dir.mkdir(dir) Dir.should.exist?(dir) File.chmod(0777, dir) - @object.world_writable?(dir).should be_an_instance_of(Integer) + @object.world_writable?(dir).should.instance_of?(Integer) Dir.rmdir(dir) end end diff --git a/spec/ruby/shared/file/writable_real.rb b/spec/ruby/shared/file/writable_real.rb index b4a0a58c6e..4602996187 100644 --- a/spec/ruby/shared/file/writable_real.rb +++ b/spec/ruby/shared/file/writable_real.rb @@ -16,13 +16,13 @@ describe :file_writable_real, shared: true do end it "raises an ArgumentError if not passed one argument" do - -> { File.writable_real? }.should raise_error(ArgumentError) + -> { File.writable_real? }.should.raise(ArgumentError) end it "raises a TypeError if not passed a String type" do - -> { @object.send(@method, 1) }.should raise_error(TypeError) - -> { @object.send(@method, nil) }.should raise_error(TypeError) - -> { @object.send(@method, false) }.should raise_error(TypeError) + -> { @object.send(@method, 1) }.should.raise(TypeError) + -> { @object.send(@method, nil) }.should.raise(TypeError) + -> { @object.send(@method, false) }.should.raise(TypeError) end platform_is_not :windows do diff --git a/spec/ruby/shared/file/zero.rb b/spec/ruby/shared/file/zero.rb index 6a9399a021..94285c14c5 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 - -> { File.zero? }.should raise_error(ArgumentError) + -> { File.zero? }.should.raise(ArgumentError) end it "raises a TypeError if not passed a String type" do - -> { @object.send(@method, nil) }.should raise_error(TypeError) - -> { @object.send(@method, true) }.should raise_error(TypeError) - -> { @object.send(@method, false) }.should raise_error(TypeError) + -> { @object.send(@method, nil) }.should.raise(TypeError) + -> { @object.send(@method, true) }.should.raise(TypeError) + -> { @object.send(@method, false) }.should.raise(TypeError) end it "returns true inside a block opening a file if it is empty" do @@ -57,7 +57,7 @@ describe :file_zero, shared: true do # See https://bugs.ruby-lang.org/issues/449 for background it "returns true or false for a directory" do - @object.send(@method, @dir).should be_true_or_false + [true, false].should.include? @object.send(@method, @dir) end end diff --git a/spec/ruby/shared/hash/key_error.rb b/spec/ruby/shared/hash/key_error.rb index 54dcb89e91..0044cd5de2 100644 --- a/spec/ruby/shared/hash/key_error.rb +++ b/spec/ruby/shared/hash/key_error.rb @@ -2,21 +2,21 @@ describe :key_error, shared: true do it "raises a KeyError" do -> { @method.call(@object, 'foo') - }.should raise_error(KeyError) + }.should.raise(KeyError) 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) + }.should.raise(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| + }.should.raise(KeyError) { |err| err.key.to_s.should == 'foo' } end diff --git a/spec/ruby/shared/io/putc.rb b/spec/ruby/shared/io/putc.rb index e6012c0098..56902ccad5 100644 --- a/spec/ruby/shared/io/putc.rb +++ b/spec/ruby/shared/io/putc.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary describe :io_putc, shared: true do after :each do @io.close if @io && !@io.closed? @@ -40,18 +40,18 @@ describe :io_putc, shared: true do it "raises IOError on a closed stream" do @io.close - -> { @io_object.send(@method, "a") }.should raise_error(IOError) + -> { @io_object.send(@method, "a") }.should.raise(IOError) end it "raises a TypeError when passed nil" do - -> { @io_object.send(@method, nil) }.should raise_error(TypeError) + -> { @io_object.send(@method, nil) }.should.raise(TypeError) end it "raises a TypeError when passed false" do - -> { @io_object.send(@method, false) }.should raise_error(TypeError) + -> { @io_object.send(@method, false) }.should.raise(TypeError) end it "raises a TypeError when passed true" do - -> { @io_object.send(@method, true) }.should raise_error(TypeError) + -> { @io_object.send(@method, true) }.should.raise(TypeError) end end diff --git a/spec/ruby/shared/kernel/at_exit.rb b/spec/ruby/shared/kernel/at_exit.rb index 29db79bb39..a868ed1e0e 100644 --- a/spec/ruby/shared/kernel/at_exit.rb +++ b/spec/ruby/shared/kernel/at_exit.rb @@ -60,10 +60,7 @@ 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") - - # 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") + result.should.include?("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/kernel/complex.rb b/spec/ruby/shared/kernel/complex.rb index 98ee0b2b3f..6e0764dd3d 100644 --- a/spec/ruby/shared/kernel/complex.rb +++ b/spec/ruby/shared/kernel/complex.rb @@ -2,7 +2,7 @@ describe :kernel_complex, shared: true do it "returns a Complex object" do - @object.send(@method, '9').should be_an_instance_of(Complex) + @object.send(@method, '9').should.instance_of?(Complex) end it "understands integers" do diff --git a/spec/ruby/shared/kernel/equal.rb b/spec/ruby/shared/kernel/equal.rb index 0a70aec639..3b74232922 100644 --- a/spec/ruby/shared/kernel/equal.rb +++ b/spec/ruby/shared/kernel/equal.rb @@ -2,13 +2,13 @@ describe :object_equal, shared: true do it "returns true if other is identical to self" do obj = Object.new - obj.__send__(@method, obj).should be_true + obj.__send__(@method, obj).should == true end it "returns false if other is not identical to self" do a = Object.new b = Object.new - a.__send__(@method, b).should be_false + a.__send__(@method, b).should == false end it "returns true only if self and other are the same object" do diff --git a/spec/ruby/shared/kernel/object_id.rb b/spec/ruby/shared/kernel/object_id.rb index 099df8ff94..6469e49903 100644 --- a/spec/ruby/shared/kernel/object_id.rb +++ b/spec/ruby/shared/kernel/object_id.rb @@ -2,7 +2,7 @@ describe :object_id, shared: true do it "returns an integer" do o1 = @object.new - o1.__send__(@method).should be_kind_of(Integer) + o1.__send__(@method).should.is_a?(Integer) end it "returns the same value on all calls to id for a given object" do diff --git a/spec/ruby/shared/kernel/raise.rb b/spec/ruby/shared/kernel/raise.rb index 1917a4c923..07b6a30de2 100644 --- a/spec/ruby/shared/kernel/raise.rb +++ b/spec/ruby/shared/kernel/raise.rb @@ -7,9 +7,9 @@ describe :kernel_raise, shared: true do -> do @object.raise Exception, "abort" ScratchPad.record :no_abort - end.should raise_error(Exception, "abort") + end.should.raise(Exception, "abort") - ScratchPad.recorded.should be_nil + ScratchPad.recorded.should == nil end it "accepts an exception that implements to_hash" do @@ -19,7 +19,7 @@ describe :kernel_raise, shared: true do end end error = custom_error.new - -> { @object.raise(error) }.should raise_error(custom_error) + -> { @object.raise(error) }.should.raise(custom_error) end it "allows the message parameter to be a hash" do @@ -30,7 +30,7 @@ describe :kernel_raise, shared: true do end end - -> { @object.raise(data_error, {data: 42}) }.should raise_error(data_error) do |ex| + -> { @object.raise(data_error, {data: 42}) }.should.raise(data_error) do |ex| ex.data.should == {data: 42} end end @@ -44,37 +44,22 @@ describe :kernel_raise, shared: true do end end - -> { @object.raise(data_error, data: 42) }.should raise_error(data_error) do |ex| + -> { @object.raise(data_error, data: 42) }.should.raise(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 - -> { @object.raise }.should raise_error(RuntimeError, "") + -> { @object.raise }.should.raise(RuntimeError, "") end it "raises a given Exception instance" do error = RuntimeError.new - -> { @object.raise(error) }.should raise_error(error) + -> { @object.raise(error) }.should.raise(error) end it "raises a RuntimeError if string given" do - -> { @object.raise("a bad thing") }.should raise_error(RuntimeError) + -> { @object.raise("a bad thing") }.should.raise(RuntimeError, "a bad thing") end it "passes no arguments to the constructor when given only an exception class" do @@ -82,69 +67,67 @@ describe :kernel_raise, shared: true do def initialize end end - -> { @object.raise(klass) }.should raise_error(klass) { |e| e.message.should == klass.to_s } + -> { @object.raise(klass) }.should.raise(klass) { |e| e.message.should == klass.to_s } end it "raises a TypeError when passed a non-Exception object" do - -> { @object.raise(Object.new) }.should raise_error(TypeError) + -> { @object.raise(Object.new) }.should.raise(TypeError, "exception class/object expected") + -> { @object.raise(Object.new, "message") }.should.raise(TypeError, "exception class/object expected") + -> { @object.raise(Object.new, "message", []) }.should.raise(TypeError, "exception class/object expected") end it "raises a TypeError when passed true" do - -> { @object.raise(true) }.should raise_error(TypeError) + -> { @object.raise(true) }.should.raise(TypeError, "exception class/object expected") end it "raises a TypeError when passed false" do - -> { @object.raise(false) }.should raise_error(TypeError) + -> { @object.raise(false) }.should.raise(TypeError, "exception class/object expected") end it "raises a TypeError when passed nil" do - -> { @object.raise(nil) }.should raise_error(TypeError) + -> { @object.raise(nil) }.should.raise(TypeError, "exception class/object expected") + end + + it "raises a TypeError when passed a message and an extra argument" do + -> { @object.raise("message", {cause: RuntimeError.new()}) }.should.raise(TypeError, "exception class/object expected") + end + + it "raises TypeError when passed a non-Exception object but it responds to #exception method that doesn't return an instance of Exception class" do + e = Object.new + def e.exception + Array + end + + -> { + @object.raise e + }.should.raise(TypeError, "exception object expected") end 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 - initial_raise_line = __LINE__; Fiber.yield - rescue => raised - begin - raise_again_line = __LINE__; Fiber.yield raised - rescue => raised_again - raised_again - end - end - end - fiber.resume - raised = fiber.raise 'raised' - raised_again = fiber.raise raised - else - begin - initial_raise_line = __LINE__; @object.raise 'raised' - rescue => raised - begin - raise_again_line = __LINE__; @object.raise raised - rescue => raised_again - raised_again - end - end + exception = nil + + begin + raise "raised" + rescue => exception + # Ignore. end - raised_again.backtrace.first.should include("#{__FILE__}:#{initial_raise_line}:") - raised_again.backtrace.first.should_not include("#{__FILE__}:#{raise_again_line}:") + backtrace = exception.backtrace + + begin + raised_exception = @object.raise(exception) + rescue => raised_exception + # Ignore. + end + + raised_exception.backtrace.should == backtrace + raised_exception.should == exception end it "allows Exception, message, and backtrace parameters" do -> do @object.raise(ArgumentError, "message", caller) - end.should raise_error(ArgumentError, "message") + end.should.raise(ArgumentError, "message") end ruby_version_is "3.4" do @@ -152,9 +135,258 @@ describe :kernel_raise, shared: true do it "allows Exception, message, and backtrace_locations parameters" do -> do @object.raise(ArgumentError, "message", locations) - end.should raise_error(ArgumentError, "message") { |error| + end.should.raise(ArgumentError, "message") { |error| error.backtrace_locations.map(&:to_s).should == locations.map(&:to_s) } end end end + +describe :kernel_raise_with_cause, shared: true do + context "without cause keyword argument" do + it "sets cause to nil when there is no previous exception" do + -> do + @object.raise("error without a cause") + end.should.raise(RuntimeError, "error without a cause", cause: nil) + end + + it "supports automatic cause chaining from a previous exception" do + begin + raise StandardError,"first error" + rescue => cause + -> { @object.raise("second error") }.should.raise(RuntimeError, "second error", cause:) + end + end + end + + context "with cause keyword argument" do + it "allows setting exception's cause" do + cause = StandardError.new("original error") + + -> do + @object.raise("new error", cause:) + end.should.raise(RuntimeError, "new error", cause:) + end + + it "allows setting cause to nil" do + -> do + @object.raise("error without a cause", cause: nil) + end.should.raise(RuntimeError, "error without a cause") do |error| + error.cause.should == nil + end + end + + it "raises an ArgumentError when only cause is given" do + cause = StandardError.new("cause") + -> do + @object.raise(cause:) + end.should.raise(ArgumentError, "only cause is given with no arguments") + end + + it "raises an ArgumentError when only cause is given and is nil" do + -> do + @object.raise(cause: nil) + end.should.raise(ArgumentError, "only cause is given with no arguments") + end + + it "raises a TypeError when given cause is not an instance of Exception or nil" do + cause = Object.new + -> do + @object.raise("message", cause:) + end.should.raise(TypeError, "exception object expected") + end + + it "doesn't set given cause when it equals the raised exception" do + cause = StandardError.new("cause") + + -> do + @object.raise(cause, cause:) + end.should.raise(StandardError, "cause", cause: nil) + end + + it "raises ArgumentError when cause creates a circular reference" do + -> { + begin + raise "Error 1" + rescue => error1 + begin + raise "Error 2" + rescue => error2 + begin + raise "Error 3" + rescue => error3 + @object.raise(error1, cause: error3) + end + end + end + }.should.raise(ArgumentError, "circular causes") + end + + it "supports exception class with message and cause" do + cause = StandardError.new("cause message") + + -> do + @object.raise(ArgumentError, "argument error message", cause:) + end.should.raise(ArgumentError, "argument error message", cause:) + end + + it "supports exception class with message, backtrace and cause" do + cause = StandardError.new("cause message") + backtrace = ["line1", "line2"] + + -> do + @object.raise(ArgumentError, "argument error message", backtrace, cause:) + end.should.raise(ArgumentError, "argument error message", cause:) do |error| + error.backtrace.should == backtrace + end + end + + it "supports cause: exception, overriding previous exception" do + custom_error = StandardError.new("custom error") + -> do + begin + raise "first error" + rescue + @object.raise("second error", cause: custom_error) + end + end.should.raise(RuntimeError, "second error", cause: custom_error) + end + + it "supports cause: nil, discarding previous exception" do + -> do + begin + raise "first error" + rescue + # Explicit nil prevents chaining: + @object.raise("second error", cause: nil) + end + end.should.raise(RuntimeError, "second error", cause: nil) + end + end +end + +describe :kernel_raise_across_contexts, shared: true do + ruby_version_is "4.0" do + describe "with cause keyword argument" do + it "uses the cause from the calling context" do + original_cause = nil + result = nil + + # We have no cause ($!) and we don't specify one explicitly either: + @object.raise("second error") do |&block| + begin + begin + raise "first error" + rescue => original_cause + # We have a cause here ($!) but we should ignore it: + block.call + end + rescue => result + # Ignore. + end + end + + result.should.is_a?(RuntimeError) + result.message.should == "second error" + result.cause.should == nil + end + + it "accepts a cause keyword argument that overrides the last exception" do + original_cause = nil + override_cause = StandardError.new("override cause") + result = nil + + begin + raise "outer error" + rescue + # We have an existing cause, but we want to override it: + @object.raise("second error", cause: override_cause) do |&block| + begin + begin + raise "first error" + rescue => original_cause + # We also have an existing cause here: + block.call + end + rescue => result + # Ignore. + end + end + end + + result.should.is_a?(RuntimeError) + result.message.should == "second error" + result.cause.should == override_cause + end + + it "supports automatic cause chaining from calling context" do + result = nil + + @object.raise("new error") do |&block| + begin + begin + raise "original error" + rescue + block.call # Let the context yield/sleep + end + rescue => result + # Ignore. + end + end + + result.should.is_a?(RuntimeError) + result.message.should == "new error" + # Calling context has no current exception: + result.cause.should == nil + end + + it "supports explicit cause: nil to prevent cause chaining" do + result = nil + + begin + raise "calling context error" + rescue + @object.raise("new error", cause: nil) do |&block| + begin + begin + raise "target context error" + rescue + block.call # Let the context yield/sleep + end + rescue => result + # Ignore. + end + end + + result.should.is_a?(RuntimeError) + result.message.should == "new error" + result.cause.should == nil + end + end + + it "raises TypeError when cause is not an Exception" do + -> { + @object.raise("error", cause: "not an exception") do |&block| + begin + block.call # Let the context yield/sleep + rescue + # Ignore - we expect the TypeError to be raised in the calling context + end + end + }.should.raise(TypeError, "exception object expected") + end + + it "raises ArgumentError when only cause is given with no arguments" do + -> { + @object.raise(cause: StandardError.new("cause")) do |&block| + begin + block.call # Let the context yield/sleep + rescue + # Ignore - we expect the ArgumentError to be raised in the calling context + end + end + }.should.raise(ArgumentError, "only cause is given with no arguments") + end + end + end +end diff --git a/spec/ruby/shared/process/abort.rb b/spec/ruby/shared/process/abort.rb index 935637e1c2..19f9f1e6a5 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 - -> { @object.abort }.should raise_error(SystemExit) + -> { @object.abort }.should.raise(SystemExit) end it "sets the exception message to the given message" do - -> { @object.abort "message" }.should raise_error { |e| e.message.should == "message" } + -> { @object.abort "message" }.should.raise { |e| e.message.should == "message" } end it "sets the exception status code of 1" do - -> { @object.abort }.should raise_error { |e| e.status.should == 1 } + -> { @object.abort }.should.raise { |e| e.status.should == 1 } end it "prints the specified message to STDERR" do - -> { @object.abort "a message" }.should raise_error(SystemExit) + -> { @object.abort "a message" }.should.raise(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") - -> { @object.abort str }.should raise_error(SystemExit, "message") + -> { @object.abort str }.should.raise(SystemExit, "message") end it "raises TypeError when given a non-String object" do - -> { @object.abort 123 }.should raise_error(TypeError) + -> { @object.abort 123 }.should.raise(TypeError) end end diff --git a/spec/ruby/shared/process/exit.rb b/spec/ruby/shared/process/exit.rb index 1e073614a3..cacf2f8774 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 - -> { @object.exit }.should raise_error(SystemExit) { |e| + -> { @object.exit }.should.raise(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| - -> { @object.exit(value) }.should raise_error(SystemExit) { |e| + -> { @object.exit(value) }.should.raise(SystemExit) { |e| e.status.should == value } end @@ -15,14 +15,14 @@ describe :process_exit, shared: true do it "raises a SystemExit with the specified boolean status" do { true => 0, false => 1 }.each do |value, status| - -> { @object.exit(value) }.should raise_error(SystemExit) { |e| + -> { @object.exit(value) }.should.raise(SystemExit) { |e| e.status.should == status } end end it "raises a SystemExit with message 'exit'" do - -> { @object.exit }.should raise_error(SystemExit) { |e| + -> { @object.exit }.should.raise(SystemExit) { |e| e.message.should == "exit" } end @@ -30,24 +30,24 @@ describe :process_exit, shared: true do 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) - -> { @object.exit(obj) }.should raise_error(SystemExit) { |e| + -> { @object.exit(obj) }.should.raise(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| - -> { @object.exit(value) }.should raise_error(SystemExit) { |e| + -> { @object.exit(value) }.should.raise(SystemExit) { |e| e.status.should == status } end end it "raises TypeError if can't convert the argument to an Integer" do - -> { @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) + -> { @object.exit(Object.new) }.should.raise(TypeError) + -> { @object.exit('0') }.should.raise(TypeError) + -> { @object.exit([0]) }.should.raise(TypeError) + -> { @object.exit(nil) }.should.raise(TypeError) end it "raises the SystemExit in the main thread if it reaches the top-level handler of another thread" do @@ -75,7 +75,7 @@ describe :process_exit, shared: true do ScratchPad.recorded.should == [:in_thread, :in_main] # the thread also keeps the exception as its value - -> { t.value }.should raise_error(SystemExit) + -> { t.value }.should.raise(SystemExit) end end diff --git a/spec/ruby/shared/process/fork.rb b/spec/ruby/shared/process/fork.rb index 8dbb3d0da4..dd595cd93e 100644 --- a/spec/ruby/shared/process/fork.rb +++ b/spec/ruby/shared/process/fork.rb @@ -3,12 +3,12 @@ describe :process_fork, shared: true do it "returns false from #respond_to?" do # Workaround for Kernel::Method being public and losing the "non-respond_to? magic" mod = @object.class.name == "KernelSpecs::Method" ? Object.new : @object - mod.respond_to?(:fork).should be_false - mod.respond_to?(:fork, true).should be_false + mod.respond_to?(:fork).should == false + mod.respond_to?(:fork, true).should == false end it "raises a NotImplementedError when called" do - -> { @object.fork }.should raise_error(NotImplementedError) + -> { @object.fork }.should.raise(NotImplementedError) end end @@ -74,16 +74,19 @@ describe :process_fork, shared: true do it "marks threads from the parent as killed" do t = Thread.new { sleep } - pid = @object.fork { - touch(@file) do |f| - f.write Thread.current.alive? - f.write t.alive? - end - Process.exit! - } - Process.waitpid(pid) - t.kill - t.join + begin + pid = @object.fork { + touch(@file) do |f| + f.write Thread.current.alive? + f.write t.alive? + end + Process.exit! + } + Process.waitpid(pid) + ensure + t.kill + t.join + end File.read(@file).should == "truefalse" end end diff --git a/spec/ruby/shared/queue/clear.rb b/spec/ruby/shared/queue/clear.rb index 5db5a5b497..742468a859 100644 --- a/spec/ruby/shared/queue/clear.rb +++ b/spec/ruby/shared/queue/clear.rb @@ -3,9 +3,9 @@ describe :queue_clear, shared: true do queue = @object.call queue << Object.new queue << 1 - queue.empty?.should be_false + queue.empty?.should == false queue.clear - queue.empty?.should be_true + queue.empty?.should == true end # TODO: test for atomicity of Queue#clear diff --git a/spec/ruby/shared/queue/close.rb b/spec/ruby/shared/queue/close.rb index 0e7c69acba..1b0908c27c 100644 --- a/spec/ruby/shared/queue/close.rb +++ b/spec/ruby/shared/queue/close.rb @@ -2,9 +2,9 @@ describe :queue_close, shared: true do it "may be called multiple times" do q = @object.call q.close - q.closed?.should be_true + q.closed?.should == true q.close # no effect - q.closed?.should be_true + q.closed?.should == true end it "returns self" do diff --git a/spec/ruby/shared/queue/closed.rb b/spec/ruby/shared/queue/closed.rb index b3cea0c524..8a7d65055f 100644 --- a/spec/ruby/shared/queue/closed.rb +++ b/spec/ruby/shared/queue/closed.rb @@ -1,12 +1,12 @@ describe :queue_closed?, shared: true do it "returns false initially" do queue = @object.call - queue.closed?.should be_false + queue.closed?.should == false end it "returns true when the queue is closed" do queue = @object.call queue.close - queue.closed?.should be_true + queue.closed?.should == true end end diff --git a/spec/ruby/shared/queue/deque.rb b/spec/ruby/shared/queue/deque.rb index 0abba5301e..45cbc4a995 100644 --- a/spec/ruby/shared/queue/deque.rb +++ b/spec/ruby/shared/queue/deque.rb @@ -65,66 +65,64 @@ describe :queue_deq, shared: true do 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: TIME_TOLERANCE).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 - - Thread.new { - q.send(@method, timeout: 0.001).should == nil - }.join - end - - it "does nothing if the timeout is nil" do - q = @object.call - t = Thread.new { - q.send(@method, timeout: nil).should == 1 - } - Thread.pass until t.status == "sleep" && q.num_waiting == 1 - 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 - - it "returns nil for a closed empty queue" do - q = @object.call - q.close - q.send(@method, timeout: 0).should == nil - end + it "returns an item if one is available in time" do + q = @object.call + + t = Thread.new { + q.send(@method, timeout: TIME_TOLERANCE).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 + + Thread.new { + q.send(@method, timeout: 0.001).should == nil + }.join + end + + it "does nothing if the timeout is nil" do + q = @object.call + t = Thread.new { + q.send(@method, timeout: nil).should == 1 + } + Thread.pass until t.status == "sleep" && q.num_waiting == 1 + 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_consistent_error(TypeError, "no implicit conversion of String into Float") + + -> { + q.send(@method, timeout: false) + }.should raise_consistent_error(TypeError, "no implicit conversion of false into Float") + end + + it "raise ArgumentError if non_block = true is passed too" do + q = @object.call + -> { + q.send(@method, true, timeout: 1) + }.should.raise(ArgumentError, "can't set a timeout if non_block is enabled") + end + + it "returns nil for a closed empty queue" do + q = @object.call + q.close + q.send(@method, timeout: 0).should == nil end end @@ -139,7 +137,7 @@ describe :queue_deq, shared: true do it "raises a ThreadError if the queue is empty" do q = @object.call - -> { q.send(@method, true) }.should raise_error(ThreadError) + -> { q.send(@method, true) }.should.raise(ThreadError) end it "removes an item from a closed queue" do @@ -152,15 +150,15 @@ describe :queue_deq, shared: true do it "raises a ThreadError for a closed empty queue" do q = @object.call q.close - -> { q.send(@method, true) }.should raise_error(ThreadError) + -> { q.send(@method, true) }.should.raise(ThreadError) end it "converts true-ish non_blocking argument to true" do q = @object.call - -> { q.send(@method, true) }.should raise_error(ThreadError) - -> { q.send(@method, 1) }.should raise_error(ThreadError) - -> { q.send(@method, "") }.should raise_error(ThreadError) + -> { q.send(@method, true) }.should.raise(ThreadError) + -> { q.send(@method, 1) }.should.raise(ThreadError) + -> { q.send(@method, "") }.should.raise(ThreadError) end end end diff --git a/spec/ruby/shared/queue/empty.rb b/spec/ruby/shared/queue/empty.rb index 4acd831d48..052ce6ac23 100644 --- a/spec/ruby/shared/queue/empty.rb +++ b/spec/ruby/shared/queue/empty.rb @@ -1,12 +1,12 @@ describe :queue_empty?, shared: true do it "returns true on an empty Queue" do queue = @object.call - queue.empty?.should be_true + queue.empty?.should == true end it "returns false when Queue is not empty" do queue = @object.call queue << Object.new - queue.empty?.should be_false + queue.empty?.should == false end end diff --git a/spec/ruby/shared/queue/enque.rb b/spec/ruby/shared/queue/enque.rb index 8aba02e544..61d962b788 100644 --- a/spec/ruby/shared/queue/enque.rb +++ b/spec/ruby/shared/queue/enque.rb @@ -13,6 +13,6 @@ describe :queue_enq, shared: true do q.close -> { q.send @method, Object.new - }.should raise_error(ClosedQueueError) + }.should.raise(ClosedQueueError) end end diff --git a/spec/ruby/shared/queue/freeze.rb b/spec/ruby/shared/queue/freeze.rb index 4c506a4235..7f1f72fd7e 100644 --- a/spec/ruby/shared/queue/freeze.rb +++ b/spec/ruby/shared/queue/freeze.rb @@ -1,18 +1,8 @@ describe :queue_freeze, shared: true do - ruby_version_is ""..."3.3" do - it "can be frozen" do - queue = @object.call + it "raises an exception when freezing" do + queue = @object.call + -> { queue.freeze - queue.should.frozen? - end - end - - ruby_version_is "3.3" do - it "raises an exception when freezing" do - queue = @object.call - -> { - queue.freeze - }.should raise_error(TypeError, "cannot freeze #{queue}") - end + }.should.raise(TypeError, "cannot freeze #{queue}") end end diff --git a/spec/ruby/shared/sizedqueue/enque.rb b/spec/ruby/shared/sizedqueue/enque.rb index 2f25517675..014056acda 100644 --- a/spec/ruby/shared/sizedqueue/enque.rb +++ b/spec/ruby/shared/sizedqueue/enque.rb @@ -29,7 +29,7 @@ describe :sizedqueue_enq, shared: true do q.size.should == 1 add_to_queue.call q.size.should == 2 - add_to_queue.should raise_error(ThreadError) + add_to_queue.should.raise(ThreadError) end it "interrupts enqueuing threads with ClosedQueueError when the queue is closed" do @@ -37,7 +37,7 @@ describe :sizedqueue_enq, shared: true do q << 1 t = Thread.new { - -> { q.send(@method, 2) }.should raise_error(ClosedQueueError, "queue closed") + -> { q.send(@method, 2) }.should.raise(ClosedQueueError, "queue closed") } Thread.pass until q.num_waiting == 1 @@ -49,83 +49,81 @@ describe :sizedqueue_enq, shared: true do 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: TIME_TOLERANCE).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 available 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 - 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") - 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 - - it "raise ClosedQueueError when closed before enqueued" do - q = @object.call(1) - q.close - -> { q.send(@method, 2, timeout: 1) }.should raise_error(ClosedQueueError, "queue closed") - end - - it "interrupts enqueuing threads with ClosedQueueError when the queue is closed" do - q = @object.call(1) - q << 1 - - t = Thread.new { - -> { q.send(@method, 1, timeout: TIME_TOLERANCE) }.should raise_error(ClosedQueueError, "queue closed") - } - - Thread.pass until q.num_waiting == 1 - - q.close - - t.join - q.pop.should == 1 - end + 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: TIME_TOLERANCE).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 available 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 + 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_consistent_error(TypeError, "no implicit conversion of String into Float") + + -> { + q.send(@method, 2, timeout: false) + }.should raise_consistent_error(TypeError, "no implicit conversion of false into Float") + 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(ArgumentError, "can't set a timeout if non_block is enabled") + end + + it "raise ClosedQueueError when closed before enqueued" do + q = @object.call(1) + q.close + -> { q.send(@method, 2, timeout: 1) }.should.raise(ClosedQueueError, "queue closed") + end + + it "interrupts enqueuing threads with ClosedQueueError when the queue is closed" do + q = @object.call(1) + q << 1 + + t = Thread.new { + -> { q.send(@method, 1, timeout: TIME_TOLERANCE) }.should.raise(ClosedQueueError, "queue closed") + } + + Thread.pass until q.num_waiting == 1 + + q.close + + t.join + q.pop.should == 1 end end end diff --git a/spec/ruby/shared/sizedqueue/max.rb b/spec/ruby/shared/sizedqueue/max.rb index ea10d24be0..167f669275 100644 --- a/spec/ruby/shared/sizedqueue/max.rb +++ b/spec/ruby/shared/sizedqueue/max.rb @@ -19,7 +19,7 @@ describe :sizedqueue_max=, shared: true do q.enq 2 q.enq 3 q.max = 2 - (q.size > q.max).should be_true + (q.size > q.max).should == true q.deq.should == 1 q.deq.should == 2 q.deq.should == 3 @@ -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) - -> { q.max = "foo" }.should raise_error(TypeError) - -> { q.max = Object.new }.should raise_error(TypeError) + -> { q.max = "foo" }.should.raise(TypeError) + -> { q.max = Object.new }.should.raise(TypeError) end it "raises an argument error when set to zero" do q = @object.call(5) q.max.should == 5 - -> { q.max = 0 }.should raise_error(ArgumentError) + -> { q.max = 0 }.should.raise(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 - -> { q.max = -1 }.should raise_error(ArgumentError) + -> { q.max = -1 }.should.raise(ArgumentError) q.max.should == 5 end end diff --git a/spec/ruby/shared/sizedqueue/new.rb b/spec/ruby/shared/sizedqueue/new.rb index 2573194efb..2904422a45 100644 --- a/spec/ruby/shared/sizedqueue/new.rb +++ b/spec/ruby/shared/sizedqueue/new.rb @@ -1,7 +1,7 @@ describe :sizedqueue_new, shared: true do 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") }.should.raise(TypeError) + -> { @object.call(Object.new) }.should.raise(TypeError) @object.call(12.9).max.should == 12 object = Object.new @@ -10,14 +10,14 @@ describe :sizedqueue_new, shared: true do end it "raises an argument error when no argument is given" do - -> { @object.call }.should raise_error(ArgumentError) + -> { @object.call }.should.raise(ArgumentError) end it "raises an argument error when the given argument is zero" do - -> { @object.call(0) }.should raise_error(ArgumentError) + -> { @object.call(0) }.should.raise(ArgumentError) end it "raises an argument error when the given argument is negative" do - -> { @object.call(-1) }.should raise_error(ArgumentError) + -> { @object.call(-1) }.should.raise(ArgumentError) end end diff --git a/spec/ruby/shared/string/end_with.rb b/spec/ruby/shared/string/end_with.rb index 08f43c1bce..8eb9693395 100644 --- a/spec/ruby/shared/string/end_with.rb +++ b/spec/ruby/shared/string/end_with.rb @@ -30,9 +30,9 @@ describe :end_with, shared: true do 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) + -> { "hello".send(@method).end_with?(1) }.should.raise(TypeError) + -> { "hello".send(@method).end_with?(["o"]) }.should.raise(TypeError) + -> { "hello".send(@method).end_with?(1, nil, "o") }.should.raise(TypeError) end it "uses only the needed arguments" do @@ -49,7 +49,7 @@ describe :end_with, shared: true do pat = "ア".encode Encoding::EUC_JP -> do "あれ".send(@method).end_with?(pat) - end.should raise_error(Encoding::CompatibilityError) + end.should.raise(Encoding::CompatibilityError) end it "checks that we are starting to match at the head of a character" do diff --git a/spec/ruby/shared/string/start_with.rb b/spec/ruby/shared/string/start_with.rb index 4b947a3bbf..fe12e28969 100644 --- a/spec/ruby/shared/string/start_with.rb +++ b/spec/ruby/shared/string/start_with.rb @@ -26,9 +26,9 @@ describe :start_with, shared: true do 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) + -> { "hello".send(@method).start_with?(1) }.should.raise(TypeError) + -> { "hello".send(@method).start_with?(["h"]) }.should.raise(TypeError) + -> { "hello".send(@method).start_with?(1, nil, "h") }.should.raise(TypeError) end it "uses only the needed arguments" do @@ -60,25 +60,17 @@ describe :start_with, shared: true do 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 + "test-1337".send(@method).start_with?(regexp).should == true + Regexp.last_match.should_not == 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 + "test-asdf".send(@method).start_with?(regexp).should == false + Regexp.last_match.should == nil + $1.should == nil end - ruby_version_is ""..."3.3" do - it "does not check that we are not matching part of a character" do - "\xC3\xA9".send(@method).should.start_with?("\xC3") - end - end - - ruby_version_is "3.3" do # #19784 - it "checks that we are not matching part of a character" do - "\xC3\xA9".send(@method).should_not.start_with?("\xC3") - end + it "checks that we are not matching part of a character" do + "\xC3\xA9".send(@method).should_not.start_with?("\xC3") end end diff --git a/spec/ruby/shared/string/times.rb b/spec/ruby/shared/string/times.rb index 4814f894cf..0a16ba8b82 100644 --- a/spec/ruby/shared/string/times.rb +++ b/spec/ruby/shared/string/times.rb @@ -18,14 +18,14 @@ describe :string_times, shared: true do end it "raises an ArgumentError when given integer is negative" do - -> { @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) + -> { @object.call("cool", -3) }.should.raise(ArgumentError) + -> { @object.call("cool", -3.14) }.should.raise(ArgumentError) + -> { @object.call("cool", min_long) }.should.raise(ArgumentError) end it "raises a RangeError when given integer is a Bignum" do - -> { @object.call("cool", 999999999999999999999) }.should raise_error(RangeError) - -> { @object.call("", 999999999999999999999) }.should raise_error(RangeError) + -> { @object.call("cool", 999999999999999999999) }.should.raise(RangeError) + -> { @object.call("", 999999999999999999999) }.should.raise(RangeError) end it "works with huge long values when string is empty" do @@ -33,26 +33,26 @@ describe :string_times, shared: true do end 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) + @object.call(MyString.new("cool"), 0).should.instance_of?(String) + @object.call(MyString.new("cool"), 1).should.instance_of?(String) + @object.call(MyString.new("cool"), 2).should.instance_of?(String) end it "returns a String in the same encoding as self" do str = "\xE3\x81\x82".dup.force_encoding Encoding::UTF_8 result = @object.call(str, 2) - result.encoding.should equal(Encoding::UTF_8) + result.encoding.should.equal?(Encoding::UTF_8) end platform_is c_long_size: 32 do it "raises an ArgumentError if the length of the resulting string doesn't fit into a long" do - -> { @object.call("abc", (2 ** 31) - 1) }.should raise_error(ArgumentError) + -> { @object.call("abc", (2 ** 31) - 1) }.should.raise(ArgumentError) end end platform_is c_long_size: 64 do it "raises an ArgumentError if the length of the resulting string doesn't fit into a long" do - -> { @object.call("abc", (2 ** 63) - 1) }.should raise_error(ArgumentError) + -> { @object.call("abc", (2 ** 63) - 1) }.should.raise(ArgumentError) end end end diff --git a/spec/ruby/shared/types/rb_num2dbl_fails.rb b/spec/ruby/shared/types/rb_num2dbl_fails.rb index ec7cc11986..4d4856fa6c 100644 --- a/spec/ruby/shared/types/rb_num2dbl_fails.rb +++ b/spec/ruby/shared/types/rb_num2dbl_fails.rb @@ -7,11 +7,11 @@ describe :rb_num2dbl_fails, shared: true do it "fails if string is provided" do - -> { @object.call("123") }.should raise_error(TypeError, "no implicit conversion to float from string") + -> { @object.call("123") }.should raise_consistent_error(TypeError, "no implicit conversion of String into Float") end it "fails if boolean is provided" do - -> { @object.call(true) }.should raise_error(TypeError, "no implicit conversion to float from true") - -> { @object.call(false) }.should raise_error(TypeError, "no implicit conversion to float from false") + -> { @object.call(true) }.should raise_consistent_error(TypeError, "no implicit conversion of true into Float") + -> { @object.call(false) }.should raise_consistent_error(TypeError, "no implicit conversion of false into Float") end end |
