Class: RSpec::Core::Formatters::ExceptionPresenter
- Inherits:
-
Object
- Object
- RSpec::Core::Formatters::ExceptionPresenter
- 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
-
#colorized_message_lines(colorizer = ::RSpec::Core::Formatters::ConsoleCodes) ⇒ Object
Override to only color uncolored lines in red and to not color empty lines.
-
#initialize(exception, example, options = {}) ⇒ ExceptionPresenter
constructor
A new instance of ExceptionPresenter.
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, ={}) @exception = exception @example = example @message_color = .fetch(:message_color) { RSpec.configuration.failure_color } @description = .fetch(:description) { example.full_description } @detail_formatter = .fetch(:detail_formatter) { Proc.new {} } @extra_detail_formatter = .fetch(:extra_detail_formatter) { Proc.new {} } @backtrace_formatter = .fetch(:backtrace_formatter) { RSpec.configuration.backtrace_formatter } @indentation = .fetch(:indentation, 2) @skip_shared_group_trace = .fetch(:skip_shared_group_trace, false) # Patch to convert options[:failure_lines] to groups if .include?(:failure_lines) @failure_line_groups = [ { lines: [: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 (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(/^[ ]+/, ''), ) if indentation indentation + rest else rest end end end end end add_shared_group_lines(lines, colorizer) end |