File: detailed_message_spec.rb

package info (click to toggle)
jruby 9.4.8.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 89,244 kB
  • sloc: ruby: 548,574; java: 276,189; yacc: 25,873; ansic: 6,178; xml: 6,111; sh: 1,855; sed: 94; makefile: 78; jsp: 48; tcl: 40; exp: 12
file content (52 lines) | stat: -rw-r--r-- 2,298 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require_relative '../../spec_helper'
require_relative 'fixtures/common'

describe "Exception#detailed_message" do
  ruby_version_is "3.2" do
    it "returns decorated message" do
      RuntimeError.new("new error").detailed_message.should == "new error (RuntimeError)"
    end

    it "is called by #full_message to allow message customization" do
      exception = Exception.new("new error")
      def exception.detailed_message(**)
        "<prefix>#{message}<suffix>"
      end
      exception.full_message(highlight: false).should.include? "<prefix>new error<suffix>"
    end

    it "returns just a message if exception class is anonymous" do
      Class.new(RuntimeError).new("message").detailed_message.should == "message"
    end

    it "returns 'unhandled exception' for an instance of RuntimeError with empty message" do
      RuntimeError.new("").detailed_message.should == "unhandled exception"
    end

    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