summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/enumerable/grep_spec.rb24
-rw-r--r--spec/ruby/core/enumerable/grep_v_spec.rb24
2 files changed, 34 insertions, 14 deletions
diff --git a/spec/ruby/core/enumerable/grep_spec.rb b/spec/ruby/core/enumerable/grep_spec.rb
index c9c0f34e27..4e66bb85ea 100644
--- a/spec/ruby/core/enumerable/grep_spec.rb
+++ b/spec/ruby/core/enumerable/grep_spec.rb
@@ -40,15 +40,25 @@ describe "Enumerable#grep" do
$~.should == nil
end
- it "sets $~ to the last match when given no block" do
- "z" =~ /z/ # Reset $~
- ["abc", "def"].grep(/b/).should == ["abc"]
+ ruby_version_is ""..."3.0.0" do
+ it "sets $~ to the last match when given no block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].grep(/b/).should == ["abc"]
- # Set by the failed match of "def"
- $~.should == nil
+ # Set by the failed match of "def"
+ $~.should == nil
- ["abc", "def"].grep(/e/)
- $&.should == "e"
+ ["abc", "def"].grep(/e/)
+ $&.should == "e"
+ end
+ end
+
+ ruby_version_is "3.0.0" do
+ it "does not set $~ when given no block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].grep(/b/).should == ["abc"]
+ $&.should == "z"
+ end
end
describe "with a block" do
diff --git a/spec/ruby/core/enumerable/grep_v_spec.rb b/spec/ruby/core/enumerable/grep_v_spec.rb
index 6dec487065..8cae3ac618 100644
--- a/spec/ruby/core/enumerable/grep_v_spec.rb
+++ b/spec/ruby/core/enumerable/grep_v_spec.rb
@@ -20,15 +20,25 @@ describe "Enumerable#grep_v" do
$&.should == "e"
end
- it "sets $~ to the last match when given no block" do
- "z" =~ /z/ # Reset $~
- ["abc", "def"].grep_v(/e/).should == ["abc"]
+ ruby_version_is ""..."3.0.0" do
+ it "sets $~ to the last match when given no block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].grep_v(/e/).should == ["abc"]
- # Set by the match of "def"
- $&.should == "e"
+ # Set by the match of "def"
+ $&.should == "e"
- ["abc", "def"].grep_v(/b/)
- $&.should == nil
+ ["abc", "def"].grep_v(/b/)
+ $&.should == nil
+ end
+ end
+
+ ruby_version_is "3.0.0" do
+ it "does not set $~ when given no block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].grep_v(/e/).should == ["abc"]
+ $&.should == "z"
+ end
end
describe "without block" do