From b7d6d52322fab1c26f94680cc48b691d388a547b Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Thu, 4 Jun 2026 17:45:38 +0200 Subject: [PATCH 1/2] Move generic format/sprintf warn specs to shared examples Also use the `complain` matcher instead of `ruby_exe` --- core/kernel/format_spec.rb | 32 -------------------------------- core/kernel/shared/sprintf.rb | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/core/kernel/format_spec.rb b/core/kernel/format_spec.rb index 35c752b1a..7fe5bfb5e 100644 --- a/core/kernel/format_spec.rb +++ b/core/kernel/format_spec.rb @@ -12,36 +12,4 @@ it "is accessible as a module function" do Kernel.format("%s", "hello").should == "hello" end - - describe "when $VERBOSE is true" do - it "warns if too many arguments are passed" do - code = <<~RUBY - $VERBOSE = true - format("test", 1) - RUBY - - ruby_exe(code, args: "2>&1").should.include?("warning: too many arguments for format string") - end - - it "does not warns if too many keyword arguments are passed" do - code = <<~RUBY - $VERBOSE = true - format("test %{test}", test: 1, unused: 2) - RUBY - - ruby_exe(code, args: "2>&1").should_not.include?("warning") - end - - ruby_bug "#20593", ""..."3.4" do - it "doesn't warns if keyword arguments are passed and none are used" do - code = <<~RUBY - $VERBOSE = true - format("test", test: 1) - format("test", {}) - RUBY - - ruby_exe(code, args: "2>&1").should_not.include?("warning") - end - end - end end diff --git a/core/kernel/shared/sprintf.rb b/core/kernel/shared/sprintf.rb index b40bd95f5..e57334c5a 100644 --- a/core/kernel/shared/sprintf.rb +++ b/core/kernel/shared/sprintf.rb @@ -1031,4 +1031,27 @@ def obj.to_str; end it "does not raise error when passed more arguments than needed" do sprintf("%s %d %c", "string", 2, "c", []).should == "string 2 c" end + + describe "when $VERBOSE is true" do + it "warns if too many arguments are passed" do + -> { + format("test", 1) + }.should complain(/too many arguments for format string/, verbose: true) + end + + it "does not warns if too many keyword arguments are passed" do + -> { + format("test %{test}", test: 1, unused: 2) + }.should_not complain(verbose: true) + end + + ruby_bug "#20593", ""..."3.4" do + it "doesn't warns if keyword arguments are passed and none are used" do + -> { + format("test", test: 1) + format("test", {}) + }.should_not complain(verbose: true) + end + end + end end From 2e460a907af4e0188cdf8da9f7eaf9dc011517fe Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Thu, 4 Jun 2026 22:05:24 +0200 Subject: [PATCH 2/2] Clean up remaining core aliased methods And also one for zlib. Previously I just checked core/*/shared. But some didn't use that, and others I skipped by accident. I used the following script (with `--disable-gems`) to find aliased methods: ```rb require "objspace" r = {} ObjectSpace.each_object(Module) do |mod| next if mod.inspect.include?(" do + Dir.delete DirSpecs.mock_rmdir("nonempty") + end.should.raise(Errno::ENOTEMPTY) + end + + it "raises an Errno::ENOENT when trying to remove a non-existing directory" do + -> do + Dir.delete DirSpecs.nonexistent + end.should.raise(Errno::ENOENT) + end + + it "raises an Errno::ENOTDIR when trying to remove a non-directory" do + file = DirSpecs.mock_rmdir("nonempty/regular") + touch(file) + -> do + Dir.delete file + end.should.raise(Errno::ENOTDIR) + end + + # this won't work on Windows, since chmod(0000) does not remove all permissions + platform_is_not :windows do + as_user do + it "raises an Errno::EACCES if lacking adequate permissions to remove the directory" do + parent = DirSpecs.mock_rmdir("noperm") + child = DirSpecs.mock_rmdir("noperm", "child") + File.chmod(0000, parent) + -> do + Dir.delete child + end.should.raise(Errno::EACCES) + end + end + end end diff --git a/core/dir/rmdir_spec.rb b/core/dir/rmdir_spec.rb index 08cd1a5bc..c31067ca2 100644 --- a/core/dir/rmdir_spec.rb +++ b/core/dir/rmdir_spec.rb @@ -1,15 +1,7 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' -require_relative 'shared/delete' describe "Dir.rmdir" do - before :all do - DirSpecs.create_mock_dirs + it "is an alias of Dir.delete" do + Dir.method(:rmdir).should == Dir.method(:delete) end - - after :all do - DirSpecs.delete_mock_dirs - end - - it_behaves_like :dir_delete, :rmdir end diff --git a/core/dir/shared/delete.rb b/core/dir/shared/delete.rb deleted file mode 100644 index ba013e861..000000000 --- a/core/dir/shared/delete.rb +++ /dev/null @@ -1,53 +0,0 @@ -describe :dir_delete, shared: true do - before :each do - DirSpecs.rmdir_dirs true - end - - after :each do - DirSpecs.rmdir_dirs false - end - - it "removes empty directories" do - Dir.send(@method, DirSpecs.mock_rmdir("empty")).should == 0 - end - - it "calls #to_path on non-String arguments" do - p = mock('path') - p.should_receive(:to_path).and_return(DirSpecs.mock_rmdir("empty")) - Dir.send(@method, p) - end - - it "raises an Errno::ENOTEMPTY when trying to remove a nonempty directory" do - -> do - Dir.send @method, DirSpecs.mock_rmdir("nonempty") - end.should.raise(Errno::ENOTEMPTY) - end - - it "raises an Errno::ENOENT when trying to remove a non-existing directory" do - -> do - Dir.send @method, DirSpecs.nonexistent - end.should.raise(Errno::ENOENT) - end - - it "raises an Errno::ENOTDIR when trying to remove a non-directory" do - file = DirSpecs.mock_rmdir("nonempty/regular") - touch(file) - -> do - Dir.send @method, file - end.should.raise(Errno::ENOTDIR) - end - - # this won't work on Windows, since chmod(0000) does not remove all permissions - platform_is_not :windows do - as_user do - it "raises an Errno::EACCES if lacking adequate permissions to remove the directory" do - parent = DirSpecs.mock_rmdir("noperm") - child = DirSpecs.mock_rmdir("noperm", "child") - File.chmod(0000, parent) - -> do - Dir.send @method, child - end.should.raise(Errno::EACCES) - end - end - end -end diff --git a/core/dir/unlink_spec.rb b/core/dir/unlink_spec.rb index 79027e020..d9cd1b1a8 100644 --- a/core/dir/unlink_spec.rb +++ b/core/dir/unlink_spec.rb @@ -1,15 +1,7 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' -require_relative 'shared/delete' describe "Dir.unlink" do - before :all do - DirSpecs.create_mock_dirs + it "is an alias of Dir.delete" do + Dir.method(:unlink).should == Dir.method(:delete) end - - after :all do - DirSpecs.delete_mock_dirs - end - - it_behaves_like :dir_delete, :unlink end diff --git a/core/false/inspect_spec.rb b/core/false/inspect_spec.rb index 4cbb55d43..70f4aa015 100644 --- a/core/false/inspect_spec.rb +++ b/core/false/inspect_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' describe "FalseClass#inspect" do - it "returns the string 'false'" do - false.inspect.should == "false" + it "is an alias of FalseClass#to_s" do + false.method(:inspect).should == false.method(:to_s) end end diff --git a/core/false/xor_spec.rb b/core/false/xor_spec.rb index 1b87b9f41..d8432ca32 100644 --- a/core/false/xor_spec.rb +++ b/core/false/xor_spec.rb @@ -1,11 +1,7 @@ require_relative '../../spec_helper' describe "FalseClass#^" do - it "returns false if other is nil or false, otherwise true" do - (false ^ false).should == false - (false ^ true).should == true - (false ^ nil).should == false - (false ^ "").should == true - (false ^ mock('x')).should == true + it "is an alias of FalseClass#|" do + false.method(:^).should == false.method(:|) end end diff --git a/core/file/zero_spec.rb b/core/file/zero_spec.rb index 01c7505ef..09b0decf4 100644 --- a/core/file/zero_spec.rb +++ b/core/file/zero_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' -require_relative '../../shared/file/zero' describe "File.zero?" do - it_behaves_like :file_zero, :zero?, File - it_behaves_like :file_zero_missing, :zero?, File + it "is an alias of File.empty?" do + File.method(:zero?).should == File.method(:empty?) + end end diff --git a/core/filetest/empty_spec.rb b/core/filetest/empty_spec.rb new file mode 100644 index 000000000..2c7fbe0dc --- /dev/null +++ b/core/filetest/empty_spec.rb @@ -0,0 +1,7 @@ +require_relative '../../spec_helper' +require_relative '../../shared/file/zero' + +describe "FileTest.empty?" do + it_behaves_like :file_zero, :empty?, FileTest + it_behaves_like :file_zero_missing, :empty?, FileTest +end diff --git a/core/filetest/zero_spec.rb b/core/filetest/zero_spec.rb index 92cab67f1..de024c25f 100644 --- a/core/filetest/zero_spec.rb +++ b/core/filetest/zero_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' -require_relative '../../shared/file/zero' describe "FileTest.zero?" do - it_behaves_like :file_zero, :zero?, FileTest - it_behaves_like :file_zero_missing, :zero?, FileTest + it "is an alias of FileTest.empty?" do + FileTest.method(:zero?).should == FileTest.method(:empty?) + end end diff --git a/core/integer/inspect_spec.rb b/core/integer/inspect_spec.rb new file mode 100644 index 000000000..0b0d5cc7a --- /dev/null +++ b/core/integer/inspect_spec.rb @@ -0,0 +1,7 @@ +require_relative '../../spec_helper' + +describe "Integer#inspect" do + it "is an alias of Integer#to_s" do + Integer.instance_method(:inspect).should == Integer.instance_method(:to_s) + end +end diff --git a/core/io/eof_spec.rb b/core/io/eof_spec.rb index c8955abde..561daa4ec 100644 --- a/core/io/eof_spec.rb +++ b/core/io/eof_spec.rb @@ -105,3 +105,9 @@ @r.should.eof? end end + +describe "IO#eof" do + it "is an alias of IO#eof?" do + IO.instance_method(:eof).should == IO.instance_method(:eof?) + end +end diff --git a/core/io/to_i_spec.rb b/core/io/to_i_spec.rb index 1d0cf2a1f..b271112a8 100644 --- a/core/io/to_i_spec.rb +++ b/core/io/to_i_spec.rb @@ -1,12 +1,7 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' describe "IO#to_i" do - it "returns the numeric file descriptor of the given IO object" do - $stdout.to_i.should == 1 - end - - it "raises IOError on closed stream" do - -> { IOSpecs.closed_io.to_i }.should.raise(IOError) + it "is an alias of IO#fileno" do + IO.instance_method(:to_i).should == IO.instance_method(:fileno) end end diff --git a/core/io/to_path_spec.rb b/core/io/to_path_spec.rb new file mode 100644 index 000000000..ec6dffc11 --- /dev/null +++ b/core/io/to_path_spec.rb @@ -0,0 +1,7 @@ +require_relative '../../spec_helper' + +describe "IO#to_path" do + it "is an alias of IO#path" do + IO.instance_method(:to_path).should == IO.instance_method(:path) + end +end diff --git a/core/kernel/fail_spec.rb b/core/kernel/fail_spec.rb index ac379b67d..2d117d26c 100644 --- a/core/kernel/fail_spec.rb +++ b/core/kernel/fail_spec.rb @@ -1,42 +1,13 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' describe "Kernel#fail" do - it "is a private method" do - Kernel.private_instance_methods(false).should.include?(:fail) - end - - it "raises a RuntimeError" do - -> { fail }.should.raise(RuntimeError) - end - - it "accepts an Object with an exception method returning an Exception" do - obj = Object.new - def obj.exception(msg) - StandardError.new msg - end - -> { fail obj, "..." }.should.raise(StandardError, "...") - end - - it "instantiates the specified exception class" do - error_class = Class.new(RuntimeError) - -> { fail error_class }.should.raise(error_class) - end - - it "uses the specified message" do - -> { - begin - fail "the duck is not irish." - rescue => e - e.message.should == "the duck is not irish." - raise - else - raise Exception - end - }.should.raise(RuntimeError) + it "is an alias of Kernel#raise" do + Kernel.instance_method(:fail).should == Kernel.instance_method(:raise) end end describe "Kernel.fail" do - it "needs to be reviewed for spec completeness" + it "is an alias of Kernel.raise" do + Kernel.method(:fail).should == Kernel.method(:raise) + end end diff --git a/core/kernel/format_spec.rb b/core/kernel/format_spec.rb index 7fe5bfb5e..a311f3c3d 100644 --- a/core/kernel/format_spec.rb +++ b/core/kernel/format_spec.rb @@ -1,15 +1,13 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' -# NOTE: most specs are in sprintf_spec.rb, this is just an alias describe "Kernel#format" do - it "is a private method" do - Kernel.private_instance_methods(false).should.include?(:format) + it "is an alias of Kernel#sprintf" do + Kernel.instance_method(:format).should == Kernel.instance_method(:sprintf) end end describe "Kernel.format" do - it "is accessible as a module function" do - Kernel.format("%s", "hello").should == "hello" + it "is an alias of Kernel.sprintf" do + Kernel.method(:format).should == Kernel.method(:sprintf) end end diff --git a/core/module/inspect_spec.rb b/core/module/inspect_spec.rb new file mode 100644 index 000000000..68c8494c9 --- /dev/null +++ b/core/module/inspect_spec.rb @@ -0,0 +1,7 @@ +require_relative '../../spec_helper' + +describe "Module#inspect" do + it "is an alias of Module#to_s" do + Module.instance_method(:inspect).should == Module.instance_method(:to_s) + end +end diff --git a/core/nil/xor_spec.rb b/core/nil/xor_spec.rb index b45da9d44..31ce33e97 100644 --- a/core/nil/xor_spec.rb +++ b/core/nil/xor_spec.rb @@ -1,11 +1,7 @@ require_relative '../../spec_helper' describe "NilClass#^" do - it "returns false if other is nil or false, otherwise true" do - (nil ^ nil).should == false - (nil ^ true).should == true - (nil ^ false).should == false - (nil ^ "").should == true - (nil ^ mock('x')).should == true + it "is an alias of NilClass#|" do + nil.method(:^).should == nil.method(:|) end end diff --git a/core/numeric/modulo_spec.rb b/core/numeric/modulo_spec.rb index e3dc7e56f..0baf96dc1 100644 --- a/core/numeric/modulo_spec.rb +++ b/core/numeric/modulo_spec.rb @@ -1,7 +1,12 @@ require_relative '../../spec_helper' -require_relative 'fixtures/classes' -describe :numeric_modulo_19, shared: true do +describe "Numeric#modulo" do + it "is an alias of Numeric#%" do + Numeric.instance_method(:modulo).should == Numeric.instance_method(:%) + end +end + +describe "Numeric#%" do it "returns self - other * self.div(other)" do s = mock_numeric('self') o = mock_numeric('other') @@ -11,14 +16,6 @@ s.should_receive(:div).with(o).and_return(n3) o.should_receive(:*).with(n3).and_return(n4) s.should_receive(:-).with(n4).and_return(n5) - s.send(@method, o).should == n5 + (s % o).should == n5 end end - -describe "Numeric#modulo" do - it_behaves_like :numeric_modulo_19, :modulo -end - -describe "Numeric#%" do - it_behaves_like :numeric_modulo_19, :% -end diff --git a/core/objectspace/weakmap/each_pair_spec.rb b/core/objectspace/weakmap/each_pair_spec.rb index ea29edbd2..272669ad0 100644 --- a/core/objectspace/weakmap/each_pair_spec.rb +++ b/core/objectspace/weakmap/each_pair_spec.rb @@ -1,11 +1,8 @@ require_relative '../../../spec_helper' -require_relative 'shared/members' -require_relative 'shared/each' describe "ObjectSpace::WeakMap#each_pair" do - it_behaves_like :weakmap_members, -> map { a = []; map.each_pair{ |k,v| a << "#{k}#{v}" }; a }, %w[Ax By] -end - -describe "ObjectSpace::WeakMap#each_key" do - it_behaves_like :weakmap_each, :each_pair + it "is an alias of ObjectSpace::WeakMap#each" do + ObjectSpace::WeakMap.instance_method(:each_pair).should == + ObjectSpace::WeakMap.instance_method(:each) + end end diff --git a/core/objectspace/weakmap/each_spec.rb b/core/objectspace/weakmap/each_spec.rb index 46fcb66a6..8493a3615 100644 --- a/core/objectspace/weakmap/each_spec.rb +++ b/core/objectspace/weakmap/each_spec.rb @@ -6,6 +6,6 @@ it_behaves_like :weakmap_members, -> map { a = []; map.each{ |k,v| a << "#{k}#{v}" }; a }, %w[Ax By] end -describe "ObjectSpace::WeakMap#each_key" do +describe "ObjectSpace::WeakMap#each" do it_behaves_like :weakmap_each, :each end diff --git a/core/objectspace/weakmap/each_value_spec.rb b/core/objectspace/weakmap/each_value_spec.rb index 65a1a7f6f..89f2f6ae9 100644 --- a/core/objectspace/weakmap/each_value_spec.rb +++ b/core/objectspace/weakmap/each_value_spec.rb @@ -6,6 +6,6 @@ it_behaves_like :weakmap_members, -> map { a = []; map.each_value{ |k| a << k }; a }, %w[x y] end -describe "ObjectSpace::WeakMap#each_key" do +describe "ObjectSpace::WeakMap#each_value" do it_behaves_like :weakmap_each, :each_value end diff --git a/core/objectspace/weakmap/include_spec.rb b/core/objectspace/weakmap/include_spec.rb index 54ca6b303..1affaef90 100644 --- a/core/objectspace/weakmap/include_spec.rb +++ b/core/objectspace/weakmap/include_spec.rb @@ -1,6 +1,32 @@ require_relative '../../../spec_helper' -require_relative 'shared/include' describe "ObjectSpace::WeakMap#include?" do - it_behaves_like :weakmap_include?, :include? + it "recognizes keys in use" do + map = ObjectSpace::WeakMap.new + key1, key2 = %w[a b].map(&:upcase) + ref1, ref2 = %w[x y] + + map[key1] = ref1 + map.include?(key1).should == true + map[key1] = ref1 + map.include?(key1).should == true + map[key2] = ref2 + map.include?(key2).should == true + end + + it "matches using identity semantics" do + map = ObjectSpace::WeakMap.new + key1, key2 = %w[a a].map(&:upcase) + ref = "x" + map[key1] = ref + map.include?(key2).should == false + end + + it "reports true if the pair exists and the value is nil" do + map = ObjectSpace::WeakMap.new + key = Object.new + map[key] = nil + map.size.should == 1 + map.include?(key).should == true + end end diff --git a/core/objectspace/weakmap/key_spec.rb b/core/objectspace/weakmap/key_spec.rb index 999685ff9..5d38f1fa5 100644 --- a/core/objectspace/weakmap/key_spec.rb +++ b/core/objectspace/weakmap/key_spec.rb @@ -1,6 +1,8 @@ require_relative '../../../spec_helper' -require_relative 'shared/include' describe "ObjectSpace::WeakMap#key?" do - it_behaves_like :weakmap_include?, :key? + it "is an alias of ObjectSpace::WeakMap#include?" do + ObjectSpace::WeakMap.instance_method(:key?).should == + ObjectSpace::WeakMap.instance_method(:include?) + end end diff --git a/core/objectspace/weakmap/length_spec.rb b/core/objectspace/weakmap/length_spec.rb index 3a935648b..8ad47aa9d 100644 --- a/core/objectspace/weakmap/length_spec.rb +++ b/core/objectspace/weakmap/length_spec.rb @@ -1,6 +1,8 @@ require_relative '../../../spec_helper' -require_relative 'shared/size' describe "ObjectSpace::WeakMap#length" do - it_behaves_like :weakmap_size, :length + it "is an alias of ObjectSpace::WeakMap#size" do + ObjectSpace::WeakMap.instance_method(:length).should == + ObjectSpace::WeakMap.instance_method(:size) + end end diff --git a/core/objectspace/weakmap/member_spec.rb b/core/objectspace/weakmap/member_spec.rb index cefb190ce..eaf9a7628 100644 --- a/core/objectspace/weakmap/member_spec.rb +++ b/core/objectspace/weakmap/member_spec.rb @@ -1,6 +1,8 @@ require_relative '../../../spec_helper' -require_relative 'shared/include' describe "ObjectSpace::WeakMap#member?" do - it_behaves_like :weakmap_include?, :member? + it "is an alias of ObjectSpace::WeakMap#include?" do + ObjectSpace::WeakMap.instance_method(:member?).should == + ObjectSpace::WeakMap.instance_method(:include?) + end end diff --git a/core/objectspace/weakmap/shared/include.rb b/core/objectspace/weakmap/shared/include.rb deleted file mode 100644 index 1770eeac8..000000000 --- a/core/objectspace/weakmap/shared/include.rb +++ /dev/null @@ -1,30 +0,0 @@ -describe :weakmap_include?, shared: true do - it "recognizes keys in use" do - map = ObjectSpace::WeakMap.new - key1, key2 = %w[a b].map(&:upcase) - ref1, ref2 = %w[x y] - - map[key1] = ref1 - map.send(@method, key1).should == true - map[key1] = ref1 - map.send(@method, key1).should == true - map[key2] = ref2 - map.send(@method, key2).should == true - end - - it "matches using identity semantics" do - map = ObjectSpace::WeakMap.new - key1, key2 = %w[a a].map(&:upcase) - ref = "x" - map[key1] = ref - map.send(@method, key2).should == false - end - - it "reports true if the pair exists and the value is nil" do - map = ObjectSpace::WeakMap.new - key = Object.new - map[key] = nil - map.size.should == 1 - map.send(@method, key).should == true - end -end diff --git a/core/objectspace/weakmap/shared/size.rb b/core/objectspace/weakmap/shared/size.rb deleted file mode 100644 index 1064f99d1..000000000 --- a/core/objectspace/weakmap/shared/size.rb +++ /dev/null @@ -1,14 +0,0 @@ -describe :weakmap_size, shared: true do - it "is correct" do - map = ObjectSpace::WeakMap.new - key1, key2 = %w[a b].map(&:upcase) - ref1, ref2 = %w[x y] - map.send(@method).should == 0 - map[key1] = ref1 - map.send(@method).should == 1 - map[key1] = ref1 - map.send(@method).should == 1 - map[key2] = ref2 - map.send(@method).should == 2 - end -end diff --git a/core/objectspace/weakmap/size_spec.rb b/core/objectspace/weakmap/size_spec.rb index 1446abaa2..d301750c6 100644 --- a/core/objectspace/weakmap/size_spec.rb +++ b/core/objectspace/weakmap/size_spec.rb @@ -1,6 +1,16 @@ require_relative '../../../spec_helper' -require_relative 'shared/size' describe "ObjectSpace::WeakMap#size" do - it_behaves_like :weakmap_size, :size + it "is correct" do + map = ObjectSpace::WeakMap.new + key1, key2 = %w[a b].map(&:upcase) + ref1, ref2 = %w[x y] + map.size.should == 0 + map[key1] = ref1 + map.size.should == 1 + map[key1] = ref1 + map.size.should == 1 + map[key2] = ref2 + map.size.should == 2 + end end diff --git a/core/process/wait_spec.rb b/core/process/wait_spec.rb index 477acbccf..5a1889487 100644 --- a/core/process/wait_spec.rb +++ b/core/process/wait_spec.rb @@ -22,6 +22,17 @@ Process.wait.should == pid end + it "returns nil when the process has not yet completed and WNOHANG is specified" do + cmd = platform_is(:windows) ? "timeout" : "sleep" + pid = spawn("#{cmd} 5") + begin + Process.wait(pid, Process::WNOHANG).should == nil + Process.kill("KILL", pid) + ensure + Process.wait(pid) + end + end + it "sets $? to a Process::Status" do pid = Process.spawn(ruby_cmd('exit')) Process.wait diff --git a/core/process/waitpid2_spec.rb b/core/process/waitpid2_spec.rb index 45513af66..70fe0fbee 100644 --- a/core/process/waitpid2_spec.rb +++ b/core/process/waitpid2_spec.rb @@ -1,5 +1,7 @@ require_relative '../../spec_helper' describe "Process.waitpid2" do - it "needs to be reviewed for spec completeness" + it "is an alias of Process.wait2" do + Process.method(:waitpid2).should == Process.method(:wait2) + end end diff --git a/core/process/waitpid_spec.rb b/core/process/waitpid_spec.rb index a02147b66..9b2f49e7c 100644 --- a/core/process/waitpid_spec.rb +++ b/core/process/waitpid_spec.rb @@ -1,14 +1,7 @@ require_relative '../../spec_helper' describe "Process.waitpid" do - it "returns nil when the process has not yet completed and WNOHANG is specified" do - cmd = platform_is(:windows) ? "timeout" : "sleep" - pid = spawn("#{cmd} 5") - begin - Process.waitpid(pid, Process::WNOHANG).should == nil - Process.kill("KILL", pid) - ensure - Process.wait(pid) - end + it "is an alias of Process.wait" do + Process.method(:waitpid).should == Process.method(:wait) end end diff --git a/core/queue/deq_spec.rb b/core/queue/deq_spec.rb index a2784e6a6..374611366 100644 --- a/core/queue/deq_spec.rb +++ b/core/queue/deq_spec.rb @@ -1,11 +1,7 @@ require_relative '../../spec_helper' -require_relative '../../shared/queue/deque' -require_relative '../../shared/types/rb_num2dbl_fails' describe "Queue#deq" do - it_behaves_like :queue_deq, :deq, -> { Queue.new } -end - -describe "Queue operations with timeout" do - it_behaves_like :rb_num2dbl_fails, nil, -> v { q = Queue.new; q.push(1); q.deq(timeout: v) } + it "is an alias of Queue#pop" do + Queue.instance_method(:deq).should == Queue.instance_method(:pop) + end end diff --git a/core/queue/enq_spec.rb b/core/queue/enq_spec.rb index c69c496fb..76ecf0ca5 100644 --- a/core/queue/enq_spec.rb +++ b/core/queue/enq_spec.rb @@ -1,6 +1,7 @@ require_relative '../../spec_helper' -require_relative '../../shared/queue/enque' describe "Queue#enq" do - it_behaves_like :queue_enq, :enq, -> { Queue.new } + it "is an alias of Queue#<<" do + Queue.instance_method(:enq).should == Queue.instance_method(:<<) + end end diff --git a/core/queue/length_spec.rb b/core/queue/length_spec.rb index 25399b2b7..0566b1d54 100644 --- a/core/queue/length_spec.rb +++ b/core/queue/length_spec.rb @@ -1,6 +1,7 @@ require_relative '../../spec_helper' -require_relative '../../shared/queue/length' describe "Queue#length" do - it_behaves_like :queue_length, :length, -> { Queue.new } + it "is an alias of Queue#size" do + Queue.instance_method(:length).should == Queue.instance_method(:size) + end end diff --git a/core/queue/push_spec.rb b/core/queue/push_spec.rb index e936f9d28..ef622ac89 100644 --- a/core/queue/push_spec.rb +++ b/core/queue/push_spec.rb @@ -1,6 +1,7 @@ require_relative '../../spec_helper' -require_relative '../../shared/queue/enque' describe "Queue#push" do - it_behaves_like :queue_enq, :push, -> { Queue.new } + it "is an alias of Queue#<<" do + Queue.instance_method(:push).should == Queue.instance_method(:<<) + end end diff --git a/core/queue/shift_spec.rb b/core/queue/shift_spec.rb index c105da74b..074332359 100644 --- a/core/queue/shift_spec.rb +++ b/core/queue/shift_spec.rb @@ -1,11 +1,7 @@ require_relative '../../spec_helper' -require_relative '../../shared/queue/deque' -require_relative '../../shared/types/rb_num2dbl_fails' describe "Queue#shift" do - it_behaves_like :queue_deq, :shift, -> { Queue.new } -end - -describe "Queue operations with timeout" do - it_behaves_like :rb_num2dbl_fails, nil, -> v { q = Queue.new; q.push(1); q.shift(timeout: v) } + it "is an alias of Queue#pop" do + Queue.instance_method(:shift).should == Queue.instance_method(:pop) + end end diff --git a/core/sizedqueue/deq_spec.rb b/core/sizedqueue/deq_spec.rb index 2aeb52f8a..51ff70655 100644 --- a/core/sizedqueue/deq_spec.rb +++ b/core/sizedqueue/deq_spec.rb @@ -1,11 +1,7 @@ require_relative '../../spec_helper' -require_relative '../../shared/queue/deque' -require_relative '../../shared/types/rb_num2dbl_fails' describe "SizedQueue#deq" do - it_behaves_like :queue_deq, :deq, -> { SizedQueue.new(10) } -end - -describe "SizedQueue operations with timeout" do - it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(10); q.push(1); q.deq(timeout: v) } + it "is an alias of SizedQueue#pop" do + SizedQueue.instance_method(:deq).should == SizedQueue.instance_method(:pop) + end end diff --git a/core/sizedqueue/enq_spec.rb b/core/sizedqueue/enq_spec.rb index b95590947..94697cd24 100644 --- a/core/sizedqueue/enq_spec.rb +++ b/core/sizedqueue/enq_spec.rb @@ -1,16 +1,7 @@ require_relative '../../spec_helper' -require_relative '../../shared/queue/enque' -require_relative '../../shared/sizedqueue/enque' -require_relative '../../shared/types/rb_num2dbl_fails' describe "SizedQueue#enq" do - it_behaves_like :queue_enq, :enq, -> { SizedQueue.new(10) } -end - -describe "SizedQueue#enq" do - it_behaves_like :sizedqueue_enq, :enq, -> n { SizedQueue.new(n) } -end - -describe "SizedQueue operations with timeout" do - it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.enq(1, timeout: v) } + it "is an alias of SizedQueue#<<" do + SizedQueue.instance_method(:enq).should == SizedQueue.instance_method(:<<) + end end diff --git a/core/sizedqueue/length_spec.rb b/core/sizedqueue/length_spec.rb index b93e7f899..b9d16d893 100644 --- a/core/sizedqueue/length_spec.rb +++ b/core/sizedqueue/length_spec.rb @@ -1,6 +1,7 @@ require_relative '../../spec_helper' -require_relative '../../shared/queue/length' describe "SizedQueue#length" do - it_behaves_like :queue_length, :length, -> { SizedQueue.new(10) } + it "is an alias of SizedQueue#size" do + SizedQueue.instance_method(:length).should == SizedQueue.instance_method(:size) + end end diff --git a/core/sizedqueue/push_spec.rb b/core/sizedqueue/push_spec.rb index 9eaa6beca..943d0fcfb 100644 --- a/core/sizedqueue/push_spec.rb +++ b/core/sizedqueue/push_spec.rb @@ -1,16 +1,7 @@ require_relative '../../spec_helper' -require_relative '../../shared/queue/enque' -require_relative '../../shared/sizedqueue/enque' -require_relative '../../shared/types/rb_num2dbl_fails' describe "SizedQueue#push" do - it_behaves_like :queue_enq, :push, -> { SizedQueue.new(10) } -end - -describe "SizedQueue#push" do - it_behaves_like :sizedqueue_enq, :push, -> n { SizedQueue.new(n) } -end - -describe "SizedQueue operations with timeout" do - it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.push(1, timeout: v) } + it "is an alias of SizedQueue#<<" do + SizedQueue.instance_method(:push).should == SizedQueue.instance_method(:<<) + end end diff --git a/core/sizedqueue/shift_spec.rb b/core/sizedqueue/shift_spec.rb index 52974c1d9..f410f3f80 100644 --- a/core/sizedqueue/shift_spec.rb +++ b/core/sizedqueue/shift_spec.rb @@ -1,11 +1,7 @@ require_relative '../../spec_helper' -require_relative '../../shared/queue/deque' -require_relative '../../shared/types/rb_num2dbl_fails' describe "SizedQueue#shift" do - it_behaves_like :queue_deq, :shift, -> { SizedQueue.new(10) } -end - -describe "SizedQueue operations with timeout" do - it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(10); q.push(1); q.shift(timeout: v) } + it "is an alias of SizedQueue#pop" do + SizedQueue.instance_method(:shift).should == SizedQueue.instance_method(:pop) + end end diff --git a/core/true/inspect_spec.rb b/core/true/inspect_spec.rb index 09d191485..b9f5390b5 100644 --- a/core/true/inspect_spec.rb +++ b/core/true/inspect_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' describe "TrueClass#inspect" do - it "returns the string 'true'" do - true.inspect.should == "true" + it "is an alias of TrueClass#to_s" do + true.method(:inspect).should == true.method(:to_s) end end diff --git a/core/unboundmethod/eql_spec.rb b/core/unboundmethod/eql_spec.rb index cf2c6b5aa..3b299d047 100644 --- a/core/unboundmethod/eql_spec.rb +++ b/core/unboundmethod/eql_spec.rb @@ -1,5 +1,7 @@ require_relative '../../spec_helper' describe "UnboundMethod#eql?" do - it "needs to be reviewed for spec completeness" + it "is an alias of UnboundMethod#==" do + UnboundMethod.instance_method(:eql?).should == UnboundMethod.instance_method(:==) + end end diff --git a/library/zlib/gzipreader/each_line_spec.rb b/library/zlib/gzipreader/each_line_spec.rb index 6f1736587..97f24d410 100644 --- a/library/zlib/gzipreader/each_line_spec.rb +++ b/library/zlib/gzipreader/each_line_spec.rb @@ -1,6 +1,9 @@ require_relative "../../../spec_helper" -require_relative 'shared/each' +require 'zlib' describe "Zlib::GzipReader#each_line" do - it_behaves_like :gzipreader_each, :each_line + it "is an alias of Zlib::GzipReader#each" do + Zlib::GzipReader.instance_method(:each_line).should == + Zlib::GzipReader.instance_method(:each) + end end diff --git a/library/zlib/gzipreader/each_spec.rb b/library/zlib/gzipreader/each_spec.rb index 3b98391a8..75fd7e6ba 100644 --- a/library/zlib/gzipreader/each_spec.rb +++ b/library/zlib/gzipreader/each_spec.rb @@ -1,6 +1,49 @@ require_relative "../../../spec_helper" -require_relative 'shared/each' +require 'stringio' +require 'zlib' describe "Zlib::GzipReader#each" do - it_behaves_like :gzipreader_each, :each + before :each do + @data = "firstline\nsecondline\n\nforthline" + @zip = [31, 139, 8, 0, 244, 125, 128, 88, 2, 255, 75, 203, 44, 42, 46, 201, + 201, 204, 75, 229, 42, 78, 77, 206, 207, 75, 1, 51, 185, 210,242, + 139, 74, 50, 64, 76, 0, 180, 54, 61, 111, 31, 0, 0, 0].pack('C*') + + @io = StringIO.new @zip + @gzreader = Zlib::GzipReader.new @io + end + + after :each do + ScratchPad.clear + end + + it "calls the given block for each line in the stream, passing the line as an argument" do + ScratchPad.record [] + @gzreader.each { |b| ScratchPad << b } + + ScratchPad.recorded.should == ["firstline\n", "secondline\n", "\n", "forthline"] + end + + it "returns an enumerator, which yields each byte in the stream, when no block is passed" do + enum = @gzreader.each + + ScratchPad.record [] + while true + begin + ScratchPad << enum.next + rescue StopIteration + break + end + end + + ScratchPad.recorded.should == ["firstline\n", "secondline\n", "\n", "forthline"] + end + + it "increments position before calling the block" do + i = 0 + @gzreader.each do |line| + i += line.length + @gzreader.pos.should == i + end + end end diff --git a/library/zlib/gzipreader/eof_spec.rb b/library/zlib/gzipreader/eof_spec.rb index a38e144c7..434e716b6 100644 --- a/library/zlib/gzipreader/eof_spec.rb +++ b/library/zlib/gzipreader/eof_spec.rb @@ -52,3 +52,10 @@ gz.eof?.should == true end end + +describe "Zlib::GzipReader#eof" do + it "is an alias of Zlib::GzipReader#eof?" do + Zlib::GzipReader.instance_method(:eof).should == + Zlib::GzipReader.instance_method(:eof?) + end +end diff --git a/library/zlib/gzipreader/shared/each.rb b/library/zlib/gzipreader/shared/each.rb deleted file mode 100644 index 71608e04a..000000000 --- a/library/zlib/gzipreader/shared/each.rb +++ /dev/null @@ -1,49 +0,0 @@ -require_relative '../../../../spec_helper' -require 'stringio' -require 'zlib' - -describe :gzipreader_each, shared: true do - before :each do - @data = "firstline\nsecondline\n\nforthline" - @zip = [31, 139, 8, 0, 244, 125, 128, 88, 2, 255, 75, 203, 44, 42, 46, 201, - 201, 204, 75, 229, 42, 78, 77, 206, 207, 75, 1, 51, 185, 210,242, - 139, 74, 50, 64, 76, 0, 180, 54, 61, 111, 31, 0, 0, 0].pack('C*') - - @io = StringIO.new @zip - @gzreader = Zlib::GzipReader.new @io - end - - after :each do - ScratchPad.clear - end - - it "calls the given block for each line in the stream, passing the line as an argument" do - ScratchPad.record [] - @gzreader.send(@method) { |b| ScratchPad << b } - - ScratchPad.recorded.should == ["firstline\n", "secondline\n", "\n", "forthline"] - end - - it "returns an enumerator, which yields each byte in the stream, when no block is passed" do - enum = @gzreader.send(@method) - - ScratchPad.record [] - while true - begin - ScratchPad << enum.next - rescue StopIteration - break - end - end - - ScratchPad.recorded.should == ["firstline\n", "secondline\n", "\n", "forthline"] - end - - it "increments position before calling the block" do - i = 0 - @gzreader.send(@method) do |line| - i += line.length - @gzreader.pos.should == i - end - end -end diff --git a/library/zlib/gzipreader/tell_spec.rb b/library/zlib/gzipreader/tell_spec.rb new file mode 100644 index 000000000..cc103e57b --- /dev/null +++ b/library/zlib/gzipreader/tell_spec.rb @@ -0,0 +1,9 @@ +require_relative "../../../spec_helper" +require 'zlib' + +describe "Zlib::GzipReader#tell" do + it "is an alias of Zlib::GzipReader#pos" do + Zlib::GzipReader.instance_method(:tell).should == + Zlib::GzipReader.instance_method(:pos) + end +end diff --git a/shared/kernel/raise.rb b/shared/kernel/raise.rb index 845916690..04eaa94e6 100644 --- a/shared/kernel/raise.rb +++ b/shared/kernel/raise.rb @@ -92,6 +92,21 @@ def initialize -> { @object.raise("message", {cause: RuntimeError.new()}) }.should.raise(TypeError, "exception class/object expected") end + it "raises result from #exception when passed a non-Exception object" do + e = Object.new + def e.exception = StandardError.new + + -> { @object.raise e }.should.raise(StandardError) + end + + it "raises result from #exception with given arguments when passed a non-Exception object" do + e = Object.new + def e.exception(msg) = StandardError.new(msg) + + -> { @object.raise e, "foo" }.should.raise(StandardError, "foo") + -> { @object.raise e }.should.raise(ArgumentError, "wrong number of arguments (given 0, expected 1)") + 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