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
100
101
# 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_colorized: false
      }
    ]
  end
end

Instance Method Details

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

Override to only color uncolored lines in red and to not color empty lines



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/super_diff/rspec/monkey_patches.rb', line 105

def colorized_message_lines(colorizer = ::RSpec::Core::Formatters::ConsoleCodes)
  lines = failure_line_groups.flat_map do |group|
    if group[:already_colorized]
      group[:lines]
    else
      group[:lines].map do |line|
        if line.strip.empty?
          line
        else
          indentation = line[/^[ ]+/]
          rest = colorizer.wrap(line.sub(/^[ ]+/, ''), message_color)

          if indentation
            indentation + rest
          else
            rest
          end
        end
      end
    end
  end

  add_shared_group_lines(lines, colorizer)
end