summaryrefslogtreecommitdiff
path: root/spec/ruby/core/exception
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/exception')
-rw-r--r--spec/ruby/core/exception/full_message_spec.rb110
-rw-r--r--spec/ruby/core/exception/key_error_spec.rb22
-rw-r--r--spec/ruby/core/exception/name_error_spec.rb12
-rw-r--r--spec/ruby/core/exception/no_method_error_spec.rb12
-rw-r--r--spec/ruby/core/exception/signal_exception_spec.rb6
-rw-r--r--spec/ruby/core/exception/top_level_spec.rb42
6 files changed, 95 insertions, 109 deletions
diff --git a/spec/ruby/core/exception/full_message_spec.rb b/spec/ruby/core/exception/full_message_spec.rb
index 9cac9fb037..4cece9ebf9 100644
--- a/spec/ruby/core/exception/full_message_spec.rb
+++ b/spec/ruby/core/exception/full_message_spec.rb
@@ -12,81 +12,77 @@ describe "Exception#full_message" do
full_message.should include "b.rb:2"
end
- ruby_version_is "2.5.1" do
- it "supports :highlight option and adds escape sequences to highlight some strings" do
- e = RuntimeError.new("Some runtime error")
+ it "supports :highlight option and adds escape sequences to highlight some strings" do
+ e = RuntimeError.new("Some runtime error")
- full_message = e.full_message(highlight: true, order: :bottom)
- full_message.should include "\e[1mTraceback\e[m (most recent call last)"
- full_message.should include "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)"
+ full_message = e.full_message(highlight: true, order: :bottom)
+ full_message.should include "\e[1mTraceback\e[m (most recent call last)"
+ full_message.should include "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)"
- full_message = e.full_message(highlight: false, order: :bottom)
- full_message.should include "Traceback (most recent call last)"
- full_message.should include "Some runtime error (RuntimeError)"
- end
+ full_message = e.full_message(highlight: false, order: :bottom)
+ full_message.should include "Traceback (most recent call last)"
+ full_message.should include "Some runtime error (RuntimeError)"
+ end
- it "supports :order option and places the error message and the backtrace at the top or the bottom" do
- e = RuntimeError.new("Some runtime error")
- e.set_backtrace(["a.rb:1", "b.rb:2"])
+ it "supports :order option and places the error message and the backtrace at the top or the bottom" do
+ e = RuntimeError.new("Some runtime error")
+ e.set_backtrace(["a.rb:1", "b.rb:2"])
- e.full_message(order: :top, highlight: false).should =~ /a.rb:1.*b.rb:2/m
- e.full_message(order: :bottom, highlight: false).should =~ /b.rb:2.*a.rb:1/m
- end
+ e.full_message(order: :top, highlight: false).should =~ /a.rb:1.*b.rb:2/m
+ e.full_message(order: :bottom, highlight: false).should =~ /b.rb:2.*a.rb:1/m
+ end
- it "shows the caller if the exception has no backtrace" do
- e = RuntimeError.new("Some runtime error")
- e.backtrace.should == nil
- full_message = e.full_message(highlight: false, order: :top)
- full_message.should include("#{__FILE__}:#{__LINE__-1}:in `")
- full_message.should include("': Some runtime error (RuntimeError)\n")
- end
+ it "shows the caller if the exception has no backtrace" do
+ e = RuntimeError.new("Some runtime error")
+ e.backtrace.should == nil
+ full_message = e.full_message(highlight: false, order: :top)
+ full_message.should include("#{__FILE__}:#{__LINE__-1}:in `")
+ full_message.should include("': Some runtime error (RuntimeError)\n")
+ end
- it "shows the exception class at the end of the first line of the message when the message contains multiple lines" do
- begin
- line = __LINE__; raise "first line\nsecond line"
- rescue => e
- full_message = e.full_message(highlight: false, order: :top).lines
- full_message[0].should include("#{__FILE__}:#{line}:in `")
- full_message[0].should include(": first line (RuntimeError)\n")
- full_message[1].should == "second line\n"
- end
+ it "shows the exception class at the end of the first line of the message when the message contains multiple lines" do
+ begin
+ line = __LINE__; raise "first line\nsecond line"
+ rescue => e
+ full_message = e.full_message(highlight: false, order: :top).lines
+ full_message[0].should include("#{__FILE__}:#{line}:in `")
+ full_message[0].should include(": first line (RuntimeError)\n")
+ full_message[1].should == "second line\n"
end
end
- ruby_version_is "2.6" do
- it "contains cause of exception" do
+ it "contains cause of exception" do
+ begin
begin
- begin
- raise 'the cause'
- rescue
- raise 'main exception'
- end
- rescue => e
- exception = e
+ raise 'the cause'
+ rescue
+ raise 'main exception'
end
-
- exception.full_message.should include "main exception"
- exception.full_message.should include "the cause"
+ rescue => e
+ exception = e
end
- it 'contains all the chain of exceptions' do
+ exception.full_message.should include "main exception"
+ exception.full_message.should include "the cause"
+ end
+
+ it 'contains all the chain of exceptions' do
+ begin
begin
begin
- begin
- raise 'origin exception'
- rescue
- raise 'intermediate exception'
- end
+ raise 'origin exception'
rescue
- raise 'last exception'
+ raise 'intermediate exception'
end
- rescue => e
- exception = e
+ rescue
+ raise 'last exception'
end
-
- exception.full_message.should include "last exception"
- exception.full_message.should include "intermediate exception"
- exception.full_message.should include "origin exception"
+ rescue => e
+ exception = e
end
+
+ exception.full_message.should include "last exception"
+ exception.full_message.should include "intermediate exception"
+ exception.full_message.should include "origin exception"
end
end
diff --git a/spec/ruby/core/exception/key_error_spec.rb b/spec/ruby/core/exception/key_error_spec.rb
index 71bf2b46ff..c5e2b1efbc 100644
--- a/spec/ruby/core/exception/key_error_spec.rb
+++ b/spec/ruby/core/exception/key_error_spec.rb
@@ -1,21 +1,19 @@
require_relative '../../spec_helper'
describe "KeyError" do
- ruby_version_is "2.6" do
- it "accepts :receiver and :key options" do
- receiver = mock("receiver")
- key = mock("key")
+ it "accepts :receiver and :key options" do
+ receiver = mock("receiver")
+ key = mock("key")
- error = KeyError.new(receiver: receiver, key: key)
+ error = KeyError.new(receiver: receiver, key: key)
- error.receiver.should == receiver
- error.key.should == key
+ error.receiver.should == receiver
+ error.key.should == key
- error = KeyError.new("message", receiver: receiver, key: key)
+ error = KeyError.new("message", receiver: receiver, key: key)
- error.message.should == "message"
- error.receiver.should == receiver
- error.key.should == key
- end
+ error.message.should == "message"
+ error.receiver.should == receiver
+ error.key.should == key
end
end
diff --git a/spec/ruby/core/exception/name_error_spec.rb b/spec/ruby/core/exception/name_error_spec.rb
index e901a80c42..ddd51a92e5 100644
--- a/spec/ruby/core/exception/name_error_spec.rb
+++ b/spec/ruby/core/exception/name_error_spec.rb
@@ -5,15 +5,13 @@ describe "NameError.new" do
NameError.new("msg","name").name.should == "name"
end
- ruby_version_is "2.6" do
- it "accepts a :receiver keyword argument" do
- receiver = mock("receiver")
+ it "accepts a :receiver keyword argument" do
+ receiver = mock("receiver")
- error = NameError.new("msg", :name, receiver: receiver)
+ error = NameError.new("msg", :name, receiver: receiver)
- error.receiver.should == receiver
- error.name.should == :name
- end
+ error.receiver.should == receiver
+ error.name.should == :name
end
end
diff --git a/spec/ruby/core/exception/no_method_error_spec.rb b/spec/ruby/core/exception/no_method_error_spec.rb
index a93ef2187e..8428ba0382 100644
--- a/spec/ruby/core/exception/no_method_error_spec.rb
+++ b/spec/ruby/core/exception/no_method_error_spec.rb
@@ -10,15 +10,13 @@ describe "NoMethodError.new" do
NoMethodError.new("msg").message.should == "msg"
end
- ruby_version_is "2.6" do
- it "accepts a :receiver keyword argument" do
- receiver = mock("receiver")
+ it "accepts a :receiver keyword argument" do
+ receiver = mock("receiver")
- error = NoMethodError.new("msg", :name, receiver: receiver)
+ error = NoMethodError.new("msg", :name, receiver: receiver)
- error.receiver.should == receiver
- error.name.should == :name
- end
+ error.receiver.should == receiver
+ error.name.should == :name
end
end
diff --git a/spec/ruby/core/exception/signal_exception_spec.rb b/spec/ruby/core/exception/signal_exception_spec.rb
index 2d2179a628..566bcb4672 100644
--- a/spec/ruby/core/exception/signal_exception_spec.rb
+++ b/spec/ruby/core/exception/signal_exception_spec.rb
@@ -30,10 +30,8 @@ describe "SignalException.new" do
-> { SignalException.new("NONEXISTENT") }.should raise_error(ArgumentError)
end
- ruby_version_is "2.6" do
- it "raises an exception with an invalid first argument type" do
- -> { SignalException.new(Object.new) }.should raise_error(ArgumentError)
- end
+ it "raises an exception with an invalid first argument type" do
+ -> { SignalException.new(Object.new) }.should raise_error(ArgumentError)
end
it "takes a signal symbol without SIG prefix as the first argument" do
diff --git a/spec/ruby/core/exception/top_level_spec.rb b/spec/ruby/core/exception/top_level_spec.rb
index 5c4514f694..b47648425e 100644
--- a/spec/ruby/core/exception/top_level_spec.rb
+++ b/spec/ruby/core/exception/top_level_spec.rb
@@ -5,29 +5,27 @@ describe "An Exception reaching the top level" do
ruby_exe('raise "foo"', args: "2>&1", exit_status: 1).should.include?("in `<main>': foo (RuntimeError)")
end
- ruby_version_is "2.6" do
- it "the Exception#cause is printed to STDERR with backtraces" do
- code = <<-RUBY
- def raise_cause
- raise "the cause"
- end
- def raise_wrapped
- raise "wrapped"
- end
- begin
- raise_cause
- rescue
- raise_wrapped
- end
- RUBY
- lines = ruby_exe(code, args: "2>&1", exit_status: 1).lines
- lines.reject! { |l| l.include?('rescue in') }
- lines.map! { |l| l.chomp[/:(in.+)/, 1] }
- lines.should == ["in `raise_wrapped': wrapped (RuntimeError)",
- "in `<main>'",
- "in `raise_cause': the cause (RuntimeError)",
- "in `<main>'"]
+ it "the Exception#cause is printed to STDERR with backtraces" do
+ code = <<-RUBY
+ def raise_cause
+ raise "the cause"
+ end
+ def raise_wrapped
+ raise "wrapped"
+ end
+ begin
+ raise_cause
+ rescue
+ raise_wrapped
end
+ RUBY
+ lines = ruby_exe(code, args: "2>&1", exit_status: 1).lines
+ lines.reject! { |l| l.include?('rescue in') }
+ lines.map! { |l| l.chomp[/:(in.+)/, 1] }
+ lines.should == ["in `raise_wrapped': wrapped (RuntimeError)",
+ "in `<main>'",
+ "in `raise_cause': the cause (RuntimeError)",
+ "in `<main>'"]
end
describe "with a custom backtrace" do