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

Inherits:
Object
  • Object
show all
Defined in:
lib/super_diff/rspec/monkey_patches.rb

Constant Summary collapse

RESET_CODE =

UPDATE: Copy from SyntaxHighlighter::CodeRayImplementation

"\e[0m"

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ExceptionPresenter.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/super_diff/rspec/monkey_patches.rb', line 82

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)
  # Patch to convert options[:failure_lines] to groups
  if options.include?(:failure_lines)
    @failure_line_groups = {
      lines: options[:failure_lines],
      already_colored: false
    }
  end
end

Instance Method Details

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

Override to only color uncolored lines in red



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/super_diff/rspec/monkey_patches.rb', line 102

def colorized_message_lines(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  lines = failure_line_groups.flat_map do |group|
    if group[:already_colored]
      group[:lines]
    else
      group[:lines].map do |line|
        colorizer.wrap(line, message_color)
      end
    end
  end

  add_shared_group_lines(lines, colorizer)
end