Class: RSpec::Core::Formatters::ExceptionPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb

Defined Under Namespace

Classes: Factory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, example, options = {}) ⇒ ExceptionPresenter

Returns a new instance of ExceptionPresenter.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 16

def initialize(exception, example, options={})
  @exception               = exception
  @example                 = example
  @message_color           = options.fetch(:message_color)          { RSpec.configuration.failure_color }
  @description             = options.fetch(:description)            { example.full_description }
  @detail_formatter        = options.fetch(:detail_formatter)       { Proc.new {} }
  @extra_detail_formatter  = options.fetch(:extra_detail_formatter) { Proc.new {} }
  @backtrace_formatter     = options.fetch(:backtrace_formatter)    { RSpec.configuration.backtrace_formatter }
  @indentation             = options.fetch(:indentation, 2)
  @skip_shared_group_trace = options.fetch(:skip_shared_group_trace, false)
  @failure_lines           = options[:failure_lines]
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



12
13
14
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 12

def description
  @description
end

#exampleObject (readonly)

Returns the value of attribute example.



12
13
14
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 12

def example
  @example
end

#exceptionObject (readonly)

Returns the value of attribute exception.



12
13
14
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 12

def exception
  @exception
end

Instance Method Details

#colorized_formatted_backtrace(colorizer = ::RSpec::Core::Formatters::ConsoleCodes) ⇒ Object



73
74
75
76
77
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 73

def colorized_formatted_backtrace(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  formatted_backtrace.map do |backtrace_info|
    colorizer.wrap "# #{backtrace_info}", RSpec.configuration.detail_color
  end
end

#colorized_message_lines(colorizer = ::RSpec::Core::Formatters::ConsoleCodes) ⇒ Object



33
34
35
36
37
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 33

def colorized_message_lines(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  add_shared_group_lines(failure_lines, colorizer).map do |line|
    colorizer.wrap line, message_color
  end
end

#formatted_backtrace(exception = @exception) ⇒ Object



39
40
41
42
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 39

def formatted_backtrace(exception=@exception)
  backtrace_formatter.format_backtrace(exception.backtrace, example.) +
    formatted_cause(exception)
end

#formatted_cause(_) ⇒ Object

:nocov:



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 67

def formatted_cause(exception)
  last_cause = final_exception(exception, [exception])
  cause = []

  if exception.cause
    cause << '------------------'
    cause << '--- Caused by: ---'
    cause << "#{exception_class_name(last_cause)}:" unless exception_class_name(last_cause) =~ /RSpec/

    encoded_string(exception_message_string(last_cause)).split("\n").each do |line|
      cause << "  #{line}"
    end

    unless last_cause.backtrace.nil? || last_cause.backtrace.empty?
      cause << ("  #{backtrace_formatter.format_backtrace(last_cause.backtrace, example.).first}")
    end
  end

  cause
end

#fully_formatted(failure_number, colorizer = ::RSpec::Core::Formatters::ConsoleCodes) ⇒ Object



79
80
81
82
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 79

def fully_formatted(failure_number, colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  lines = fully_formatted_lines(failure_number, colorizer)
  lines.join("\n") << "\n"
end

#fully_formatted_lines(failure_number, colorizer) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 84

def fully_formatted_lines(failure_number, colorizer)
  lines = [
    encoded_description(description),
    detail_formatter.call(example, colorizer),
    formatted_message_and_backtrace(colorizer),
    extra_detail_formatter.call(failure_number, colorizer),
  ].compact.flatten

  lines = indent_lines(lines, failure_number)
  lines.unshift("")
  lines
end

#message_linesObject



29
30
31
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/formatters/exception_presenter.rb', line 29

def message_lines
  add_shared_group_lines(failure_lines, Notifications::NullColorizer)
end