summaryrefslogtreecommitdiff
path: root/spec/ruby/core
diff options
context:
space:
mode:
authorBenoit Daloze <[email protected]>2020-10-24 15:52:37 +0200
committerBenoit Daloze <[email protected]>2020-10-24 15:53:53 +0200
commit148961adcd0704d964fce920330a6301b9704c25 (patch)
tree1f1f0cb7326775788683c77f0e2cceb495d3cc95 /spec/ruby/core
parent342fbae83c2e80d1b49656bc7c689cc7fe8980ce (diff)
Update to ruby/spec@4f59d86
Diffstat (limited to 'spec/ruby/core')
-rw-r--r--spec/ruby/core/array/minmax_spec.rb14
-rw-r--r--spec/ruby/core/class/new_spec.rb11
-rw-r--r--spec/ruby/core/encoding/list_spec.rb14
-rw-r--r--spec/ruby/core/enumerable/minmax_spec.rb34
-rw-r--r--spec/ruby/core/env/shared/key.rb14
-rw-r--r--spec/ruby/core/file/shared/path.rb17
-rw-r--r--spec/ruby/core/hash/element_reference_spec.rb14
-rw-r--r--spec/ruby/core/hash/fixtures/name.rb30
-rw-r--r--spec/ruby/core/hash/shared/store.rb17
-rw-r--r--spec/ruby/core/integer/chr_spec.rb13
-rw-r--r--spec/ruby/core/kernel/shared/require.rb8
-rw-r--r--spec/ruby/core/kernel/taint_spec.rb15
-rw-r--r--spec/ruby/core/kernel/tainted_spec.rb17
-rw-r--r--spec/ruby/core/kernel/trust_spec.rb16
-rw-r--r--spec/ruby/core/kernel/untaint_spec.rb16
-rw-r--r--spec/ruby/core/kernel/untrust_spec.rb15
-rw-r--r--spec/ruby/core/kernel/untrusted_spec.rb16
-rw-r--r--spec/ruby/core/kernel/warn_spec.rb31
-rw-r--r--spec/ruby/core/method/fixtures/classes.rb6
-rw-r--r--spec/ruby/core/method/shared/to_s.rb33
-rw-r--r--spec/ruby/core/method/source_location_spec.rb18
-rw-r--r--spec/ruby/core/module/autoload_spec.rb10
-rw-r--r--spec/ruby/core/range/case_compare_spec.rb5
-rw-r--r--spec/ruby/core/range/cover_spec.rb1
-rw-r--r--spec/ruby/core/range/shared/cover.rb2
-rw-r--r--spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb13
-rw-r--r--spec/ruby/core/unboundmethod/shared/to_s.rb9
-rw-r--r--spec/ruby/core/warning/element_reference_spec.rb14
-rw-r--r--spec/ruby/core/warning/element_set_spec.rb19
29 files changed, 390 insertions, 52 deletions
diff --git a/spec/ruby/core/array/minmax_spec.rb b/spec/ruby/core/array/minmax_spec.rb
new file mode 100644
index 0000000000..e11fe63347
--- /dev/null
+++ b/spec/ruby/core/array/minmax_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/enumerable/minmax'
+
+describe "Array#minmax" do
+ before :each do
+ @enum = [6, 4, 5, 10, 8]
+ @empty_enum = []
+ @incomparable_enum = [BasicObject.new, BasicObject.new]
+ @incompatible_enum = [11, "22"]
+ @strs = ["333", "2", "60", "55555", "1010", "111"]
+ end
+
+ it_behaves_like :enumerable_minmax, :minmax
+end
diff --git a/spec/ruby/core/class/new_spec.rb b/spec/ruby/core/class/new_spec.rb
index 989d674558..f863766c1a 100644
--- a/spec/ruby/core/class/new_spec.rb
+++ b/spec/ruby/core/class/new_spec.rb
@@ -96,11 +96,12 @@ describe "Class.new" do
it "raises a TypeError when given a non-Class" do
error_msg = /superclass must be a Class/
- -> { Class.new("") }.should raise_error(TypeError, error_msg)
- -> { Class.new(1) }.should raise_error(TypeError, error_msg)
- -> { Class.new(:symbol) }.should raise_error(TypeError, error_msg)
- -> { Class.new(mock('o')) }.should raise_error(TypeError, error_msg)
- -> { Class.new(Module.new) }.should raise_error(TypeError, error_msg)
+ -> { Class.new("") }.should raise_error(TypeError, error_msg)
+ -> { Class.new(1) }.should raise_error(TypeError, error_msg)
+ -> { Class.new(:symbol) }.should raise_error(TypeError, error_msg)
+ -> { Class.new(mock('o')) }.should raise_error(TypeError, error_msg)
+ -> { Class.new(Module.new) }.should raise_error(TypeError, error_msg)
+ -> { Class.new(BasicObject.new) }.should raise_error(TypeError, error_msg)
end
end
diff --git a/spec/ruby/core/encoding/list_spec.rb b/spec/ruby/core/encoding/list_spec.rb
index 2a2078974e..8efd94ab9c 100644
--- a/spec/ruby/core/encoding/list_spec.rb
+++ b/spec/ruby/core/encoding/list_spec.rb
@@ -12,7 +12,7 @@ describe "Encoding.list" do
end
it "returns each encoding only once" do
- orig = Encoding.list.map {|e| e.name}
+ orig = Encoding.list.map { |e| e.name }
orig.should == orig.uniq
end
@@ -33,7 +33,17 @@ describe "Encoding.list" do
end
it "includes dummy encodings" do
- Encoding.list.select {|e| e.dummy?}.should_not == []
+ Encoding.list.select { |e| e.dummy? }.should_not == []
+ end
+
+ it 'includes UTF-8 encoding' do
+ Encoding.list.should.include?(Encoding::UTF_8)
+ end
+
+ ruby_version_is "2.7" do
+ it 'includes CESU-8 encoding' do
+ Encoding.list.should.include?(Encoding::CESU_8)
+ end
end
# TODO: Find example that illustrates this
diff --git a/spec/ruby/core/enumerable/minmax_spec.rb b/spec/ruby/core/enumerable/minmax_spec.rb
index 29f1ecf82c..f5f17ef079 100644
--- a/spec/ruby/core/enumerable/minmax_spec.rb
+++ b/spec/ruby/core/enumerable/minmax_spec.rb
@@ -1,41 +1,17 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
+require_relative '../../shared/enumerable/minmax'
describe "Enumerable#minmax" do
before :each do
@enum = EnumerableSpecs::Numerous.new(6, 4, 5, 10, 8)
-
+ @empty_enum = EnumerableSpecs::Empty.new
+ @incomparable_enum = EnumerableSpecs::Numerous.new(BasicObject.new, BasicObject.new)
+ @incompatible_enum = EnumerableSpecs::Numerous.new(11,"22")
@strs = EnumerableSpecs::Numerous.new("333", "2", "60", "55555", "1010", "111")
end
- it "min should return the minimum element" do
- @enum.minmax.should == [4, 10]
- @strs.minmax.should == ["1010", "60" ]
- end
-
- it "returns [nil, nil] for an empty Enumerable" do
- EnumerableSpecs::Empty.new.minmax.should == [nil, nil]
- end
-
- it "raises an ArgumentError when elements are incomparable" do
- -> do
- EnumerableSpecs::Numerous.new(11,"22").minmax
- end.should raise_error(ArgumentError)
- -> do
- EnumerableSpecs::Numerous.new(11,12,22,33).minmax{|a, b| nil}
- end.should raise_error(ArgumentError)
- end
-
- it "raises a NoMethodError for elements without #<=>" do
- -> do
- EnumerableSpecs::Numerous.new(BasicObject.new, BasicObject.new).minmax
- end.should raise_error(NoMethodError)
- end
-
- it "returns the minimum when using a block rule" do
- @enum.minmax {|a,b| b <=> a }.should == [10, 4]
- @strs.minmax {|a,b| a.length <=> b.length }.should == ["2", "55555"]
- end
+ it_behaves_like :enumerable_minmax, :minmax
it "gathers whole arrays as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
diff --git a/spec/ruby/core/env/shared/key.rb b/spec/ruby/core/env/shared/key.rb
index fcb3a9b8c5..93396d2aca 100644
--- a/spec/ruby/core/env/shared/key.rb
+++ b/spec/ruby/core/env/shared/key.rb
@@ -9,15 +9,23 @@ describe :env_key, shared: true do
it "returns the index associated with the passed value" do
ENV["foo"] = "bar"
- ENV.send(@method, "bar").should == "foo"
+ suppress_warning {
+ ENV.send(@method, "bar").should == "foo"
+ }
end
it "returns nil if the passed value is not found" do
ENV.delete("foo")
- ENV.send(@method, "foo").should be_nil
+ suppress_warning {
+ ENV.send(@method, "foo").should be_nil
+ }
end
it "raises TypeError if the argument is not a String and does not respond to #to_str" do
- -> { ENV.send(@method, Object.new) }.should raise_error(TypeError, "no implicit conversion of Object into String")
+ -> {
+ suppress_warning {
+ ENV.send(@method, Object.new)
+ }
+ }.should raise_error(TypeError, "no implicit conversion of Object into String")
end
end
diff --git a/spec/ruby/core/file/shared/path.rb b/spec/ruby/core/file/shared/path.rb
index d964acc855..0a5abe33f0 100644
--- a/spec/ruby/core/file/shared/path.rb
+++ b/spec/ruby/core/file/shared/path.rb
@@ -15,6 +15,23 @@ describe :file_path, shared: true do
@file.send(@method).should be_an_instance_of(String)
end
+ it "returns a different String on every call" do
+ @file = File.new @path
+ path1 = @file.send(@method)
+ path2 = @file.send(@method)
+ path1.should == path2
+ path1.should_not.equal?(path2)
+ end
+
+ it "returns a mutable String" do
+ @file = File.new @path.dup.freeze
+ path = @file.send(@method)
+ path.should == @path
+ path.should_not.frozen?
+ path << "test"
+ @file.send(@method).should == @path
+ end
+
it "calls to_str on argument and returns exact value" do
path = mock('path')
path.should_receive(:to_str).and_return(@path)
diff --git a/spec/ruby/core/hash/element_reference_spec.rb b/spec/ruby/core/hash/element_reference_spec.rb
index 2eb65d3789..e271f37ea6 100644
--- a/spec/ruby/core/hash/element_reference_spec.rb
+++ b/spec/ruby/core/hash/element_reference_spec.rb
@@ -117,4 +117,18 @@ describe "Hash#[]" do
key = HashSpecs::KeyWithPrivateHash.new
{ key => 42 }[key].should == 42
end
+
+ it "does not dispatch to hash for Boolean, Integer, Float, String, or Symbol" do
+ code = <<-EOC
+ load '#{fixture __FILE__, "name.rb"}'
+ hash = { true => 42, false => 42, 1 => 42, 2.0 => 42, "hello" => 42, :ok => 42 }
+ [true, false, 1, 2.0, "hello", :ok].each do |value|
+ raise "incorrect value" unless hash[value] == 42
+ end
+ puts "Ok."
+ EOC
+ result = ruby_exe(code, args: "2>&1")
+ result.should == "Ok.\n"
+ end
+
end
diff --git a/spec/ruby/core/hash/fixtures/name.rb b/spec/ruby/core/hash/fixtures/name.rb
new file mode 100644
index 0000000000..b203bf6ae4
--- /dev/null
+++ b/spec/ruby/core/hash/fixtures/name.rb
@@ -0,0 +1,30 @@
+class TrueClass
+ def hash
+ raise "TrueClass#hash should not be called"
+ end
+end
+class FalseClass
+ def hash
+ raise "FalseClass#hash should not be called"
+ end
+end
+class Integer
+ def hash
+ raise "Integer#hash should not be called"
+ end
+end
+class Float
+ def hash
+ raise "Float#hash should not be called"
+ end
+end
+class String
+ def hash
+ raise "String#hash should not be called"
+ end
+end
+class Symbol
+ def hash
+ raise "Symbol#hash should not be called"
+ end
+end
diff --git a/spec/ruby/core/hash/shared/store.rb b/spec/ruby/core/hash/shared/store.rb
index 84ffb41e33..eca0e5a8e8 100644
--- a/spec/ruby/core/hash/shared/store.rb
+++ b/spec/ruby/core/hash/shared/store.rb
@@ -95,4 +95,21 @@ describe :hash_store, shared: true do
hash.each { hash.send(@method, 1, :foo) }
hash.should == {1 => :foo, 3 => 4, 5 => 6}
end
+
+ it "does not dispatch to hash for Boolean, Integer, Float, String, or Symbol" do
+ code = <<-EOC
+ load '#{fixture __FILE__, "name.rb"}'
+ hash = {}
+ [true, false, 1, 2.0, "hello", :ok].each do |value|
+ hash[value] = 42
+ raise "incorrect value" unless hash[value] == 42
+ hash[value] = 43
+ raise "incorrect value" unless hash[value] == 43
+ end
+ puts "OK"
+ puts hash.size
+ EOC
+ result = ruby_exe(code, args: "2>&1")
+ result.should == "OK\n6\n"
+ end
end
diff --git a/spec/ruby/core/integer/chr_spec.rb b/spec/ruby/core/integer/chr_spec.rb
index a8755eeb84..9f105e4241 100644
--- a/spec/ruby/core/integer/chr_spec.rb
+++ b/spec/ruby/core/integer/chr_spec.rb
@@ -240,4 +240,17 @@ describe "Integer#chr with an encoding argument" do
-> { integer.chr(encoding_name) }.should raise_error(RangeError)
end
end
+
+ ruby_version_is "2.7" do
+ it 'returns a String encoding self interpreted as a codepoint in the CESU-8 encoding' do
+ # see more details here https://en.wikipedia.org/wiki/CESU-8
+ # code points from U+0000 to U+FFFF is encoded in the same way as in UTF-8
+ 0x0045.chr(Encoding::CESU_8).bytes.should == 0x0045.chr(Encoding::UTF_8).bytes
+
+ # code points in range from U+10000 to U+10FFFF is CESU-8 data containing a 6-byte surrogate pair,
+ # which decodes to a 4-byte UTF-8 string
+ 0x10400.chr(Encoding::CESU_8).bytes.should != 0x10400.chr(Encoding::UTF_8).bytes
+ 0x10400.chr(Encoding::CESU_8).bytes.to_a.should == [0xED, 0xA0, 0x81, 0xED, 0xB0, 0x80]
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/shared/require.rb b/spec/ruby/core/kernel/shared/require.rb
index 6c6895e317..4e0322025c 100644
--- a/spec/ruby/core/kernel/shared/require.rb
+++ b/spec/ruby/core/kernel/shared/require.rb
@@ -160,6 +160,14 @@ describe :kernel_require_basic, shared: true do
ScratchPad.recorded.should == [:loaded]
end
+ it "accepts an Object with #to_path in $LOAD_PATH" do
+ obj = mock("to_path")
+ obj.should_receive(:to_path).at_least(:once).and_return(CODE_LOADING_DIR)
+ $LOAD_PATH << obj
+ @object.send(@method, "load_fixture.rb").should be_true
+ ScratchPad.recorded.should == [:loaded]
+ end
+
it "does not require file twice after $LOAD_PATH change" do
$LOAD_PATH << CODE_LOADING_DIR
@object.require("load_fixture.rb").should be_true
diff --git a/spec/ruby/core/kernel/taint_spec.rb b/spec/ruby/core/kernel/taint_spec.rb
index 060e73963e..22b2c4d0a4 100644
--- a/spec/ruby/core/kernel/taint_spec.rb
+++ b/spec/ruby/core/kernel/taint_spec.rb
@@ -44,4 +44,19 @@ describe "Kernel#taint" do
end
end
end
+
+ ruby_version_is "2.7"..."3.0" do
+ it "is a no-op" do
+ o = Object.new
+ o.taint
+ o.should_not.tainted?
+ end
+
+ it "warns in verbose mode" do
+ -> {
+ obj = mock("tainted")
+ obj.taint
+ }.should complain(/Object#taint is deprecated and will be removed in Ruby 3.2/, verbose: true)
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/tainted_spec.rb b/spec/ruby/core/kernel/tainted_spec.rb
index dbd6bc939a..022938bfc1 100644
--- a/spec/ruby/core/kernel/tainted_spec.rb
+++ b/spec/ruby/core/kernel/tainted_spec.rb
@@ -11,4 +11,21 @@ describe "Kernel#tainted?" do
p.should.tainted?
end
end
+
+ ruby_version_is "2.7"..."3.0" do
+ it "is a no-op" do
+ o = mock('o')
+ p = mock('p')
+ p.taint
+ o.should_not.tainted?
+ p.should_not.tainted?
+ end
+
+ it "warns in verbose mode" do
+ -> {
+ o = mock('o')
+ o.tainted?
+ }.should complain(/Object#tainted\? is deprecated and will be removed in Ruby 3.2/, verbose: true)
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/trust_spec.rb b/spec/ruby/core/kernel/trust_spec.rb
index 1d209ea1dc..399983f74d 100644
--- a/spec/ruby/core/kernel/trust_spec.rb
+++ b/spec/ruby/core/kernel/trust_spec.rb
@@ -24,4 +24,20 @@ describe "Kernel#trust" do
o.trust.should equal(o)
end
end
+
+ ruby_version_is "2.7"..."3.0" do
+ it "is a no-op" do
+ o = Object.new.untrust
+ o.should_not.untrusted?
+ o.trust
+ o.should_not.untrusted?
+ end
+
+ it "warns in verbose mode" do
+ -> {
+ o = Object.new.untrust
+ o.trust
+ }.should complain(/Object#trust is deprecated and will be removed in Ruby 3.2/, verbose: true)
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/untaint_spec.rb b/spec/ruby/core/kernel/untaint_spec.rb
index 171d32b356..44d87da5d5 100644
--- a/spec/ruby/core/kernel/untaint_spec.rb
+++ b/spec/ruby/core/kernel/untaint_spec.rb
@@ -24,4 +24,20 @@ describe "Kernel#untaint" do
o.untaint.should equal(o)
end
end
+
+ ruby_version_is "2.7"..."3.0" do
+ it "is a no-op" do
+ o = Object.new.taint
+ o.should_not.tainted?
+ o.untaint
+ o.should_not.tainted?
+ end
+
+ it "warns in verbose mode" do
+ -> {
+ o = Object.new.taint
+ o.untaint
+ }.should complain(/Object#untaint is deprecated and will be removed in Ruby 3.2/, verbose: true)
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/untrust_spec.rb b/spec/ruby/core/kernel/untrust_spec.rb
index fca7c9ea47..aff0fec57b 100644
--- a/spec/ruby/core/kernel/untrust_spec.rb
+++ b/spec/ruby/core/kernel/untrust_spec.rb
@@ -24,4 +24,19 @@ describe "Kernel#untrust" do
o.untrust.should equal(o)
end
end
+
+ ruby_version_is "2.7"..."3.0" do
+ it "is a no-op" do
+ o = Object.new
+ o.untrust
+ o.should_not.untrusted?
+ end
+
+ it "warns in verbose mode" do
+ -> {
+ o = Object.new
+ o.untrust
+ }.should complain(/Object#untrust is deprecated and will be removed in Ruby 3.2/, verbose: true)
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/untrusted_spec.rb b/spec/ruby/core/kernel/untrusted_spec.rb
index 65cbffa3ad..5347c90093 100644
--- a/spec/ruby/core/kernel/untrusted_spec.rb
+++ b/spec/ruby/core/kernel/untrusted_spec.rb
@@ -27,4 +27,20 @@ describe "Kernel#untrusted?" do
-> { d.untrust }.should_not raise_error(RuntimeError)
end
end
+
+ ruby_version_is "2.7"..."3.0" do
+ it "is a no-op" do
+ o = mock('o')
+ o.should_not.untrusted?
+ o.untrust
+ o.should_not.untrusted?
+ end
+
+ it "warns in verbose mode" do
+ -> {
+ o = mock('o')
+ o.untrusted?
+ }.should complain(/Object#untrusted\? is deprecated and will be removed in Ruby 3.2/, verbose: true)
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/warn_spec.rb b/spec/ruby/core/kernel/warn_spec.rb
index de08cd8cff..fcba164f8f 100644
--- a/spec/ruby/core/kernel/warn_spec.rb
+++ b/spec/ruby/core/kernel/warn_spec.rb
@@ -197,4 +197,35 @@ describe "Kernel#warn" do
-> { warn(**h) }.should_not complain(verbose: true)
-> { warn('foo', **h) }.should complain("foo\n")
end
+
+ it "does not call Warning.warn if self is the Warning module" do
+ # RubyGems redefines Kernel#warn so we need to use a subprocess and disable RubyGems here
+ code = <<-RUBY
+ def Warning.warn(*args, **kwargs)
+ raise 'should not be called'
+ end
+ Kernel.instance_method(:warn).bind(Warning).call('Kernel#warn spec edge case')
+ RUBY
+ out = ruby_exe(code, args: "2>&1", options: "--disable-gems")
+ out.should == "Kernel#warn spec edge case\n"
+ $?.should.success?
+ end
+
+ it "avoids recursion if Warning#warn is redefined and calls super" do
+ # This works because of the spec above, which is the workaround for it.
+ # Note that redefining Warning#warn is a mistake which would naturally end in infinite recursion,
+ # Warning.extend Module.new { def warn } should be used instead.
+ # RubyGems redefines Kernel#warn so we need to use a subprocess and disable RubyGems here
+ code = <<-RUBY
+ module Warning
+ def warn(*args, **kwargs)
+ super
+ end
+ end
+ warn "avoid infinite recursion"
+ RUBY
+ out = ruby_exe(code, args: "2>&1", options: "--disable-gems")
+ out.should == "avoid infinite recursion\n"
+ $?.should.success?
+ end
end
diff --git a/spec/ruby/core/method/fixtures/classes.rb b/spec/ruby/core/method/fixtures/classes.rb
index f3b7ff921c..be96f65e25 100644
--- a/spec/ruby/core/method/fixtures/classes.rb
+++ b/spec/ruby/core/method/fixtures/classes.rb
@@ -50,6 +50,8 @@ module MethodSpecs
def one_req(a); end
def two_req(a, b); end
+ def one_req_named(a:); end
+
def zero_with_block(&blk); end
def one_req_with_block(a, &blk); end
def two_req_with_block(a, b, &blk); end
@@ -59,6 +61,8 @@ module MethodSpecs
def one_req_two_opt(a, b=nil, c=nil); end
def two_req_one_opt(a, b, c=nil); end
+ def one_opt_named(a: nil); end
+
def one_opt_with_block(a=nil, &blk); end
def one_req_one_opt_with_block(a, b=nil, &blk); end
def one_req_two_opt_with_block(a, b=nil, c=nil, &blk); end
@@ -71,6 +75,8 @@ module MethodSpecs
def two_req_one_opt_with_splat(a, b, c=nil, *d); end
def one_req_two_opt_with_splat(a, b=nil, c=nil, *d); end
+ def zero_with_double_splat(**a); end
+
def zero_with_splat_and_block(*a, &blk); end
def one_req_with_splat_and_block(a, *b, &blk); end
def two_req_with_splat_and_block(a, b, *c, &blk); end
diff --git a/spec/ruby/core/method/shared/to_s.rb b/spec/ruby/core/method/shared/to_s.rb
index 0c0edc2f8c..1fbee870d6 100644
--- a/spec/ruby/core/method/shared/to_s.rb
+++ b/spec/ruby/core/method/shared/to_s.rb
@@ -4,7 +4,7 @@ require_relative '../fixtures/classes'
describe :method_to_s, shared: true do
before :each do
@m = MethodSpecs::MySub.new.method :bar
- @string = @m.send(@method).sub(/0x\w+/, '0xXXXXXX')
+ @string = @m.send(@method)
end
it "returns a String" do
@@ -24,6 +24,21 @@ describe :method_to_s, shared: true do
@string.should =~ /\#bar/
end
+ ruby_version_is "2.7" do
+ it "returns a String containing method arguments" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:zero).send(@method).should.include?("()")
+ obj.method(:one_req).send(@method).should.include?("(a)")
+ obj.method(:one_req_named).send(@method).should.include?("(a:)")
+ obj.method(:zero_with_block).send(@method).should.include?("(&blk)")
+ obj.method(:one_opt).send(@method).should.include?("(a=...)")
+ obj.method(:one_opt_named).send(@method).should.include?("(a: ...)")
+ obj.method(:zero_with_splat).send(@method).should.include?("(*a)")
+ obj.method(:zero_with_double_splat).send(@method).should.include?("(**a)")
+ obj.method(:one_req_one_opt_with_splat_and_block).send(@method).should.include?("(a, b=..., *c, &blk)")
+ end
+ end
+
it "returns a String containing the Module the method is defined in" do
@string.should =~ /MethodSpecs::MyMod/
end
@@ -32,13 +47,21 @@ describe :method_to_s, shared: true do
@string.should =~ /MethodSpecs::MySub/
end
+ it "returns a String including all details" do
+ @string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar"
+ end
+
+ it "does not show the defining module if it is the same as the receiver class" do
+ MethodSpecs::A.new.method(:baz).send(@method).should.start_with? "#<Method: MethodSpecs::A#baz"
+ end
+
ruby_version_is '3.0' do
it "returns a String containing the Module containing the method if object has a singleton class but method is not defined in the singleton class" do
obj = MethodSpecs::MySub.new
obj.singleton_class
@m = obj.method(:bar)
- @string = @m.send(@method).sub(/0x\w+/, '0xXXXXXX')
- @string.should =~ /\A#<Method: MethodSpecs::MySub\(MethodSpecs::MyMod\)#bar\(\) /
+ @string = @m.send(@method)
+ @string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar"
end
end
@@ -46,7 +69,7 @@ describe :method_to_s, shared: true do
obj = MethodSpecs::MySub.new
def obj.bar; end
@m = obj.method(:bar)
- @string = @m.send(@method).sub(/0x\w+/, '0xXXXXXX')
- @string.should =~ /\A#<Method: #<MethodSpecs::MySub:0xXXXXXX>\.bar/
+ @string = @m.send(@method).sub(/0x\h+/, '0xXXXXXX')
+ @string.should.start_with? "#<Method: #<MethodSpecs::MySub:0xXXXXXX>.bar"
end
end
diff --git a/spec/ruby/core/method/source_location_spec.rb b/spec/ruby/core/method/source_location_spec.rb
index dd81b02c77..051739c57d 100644
--- a/spec/ruby/core/method/source_location_spec.rb
+++ b/spec/ruby/core/method/source_location_spec.rb
@@ -86,6 +86,24 @@ describe "Method#source_location" do
method.source_location[1].should == line
end
+ it "works for core methods where it returns nil or <internal:" do
+ loc = method(:__id__).source_location
+ if loc == nil
+ loc.should == nil
+ else
+ loc[0].should.start_with?('<internal:')
+ loc[1].should be_kind_of(Integer)
+ end
+
+ loc = method(:tap).source_location
+ if loc == nil
+ loc.should == nil
+ else
+ loc[0].should.start_with?('<internal:')
+ loc[1].should be_kind_of(Integer)
+ end
+ end
+
describe "for a Method generated by respond_to_missing?" do
it "returns nil" do
m = MethodSpecs::Methods.new
diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb
index 5c70e1a217..f17675846b 100644
--- a/spec/ruby/core/module/autoload_spec.rb
+++ b/spec/ruby/core/module/autoload_spec.rb
@@ -1,4 +1,5 @@
require_relative '../../spec_helper'
+require_relative '../../fixtures/code_loading'
require_relative 'fixtures/classes'
require 'thread'
@@ -33,14 +34,7 @@ end
describe "Module#autoload" do
before :all do
@non_existent = fixture __FILE__, "no_autoload.rb"
-
- # Require RubyGems eagerly, to ensure #require is already the RubyGems
- # version, before starting #autoload specs which snapshot #require, and
- # could end up redefining #require as the original core Kernel#require.
- begin
- require "rubygems"
- rescue LoadError
- end
+ CodeLoadingSpecs.preload_rubygems
end
before :each do
diff --git a/spec/ruby/core/range/case_compare_spec.rb b/spec/ruby/core/range/case_compare_spec.rb
index 0ca03f6a35..b1afa90a41 100644
--- a/spec/ruby/core/range/case_compare_spec.rb
+++ b/spec/ruby/core/range/case_compare_spec.rb
@@ -25,4 +25,9 @@ describe "Range#===" do
(range === RangeSpecs::WithoutSucc.new(2)).should == true
end
end
+
+ ruby_version_is "2.7" do
+ it_behaves_like :range_cover_and_include, :===
+ it_behaves_like :range_cover, :===
+ end
end
diff --git a/spec/ruby/core/range/cover_spec.rb b/spec/ruby/core/range/cover_spec.rb
index 29c0e0bfa8..fa881607e9 100644
--- a/spec/ruby/core/range/cover_spec.rb
+++ b/spec/ruby/core/range/cover_spec.rb
@@ -6,4 +6,5 @@ require_relative 'shared/cover'
describe "Range#cover?" do
it_behaves_like :range_cover_and_include, :cover?
it_behaves_like :range_cover, :cover?
+ it_behaves_like :range_cover_subrange, :cover?
end
diff --git a/spec/ruby/core/range/shared/cover.rb b/spec/ruby/core/range/shared/cover.rb
index 33d416fef5..5b09cea4e0 100644
--- a/spec/ruby/core/range/shared/cover.rb
+++ b/spec/ruby/core/range/shared/cover.rb
@@ -90,7 +90,9 @@ describe :range_cover, shared: true do
end
end
end
+end
+describe :range_cover_subrange, shared: true do
ruby_version_is "2.6" do
context "range argument" do
it "accepts range argument" do
diff --git a/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb b/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb
index 90839baa0f..b0ae28beee 100644
--- a/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb
+++ b/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb
@@ -36,6 +36,19 @@ describe 'Thread::Backtrace::Location#absolute_path' do
end
end
+ context "when used in a core method" do
+ it "returns nil" do
+ location = nil
+ tap { location = caller_locations(1, 1)[0] }
+ location.label.should == "tap"
+ if location.path.start_with?("<internal:")
+ location.absolute_path.should == nil
+ else
+ location.absolute_path.should == File.realpath(__FILE__)
+ end
+ end
+ end
+
context "canonicalization" do
platform_is_not :windows do
before :each do
diff --git a/spec/ruby/core/unboundmethod/shared/to_s.rb b/spec/ruby/core/unboundmethod/shared/to_s.rb
index 3987611d3f..38503c3c60 100644
--- a/spec/ruby/core/unboundmethod/shared/to_s.rb
+++ b/spec/ruby/core/unboundmethod/shared/to_s.rb
@@ -22,4 +22,13 @@ describe :unboundmethod_to_s, shared: true do
@from_module.send(@method).should =~ /\bUnboundMethodSpecs::Mod\b/
@from_method.send(@method).should =~ /\bUnboundMethodSpecs::Methods\b/
end
+
+ it "returns a String including all details" do
+ @from_module.send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::Methods(UnboundMethodSpecs::Mod)#from_mod"
+ @from_method.send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::Methods(UnboundMethodSpecs::Mod)#from_mod"
+ end
+
+ it "does not show the defining module if it is the same as the origin" do
+ UnboundMethodSpecs::A.instance_method(:baz).send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::A#baz"
+ end
end
diff --git a/spec/ruby/core/warning/element_reference_spec.rb b/spec/ruby/core/warning/element_reference_spec.rb
new file mode 100644
index 0000000000..c3bf06a95b
--- /dev/null
+++ b/spec/ruby/core/warning/element_reference_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+
+ruby_version_is '2.7.2' do
+ describe "Warning.[]" do
+ it "returns default values for categories :deprecated and :experimental" do
+ ruby_exe('p Warning[:deprecated]').chomp.should == "false"
+ ruby_exe('p Warning[:experimental]').chomp.should == "true"
+ end
+
+ it "raises for unknown category" do
+ -> { Warning[:noop] }.should raise_error(ArgumentError, /unknown category: noop/)
+ end
+ end
+end
diff --git a/spec/ruby/core/warning/element_set_spec.rb b/spec/ruby/core/warning/element_set_spec.rb
new file mode 100644
index 0000000000..ee83656cb4
--- /dev/null
+++ b/spec/ruby/core/warning/element_set_spec.rb
@@ -0,0 +1,19 @@
+require_relative '../../spec_helper'
+
+ruby_version_is '2.7' do
+ describe "Warning.[]=" do
+ it "emits and suppresses warnings for :deprecated" do
+ ruby_exe('Warning[:deprecated] = true; $; = ""', args: "2>&1").should =~ /is deprecated/
+ ruby_exe('Warning[:deprecated] = false; $; = ""', args: "2>&1").should == ""
+ end
+
+ it "emits and suppresses warnings for :experimental" do
+ ruby_exe('Warning[:experimental] = true; eval("0 in a")', args: "2>&1").should =~ /is experimental/
+ ruby_exe('Warning[:experimental] = false; eval("0 in a")', args: "2>&1").should == ""
+ end
+
+ it "raises for unknown category" do
+ -> { Warning[:noop] = false }.should raise_error(ArgumentError, /unknown category: noop/)
+ end
+ end
+end