class RSpec::Core::Formatters::SyntaxHighlighter
when coderay is available.
Provides terminal syntax highlighting of code snippets
@private
def self.attempt_to_add_rspec_terms_to_coderay_keywords
rubocop:disable Lint/RescueException
def self.attempt_to_add_rspec_terms_to_coderay_keywords CodeRay::Scanners::Ruby::Patterns::IDENT_KIND.add(%w[ describe context it specify before after around let subject expect allow ], :keyword) rescue Exception # Mutating CodeRay's contants like this is not a public API # and might not always work. If we cannot add our keywords # to CodeRay it is not a big deal and not worth raising an # error over, so we ignore it. end
def color_enabled_implementation
def color_enabled_implementation @color_enabled_implementation ||= begin require 'coderay' self.class.attempt_to_add_rspec_terms_to_coderay_keywords CodeRayImplementation rescue LoadError NoSyntaxHighlightingImplementation end end
def highlight(lines)
def highlight(lines) implementation.highlight_syntax(lines) end
def implementation
def implementation WindowsImplementation end
def implementation
def implementation return color_enabled_implementation if @configuration.color_enabled? NoSyntaxHighlightingImplementation end
def initialize(configuration)
def initialize(configuration) @configuration = configuration end