class RSpec::Core::Formatters::SyntaxHighlighter

@private Provides terminal syntax highlighting of code snippets when coderay is available.

Constants

WindowsImplementation

@private

Public Class Methods

attempt_to_add_rspec_terms_to_coderay_keywords() click to toggle source

rubocop:disable Lint/RescueException rubocop:disable Lint/HandleExceptions

# File lib/rspec/core/formatters/syntax_highlighter.rb, line 18
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
new(configuration) click to toggle source
# File lib/rspec/core/formatters/syntax_highlighter.rb, line 8
def initialize(configuration)
  @configuration = configuration
end

Public Instance Methods

highlight(lines) click to toggle source
# File lib/rspec/core/formatters/syntax_highlighter.rb, line 12
def highlight(lines)
  implementation.highlight_syntax(lines)
end

Private Instance Methods

color_enabled_implementation() click to toggle source
# File lib/rspec/core/formatters/syntax_highlighter.rb, line 50
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
implementation() click to toggle source

:nocov:

# File lib/rspec/core/formatters/syntax_highlighter.rb, line 39
def implementation
  WindowsImplementation
end