Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extends specs of Exception#detailed_message #1170

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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