summaryrefslogtreecommitdiff
path: root/spec/ruby/language/ensure_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/language/ensure_spec.rb')
-rw-r--r--spec/ruby/language/ensure_spec.rb49
1 files changed, 32 insertions, 17 deletions
diff --git a/spec/ruby/language/ensure_spec.rb b/spec/ruby/language/ensure_spec.rb
index e94c523e82..04ff0305ab 100644
--- a/spec/ruby/language/ensure_spec.rb
+++ b/spec/ruby/language/ensure_spec.rb
@@ -6,7 +6,7 @@ describe "An ensure block inside a begin block" do
ScratchPad.record []
end
- it "is executed when an exception is raised in it's corresponding begin block" do
+ it "is executed when an exception is raised in its corresponding begin block" do
-> {
begin
ScratchPad << :begin
@@ -14,12 +14,12 @@ describe "An ensure block inside a begin block" do
ensure
ScratchPad << :ensure
end
- }.should raise_error(EnsureSpec::Error)
+ }.should.raise(EnsureSpec::Error)
ScratchPad.recorded.should == [:begin, :ensure]
end
- it "is executed when an exception is raised and rescued in it's corresponding begin block" do
+ it "is executed when an exception is raised and rescued in its corresponding begin block" do
begin
ScratchPad << :begin
raise "An exception occurred!"
@@ -32,7 +32,7 @@ describe "An ensure block inside a begin block" do
ScratchPad.recorded.should == [:begin, :rescue, :ensure]
end
- it "is executed even when a symbol is thrown in it's corresponding begin block" do
+ it "is executed even when a symbol is thrown in its corresponding begin block" do
catch(:symbol) do
begin
ScratchPad << :begin
@@ -47,7 +47,7 @@ describe "An ensure block inside a begin block" do
ScratchPad.recorded.should == [:begin, :ensure]
end
- it "is executed when nothing is raised or thrown in it's corresponding begin block" do
+ it "is executed when nothing is raised or thrown in its corresponding begin block" do
begin
ScratchPad << :begin
rescue
@@ -74,9 +74,9 @@ describe "An ensure block inside a begin block" do
ensure
raise "from ensure"
end
- }.should raise_error(RuntimeError, "from ensure") do |e|
+ }.should.raise(RuntimeError, "from ensure") { |e|
e.cause.message.should == "from block"
- end
+ }
end
end
@@ -108,7 +108,7 @@ describe "An ensure block inside a method" do
end
it "is executed when an exception is raised in the method" do
- -> { @obj.raise_in_method_with_ensure }.should raise_error(EnsureSpec::Error)
+ -> { @obj.raise_in_method_with_ensure }.should.raise(EnsureSpec::Error)
@obj.executed.should == [:method, :ensure]
end
@@ -149,13 +149,13 @@ describe "An ensure block inside a method" do
it "overrides exception raised in rescue if raises exception itself" do
-> {
@obj.raise_in_rescue_and_raise_in_ensure
- }.should raise_error(RuntimeError, "raised in ensure")
+ }.should.raise(RuntimeError, "raised in ensure")
end
it "suppresses exception raised in method if raises exception itself" do
-> {
@obj.raise_in_method_and_raise_in_ensure
- }.should raise_error(RuntimeError, "raised in ensure")
+ }.should.raise(RuntimeError, "raised in ensure")
end
end
@@ -174,7 +174,7 @@ describe "An ensure block inside a class" do
ScratchPad << :ensure
end
ruby
- }.should raise_error(EnsureSpec::Error)
+ }.should.raise(EnsureSpec::Error)
ScratchPad.recorded.should == [:class, :ensure]
end
@@ -247,7 +247,7 @@ describe "An ensure block inside {} block" do
ensure
}
ruby
- }.should raise_error(SyntaxError)
+ }.should.raise(SyntaxError)
end
end
@@ -256,7 +256,7 @@ describe "An ensure block inside 'do end' block" do
ScratchPad.record []
end
- it "is executed when an exception is raised in it's corresponding begin block" do
+ it "is executed when an exception is raised in its corresponding begin block" do
-> {
eval(<<-ruby).call
lambda do
@@ -266,12 +266,12 @@ describe "An ensure block inside 'do end' block" do
ScratchPad << :ensure
end
ruby
- }.should raise_error(EnsureSpec::Error)
+ }.should.raise(EnsureSpec::Error)
ScratchPad.recorded.should == [:begin, :ensure]
end
- it "is executed when an exception is raised and rescued in it's corresponding begin block" do
+ it "is executed when an exception is raised and rescued in its corresponding begin block" do
eval(<<-ruby).call
lambda do
ScratchPad << :begin
@@ -286,7 +286,7 @@ describe "An ensure block inside 'do end' block" do
ScratchPad.recorded.should == [:begin, :rescue, :ensure]
end
- it "is executed even when a symbol is thrown in it's corresponding begin block" do
+ it "is executed even when a symbol is thrown in its corresponding begin block" do
catch(:symbol) do
eval(<<-ruby).call
lambda do
@@ -303,7 +303,7 @@ describe "An ensure block inside 'do end' block" do
ScratchPad.recorded.should == [:begin, :ensure]
end
- it "is executed when nothing is raised or thrown in it's corresponding begin block" do
+ it "is executed when nothing is raised or thrown in its corresponding begin block" do
eval(<<-ruby).call
lambda do
ScratchPad << :begin
@@ -328,4 +328,19 @@ describe "An ensure block inside 'do end' block" do
result.should == :begin
end
+
+ ruby_version_is "3.4" do
+ it "does not introduce extra backtrace entries" do
+ def foo
+ begin
+ raise "oops"
+ ensure
+ return caller(0, 2) # rubocop:disable Lint/EnsureReturn
+ end
+ end
+ line = __LINE__
+ foo[0].should =~ /#{__FILE__}:#{line-3}:in 'foo'/
+ foo[1].should =~ /#{__FILE__}:#{line+2}:in 'block/
+ end
+ end
end