Class: RSpec::Core::Formatters::SyntaxHighlighter Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Inherits: | Object |
Defined in: | rspec-core/lib/rspec/core/formatters/syntax_highlighter.rb |
Overview
Provides terminal syntax highlighting of code snippets when coderay is available.
Constant Summary
-
WindowsImplementation =
Not sure why, but our code above (and/or coderay itself) does not work on Windows, so we disable the feature on Windows.
NoSyntaxHighlightingImplementation
Class Method Summary
-
.attempt_to_add_rspec_terms_to_coderay_keywords
Internal use only
rubocop:disable Lint/HandleExceptions.
- .new(configuration) ⇒ SyntaxHighlighter constructor Internal use only
Instance Method Summary
- #highlight(lines) Internal use only
- #color_enabled_implementation private Internal use only
-
#implementation
private
Internal use only
:nocov:
Class Method Details
.attempt_to_add_rspec_terms_to_coderay_keywords
rubocop:disable Lint/HandleExceptions
# File 'rspec-core/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
Instance Method Details
#color_enabled_implementation (private)
[ GitHub ]# File 'rspec-core/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
#highlight(lines)
[ GitHub ]# File 'rspec-core/lib/rspec/core/formatters/syntax_highlighter.rb', line 12
def highlight(lines) implementation.highlight_syntax(lines) end
#implementation (private)
:nocov:
See additional method definition at line 39.
# File 'rspec-core/lib/rspec/core/formatters/syntax_highlighter.rb', line 44
def implementation WindowsImplementation end