Skip to content

Commit

Permalink
Merge pull request #1170 from herwinw/exception_detailed_message
Browse files Browse the repository at this point in the history
Extends specs of Exception#detailed_message
  • Loading branch information
andrykonchin authored Jun 27, 2024
2 parents 5192887 + 4489e05 commit 3d4f1e5
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions core/exception/detailed_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ def exception.detailed_message(**)
exception.full_message(highlight: false).should.include? "<prefix>new error<suffix>"
end

it "accepts highlight keyword argument and adds escape control sequences" do
RuntimeError.new("new error").detailed_message(highlight: true).should == "\e[1mnew error (\e[1;4mRuntimeError\e[m\e[1m)\e[m"
end

it "allows and ignores other keyword arguments" do
RuntimeError.new("new error").detailed_message(foo: true).should == "new error (RuntimeError)"
end

it "returns just a message if exception class is anonymous" do
Class.new(RuntimeError).new("message").detailed_message.should == "message"
end
Expand All @@ -31,13 +23,30 @@ def exception.detailed_message(**)
RuntimeError.new("").detailed_message.should == "unhandled exception"
end

it "returns just class name for an instance of RuntimeError subclass with empty message" do
it "returns just class name for an instance other than RuntimeError with empty message" do
DetailedMessageSpec::C.new("").detailed_message.should == "DetailedMessageSpec::C"
StandardError.new("").detailed_message.should == "StandardError"
end

it "returns a generated class name for an instance of RuntimeError anonymous subclass with empty message" do
klass = Class.new(RuntimeError)
klass.new("").detailed_message.should =~ /\A#<Class:0x\h+>\z/
end

it "accepts highlight keyword argument and adds escape control sequences" do
RuntimeError.new("new error").detailed_message(highlight: true).should == "\e[1mnew error (\e[1;4mRuntimeError\e[m\e[1m)\e[m"
end

it "accepts highlight keyword argument and adds escape control sequences for an instance of RuntimeError with empty message" do
RuntimeError.new("").detailed_message(highlight: true).should == "\e[1;4munhandled exception\e[m"
end

it "accepts highlight keyword argument and adds escape control sequences for an instance other than RuntimeError with empty message" do
StandardError.new("").detailed_message(highlight: true).should == "\e[1;4mStandardError\e[m"
end

it "allows and ignores other keyword arguments" do
RuntimeError.new("new error").detailed_message(foo: true).should == "new error (RuntimeError)"
end
end
end

0 comments on commit 3d4f1e5

Please sign in to comment.