summaryrefslogtreecommitdiff
path: root/spec/ruby/language/predefined_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/language/predefined_spec.rb')
-rw-r--r--spec/ruby/language/predefined_spec.rb46
1 files changed, 38 insertions, 8 deletions
diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb
index 91019cfe56..fc1667a38f 100644
--- a/spec/ruby/language/predefined_spec.rb
+++ b/spec/ruby/language/predefined_spec.rb
@@ -1,4 +1,5 @@
require_relative '../spec_helper'
+require_relative '../core/exception/shared/set_backtrace'
require 'stringio'
# The following tables are excerpted from Programming Ruby: The Pragmatic Programmer's Guide'
@@ -621,6 +622,17 @@ describe "Predefined global $@" do
end
end
+ it_behaves_like :exception_set_backtrace, -> backtrace {
+ exception = nil
+ begin
+ raise
+ rescue
+ $@ = backtrace
+ exception = $!
+ end
+ exception
+ }
+
it "cannot be assigned when there is no a rescued exception" do
-> {
$@ = []
@@ -675,7 +687,7 @@ describe "Predefined global $/" do
$VERBOSE = @verbose
end
- ruby_version_is ""..."3.5" do
+ ruby_version_is ""..."4.0" do
it "can be assigned a String" do
str = +"abc"
$/ = str
@@ -683,7 +695,7 @@ describe "Predefined global $/" do
end
end
- ruby_version_is "3.5" do
+ ruby_version_is "4.0" do
it "makes a new frozen String from the assigned String" do
string_subclass = Class.new(String)
str = string_subclass.new("abc")
@@ -736,6 +748,10 @@ describe "Predefined global $/" do
it "raises a TypeError if assigned a boolean" do
-> { $/ = true }.should raise_error(TypeError, 'value of $/ must be String')
end
+
+ it "warns if assigned non-nil" do
+ -> { $/ = "_" }.should complain(/warning: (?:non-nil )?[`']\$\/' is deprecated/)
+ end
end
describe "Predefined global $-0" do
@@ -751,7 +767,7 @@ describe "Predefined global $-0" do
$VERBOSE = @verbose
end
- ruby_version_is ""..."3.5" do
+ ruby_version_is ""..."4.0" do
it "can be assigned a String" do
str = +"abc"
$-0 = str
@@ -759,7 +775,7 @@ describe "Predefined global $-0" do
end
end
- ruby_version_is "3.5" do
+ ruby_version_is "4.0" do
it "makes a new frozen String from the assigned String" do
string_subclass = Class.new(String)
str = string_subclass.new("abc")
@@ -813,6 +829,10 @@ describe "Predefined global $-0" do
it "raises a TypeError if assigned a boolean" do
-> { $-0 = true }.should raise_error(TypeError, 'value of $-0 must be String')
end
+
+ it "warns if assigned non-nil" do
+ -> { $-0 = "_" }.should complain(/warning: (?:non-nil )?[`']\$-0' is deprecated/)
+ end
end
describe "Predefined global $\\" do
@@ -852,6 +872,10 @@ describe "Predefined global $\\" do
-> { $\ = 1 }.should raise_error(TypeError, 'value of $\ must be String')
-> { $\ = true }.should raise_error(TypeError, 'value of $\ must be String')
end
+
+ it "warns if assigned non-nil" do
+ -> { $\ = "_" }.should complain(/warning: (?:non-nil )?[`']\$\\' is deprecated/)
+ end
end
describe "Predefined global $," do
@@ -868,7 +892,7 @@ describe "Predefined global $," do
end
it "warns if assigned non-nil" do
- -> { $, = "_" }.should complain(/warning: [`']\$,' is deprecated/)
+ -> { $, = "_" }.should complain(/warning: (?:non-nil )?[`']\$,' is deprecated/)
end
end
@@ -905,7 +929,7 @@ describe "Predefined global $;" do
end
it "warns if assigned non-nil" do
- -> { $; = "_" }.should complain(/warning: [`']\$;' is deprecated/)
+ -> { $; = "_" }.should complain(/warning: (?:non-nil )?[`']\$;' is deprecated/)
end
end
@@ -1063,8 +1087,14 @@ describe "Execution variable $:" do
it "default $LOAD_PATH entries until sitelibdir included have @gem_prelude_index set" do
skip "no sense in ruby itself" if MSpecScript.instance_variable_defined?(:@testing_ruby)
- $:.should.include?(RbConfig::CONFIG['sitelibdir'])
- idx = $:.index(RbConfig::CONFIG['sitelibdir'])
+ if platform_is :windows
+ # See https://github.com/ruby/setup-ruby/pull/762#issuecomment-2917460440
+ $:.should.find { |e| File.realdirpath(e) == RbConfig::CONFIG['sitelibdir'] }
+ idx = $:.index { |e| File.realdirpath(e) == RbConfig::CONFIG['sitelibdir'] }
+ else
+ $:.should.include?(RbConfig::CONFIG['sitelibdir'])
+ idx = $:.index(RbConfig::CONFIG['sitelibdir'])
+ end
$:[idx..-1].all? { |p| p.instance_variable_defined?(:@gem_prelude_index) }.should be_true
$:[0...idx].all? { |p| !p.instance_variable_defined?(:@gem_prelude_index) }.should be_true