summaryrefslogtreecommitdiff
path: root/spec/ruby/language
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-02-08 19:43:27 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-01 15:36:20 +0900
commit826f44834fe11f3f9c52343443a15b6c83466889 (patch)
treef2c2abed62db1c750515cd8b0fbac6442b6d4200 /spec/ruby/language
parent3a2073e61b6ccce6d07d31ebd89d4c385b9a55f2 (diff)
Drop support for ruby 2.4 from ruby/spec
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2892
Diffstat (limited to 'spec/ruby/language')
-rw-r--r--spec/ruby/language/block_spec.rb18
-rw-r--r--spec/ruby/language/constants_spec.rb14
-rw-r--r--spec/ruby/language/defined_spec.rb12
-rw-r--r--spec/ruby/language/ensure_spec.rb56
-rw-r--r--spec/ruby/language/lambda_spec.rb7
-rw-r--r--spec/ruby/language/rescue_spec.rb8
-rw-r--r--spec/ruby/language/return_spec.rb214
7 files changed, 130 insertions, 199 deletions
diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb
index 99366006b0..8a02f61925 100644
--- a/spec/ruby/language/block_spec.rb
+++ b/spec/ruby/language/block_spec.rb
@@ -317,10 +317,8 @@ describe "A block" do
@y.s(0) { 1 }.should == 1
end
- ruby_version_is "2.5" do
- it "may include a rescue clause" do
- eval("@y.z do raise ArgumentError; rescue ArgumentError; 7; end").should == 7
- end
+ it "may include a rescue clause" do
+ eval("@y.z do raise ArgumentError; rescue ArgumentError; 7; end").should == 7
end
end
@@ -333,10 +331,8 @@ describe "A block" do
@y.s(0) { || 1 }.should == 1
end
- ruby_version_is "2.5" do
- it "may include a rescue clause" do
- eval('@y.z do || raise ArgumentError; rescue ArgumentError; 7; end').should == 7
- end
+ it "may include a rescue clause" do
+ eval('@y.z do || raise ArgumentError; rescue ArgumentError; 7; end').should == 7
end
end
@@ -364,10 +360,8 @@ describe "A block" do
@y.s([1, 2]) { |a| a }.should == [1, 2]
end
- ruby_version_is "2.5" do
- it "may include a rescue clause" do
- eval('@y.s(1) do |x| raise ArgumentError; rescue ArgumentError; 7; end').should == 7
- end
+ it "may include a rescue clause" do
+ eval('@y.s(1) do |x| raise ArgumentError; rescue ArgumentError; 7; end').should == 7
end
end
diff --git a/spec/ruby/language/constants_spec.rb b/spec/ruby/language/constants_spec.rb
index c4cf940cba..95b0dcace9 100644
--- a/spec/ruby/language/constants_spec.rb
+++ b/spec/ruby/language/constants_spec.rb
@@ -425,18 +425,8 @@ end
describe "top-level constant lookup" do
context "on a class" do
- ruby_version_is "" ... "2.5" do
- it "searches Object successfully after searching other scopes" do
- -> {
- String::Hash.should == Hash
- }.should complain(/toplevel constant Hash referenced by/)
- end
- end
-
- ruby_version_is "2.5" do
- it "does not search Object after searching other scopes" do
- -> { String::Hash }.should raise_error(NameError)
- end
+ it "does not search Object after searching other scopes" do
+ -> { String::Hash }.should raise_error(NameError)
end
end
diff --git a/spec/ruby/language/defined_spec.rb b/spec/ruby/language/defined_spec.rb
index 02c69d27b8..ed61ed3b53 100644
--- a/spec/ruby/language/defined_spec.rb
+++ b/spec/ruby/language/defined_spec.rb
@@ -756,16 +756,8 @@ describe "The defined? keyword for a scoped constant" do
defined?(DefinedSpecs::String).should be_nil
end
- ruby_version_is ""..."2.5" do
- it "returns 'constant' when a constant is defined on top-level but not on the class" do
- defined?(DefinedSpecs::Basic::String).should == 'constant'
- end
- end
-
- ruby_version_is "2.5" do
- it "returns nil when a constant is defined on top-level but not on the class" do
- defined?(DefinedSpecs::Basic::String).should be_nil
- end
+ it "returns nil when a constant is defined on top-level but not on the class" do
+ defined?(DefinedSpecs::Basic::String).should be_nil
end
it "returns 'constant' if the scoped-scoped constant is defined" do
diff --git a/spec/ruby/language/ensure_spec.rb b/spec/ruby/language/ensure_spec.rb
index a930bda36b..da2389e993 100644
--- a/spec/ruby/language/ensure_spec.rb
+++ b/spec/ruby/language/ensure_spec.rb
@@ -251,15 +251,14 @@ describe "An ensure block inside {} block" do
end
end
-ruby_version_is "2.5" do
- describe "An ensure block inside 'do end' block" do
- before :each do
- ScratchPad.record []
- end
+describe "An ensure block inside 'do end' block" do
+ before :each do
+ ScratchPad.record []
+ end
- it "is executed when an exception is raised in it's corresponding begin block" do
- -> {
- eval(<<-ruby).call
+ it "is executed when an exception is raised in it's corresponding begin block" do
+ -> {
+ eval(<<-ruby).call
lambda do
ScratchPad << :begin
raise EnsureSpec::Error
@@ -267,13 +266,13 @@ ruby_version_is "2.5" do
ScratchPad << :ensure
end
ruby
- }.should raise_error(EnsureSpec::Error)
+ }.should raise_error(EnsureSpec::Error)
- ScratchPad.recorded.should == [:begin, :ensure]
- end
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
- it "is executed when an exception is raised and rescued in it's corresponding begin block" do
- eval(<<-ruby).call
+ it "is executed when an exception is raised and rescued in it's corresponding begin block" do
+ eval(<<-ruby).call
lambda do
ScratchPad << :begin
raise "An exception occurred!"
@@ -284,12 +283,12 @@ ruby_version_is "2.5" do
end
ruby
- ScratchPad.recorded.should == [:begin, :rescue, :ensure]
- end
+ ScratchPad.recorded.should == [:begin, :rescue, :ensure]
+ end
- it "is executed even when a symbol is thrown in it's corresponding begin block" do
- catch(:symbol) do
- eval(<<-ruby).call
+ it "is executed even when a symbol is thrown in it's corresponding begin block" do
+ catch(:symbol) do
+ eval(<<-ruby).call
lambda do
ScratchPad << :begin
throw(:symbol)
@@ -299,13 +298,13 @@ ruby_version_is "2.5" do
ScratchPad << :ensure
end
ruby
- end
-
- ScratchPad.recorded.should == [:begin, :ensure]
end
- it "is executed when nothing is raised or thrown in it's corresponding begin block" do
- eval(<<-ruby).call
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+
+ it "is executed when nothing is raised or thrown in it's corresponding begin block" do
+ eval(<<-ruby).call
lambda do
ScratchPad << :begin
rescue
@@ -315,11 +314,11 @@ ruby_version_is "2.5" do
end
ruby
- ScratchPad.recorded.should == [:begin, :ensure]
- end
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
- it "has no return value" do
- result = eval(<<-ruby).call
+ it "has no return value" do
+ result = eval(<<-ruby).call
lambda do
:begin
ensure
@@ -327,7 +326,6 @@ ruby_version_is "2.5" do
end
ruby
- result.should == :begin
- end
+ result.should == :begin
end
end
diff --git a/spec/ruby/language/lambda_spec.rb b/spec/ruby/language/lambda_spec.rb
index 85abf3b996..3f2cb0310c 100644
--- a/spec/ruby/language/lambda_spec.rb
+++ b/spec/ruby/language/lambda_spec.rb
@@ -351,13 +351,10 @@ describe "A lambda expression 'lambda { ... }'" do
lambda { lambda }.should raise_error(ArgumentError)
end
- ruby_version_is "2.5" do
- it "may include a rescue clause" do
- eval('lambda do raise ArgumentError; rescue ArgumentError; 7; end').should be_an_instance_of(Proc)
- end
+ it "may include a rescue clause" do
+ eval('lambda do raise ArgumentError; rescue ArgumentError; 7; end').should be_an_instance_of(Proc)
end
-
context "with an implicit block" do
before do
def meth; lambda; end
diff --git a/spec/ruby/language/rescue_spec.rb b/spec/ruby/language/rescue_spec.rb
index aae16bbefb..aa529328a5 100644
--- a/spec/ruby/language/rescue_spec.rb
+++ b/spec/ruby/language/rescue_spec.rb
@@ -435,9 +435,8 @@ describe "The rescue keyword" do
}.should raise_error(SyntaxError)
end
- ruby_version_is "2.5" do
- it "allows rescue in 'do end' block" do
- lambda = eval <<-ruby
+ it "allows rescue in 'do end' block" do
+ lambda = eval <<-ruby
lambda do
raise SpecificExampleException
rescue SpecificExampleException
@@ -445,8 +444,7 @@ describe "The rescue keyword" do
end.call
ruby
- ScratchPad.recorded.should == [:caught]
- end
+ ScratchPad.recorded.should == [:caught]
end
it "allows 'rescue' in method arguments" do
diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb
index 7eef6d06ca..6b428c3f56 100644
--- a/spec/ruby/language/return_spec.rb
+++ b/spec/ruby/language/return_spec.rb
@@ -250,31 +250,30 @@ describe "The return keyword" do
end
end
- ruby_version_is '2.4.2' do
- describe "at top level" do
- before :each do
- @filename = tmp("top_return.rb")
- ScratchPad.record []
- end
+ describe "at top level" do
+ before :each do
+ @filename = tmp("top_return.rb")
+ ScratchPad.record []
+ end
- after do
- rm_r @filename
- end
+ after do
+ rm_r @filename
+ end
- it "stops file execution" do
- ruby_exe(<<-END_OF_CODE).should == "before return\n"
+ it "stops file execution" do
+ ruby_exe(<<-END_OF_CODE).should == "before return\n"
puts "before return"
return
puts "after return"
END_OF_CODE
- $?.exitstatus.should == 0
- end
+ $?.exitstatus.should == 0
+ end
- describe "within if" do
- it "is allowed" do
- File.write(@filename, <<-END_OF_CODE)
+ describe "within if" do
+ it "is allowed" do
+ File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before if"
if true
return
@@ -283,14 +282,14 @@ describe "The return keyword" do
ScratchPad << "after if"
END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before if"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before if"]
end
+ end
- describe "within while loop" do
- it "is allowed" do
- File.write(@filename, <<-END_OF_CODE)
+ describe "within while loop" do
+ it "is allowed" do
+ File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before while"
while true
return
@@ -299,14 +298,14 @@ describe "The return keyword" do
ScratchPad << "after while"
END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before while"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before while"]
end
+ end
- describe "within a begin" do
- it "is allowed in begin block" do
- File.write(@filename, <<-END_OF_CODE)
+ describe "within a begin" do
+ it "is allowed in begin block" do
+ File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before begin"
begin
return
@@ -315,12 +314,12 @@ describe "The return keyword" do
ScratchPad << "after begin"
END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before begin"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before begin"]
+ end
- it "is allowed in ensure block" do
- File.write(@filename, <<-END_OF_CODE)
+ it "is allowed in ensure block" do
+ File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before begin"
begin
ensure
@@ -330,12 +329,12 @@ describe "The return keyword" do
ScratchPad << "after begin"
END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before begin"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before begin"]
+ end
- it "is allowed in rescue block" do
- File.write(@filename, <<-END_OF_CODE)
+ it "is allowed in rescue block" do
+ File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before begin"
begin
raise
@@ -346,12 +345,12 @@ describe "The return keyword" do
ScratchPad << "after begin"
END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before begin"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before begin"]
+ end
- it "fires ensure block before returning" do
- ruby_exe(<<-END_OF_CODE).should == "within ensure\n"
+ it "fires ensure block before returning" do
+ ruby_exe(<<-END_OF_CODE).should == "within ensure\n"
begin
return
ensure
@@ -360,28 +359,10 @@ describe "The return keyword" do
puts "after begin"
END_OF_CODE
- end
-
- ruby_bug "#14061", "2.4"..."2.5" do
- it "fires ensure block before returning while loads file" do
- File.write(@filename, <<-END_OF_CODE)
- ScratchPad << "before begin"
- begin
- return
- ensure
- ScratchPad << "within ensure"
- end
-
- ScratchPad << "after begin"
- END_OF_CODE
-
- load @filename
- ScratchPad.recorded.should == ["before begin", "within ensure"]
- end
- end
+ end
- it "swallows exception if returns in ensure block" do
- File.write(@filename, <<-END_OF_CODE)
+ it "swallows exception if returns in ensure block" do
+ File.write(@filename, <<-END_OF_CODE)
begin
raise
ensure
@@ -390,45 +371,28 @@ describe "The return keyword" do
end
END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before return"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before return"]
end
+ end
- describe "within a block" do
- it "is allowed" do
- File.write(@filename, <<-END_OF_CODE)
+ describe "within a block" do
+ it "is allowed" do
+ File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before call"
proc { return }.call
ScratchPad << "after call"
END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before call"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before call"]
end
+ end
- describe "within a class" do
- ruby_version_is ""..."2.5" do
- it "is allowed" do
- File.write(@filename, <<-END_OF_CODE)
- class ReturnSpecs::A
- ScratchPad << "before return"
- return
-
- ScratchPad << "after return"
- end
- END_OF_CODE
-
- load @filename
- ScratchPad.recorded.should == ["before return"]
- end
- end
-
- ruby_version_is "2.5" do
- it "raises a SyntaxError" do
- File.write(@filename, <<-END_OF_CODE)
+ describe "within a class" do
+ it "raises a SyntaxError" do
+ File.write(@filename, <<-END_OF_CODE)
class ReturnSpecs::A
ScratchPad << "before return"
return
@@ -437,15 +401,14 @@ describe "The return keyword" do
end
END_OF_CODE
- -> { load @filename }.should raise_error(SyntaxError)
- end
- end
+ -> { load @filename }.should raise_error(SyntaxError)
end
+ end
- describe "within a block within a class" do
- ruby_version_is "2.7" do
- it "is not allowed" do
- File.write(@filename, <<-END_OF_CODE)
+ describe "within a block within a class" do
+ ruby_version_is "2.7" do
+ it "is not allowed" do
+ File.write(@filename, <<-END_OF_CODE)
class ReturnSpecs::A
ScratchPad << "before return"
1.times { return }
@@ -453,57 +416,56 @@ describe "The return keyword" do
end
END_OF_CODE
- -> { load @filename }.should raise_error(LocalJumpError)
- end
+ -> { load @filename }.should raise_error(LocalJumpError)
end
end
+ end
- describe "file loading" do
- it "stops file loading and execution" do
- File.write(@filename, <<-END_OF_CODE)
+ describe "file loading" do
+ it "stops file loading and execution" do
+ File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before return"
return
ScratchPad << "after return"
END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before return"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before return"]
end
+ end
- describe "file requiring" do
- it "stops file loading and execution" do
- File.write(@filename, <<-END_OF_CODE)
+ describe "file requiring" do
+ it "stops file loading and execution" do
+ File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before return"
return
ScratchPad << "after return"
END_OF_CODE
- require @filename
- ScratchPad.recorded.should == ["before return"]
- end
+ require @filename
+ ScratchPad.recorded.should == ["before return"]
end
+ end
- describe "return with argument" do
- ruby_version_is ""..."2.7" do
- it "does not affect exit status" do
- ruby_exe(<<-END_OF_CODE).should == ""
+ describe "return with argument" do
+ ruby_version_is ""..."2.7" do
+ it "does not affect exit status" do
+ ruby_exe(<<-END_OF_CODE).should == ""
return 10
END_OF_CODE
- $?.exitstatus.should == 0
- end
+ $?.exitstatus.should == 0
end
+ end
- ruby_version_is "2.7" do
- it "warns but does not affect exit status" do
- err = ruby_exe(<<-END_OF_CODE, args: "2>&1")
+ ruby_version_is "2.7" do
+ it "warns but does not affect exit status" do
+ err = ruby_exe(<<-END_OF_CODE, args: "2>&1")
return 10
END_OF_CODE
- $?.exitstatus.should == 0
+ $?.exitstatus.should == 0
- err.should =~ /warning: argument of top-level return is ignored/
- end
+ err.should =~ /warning: argument of top-level return is ignored/
end
end
end