Class: RSpec::Core::DidYouMean Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rspec-core/lib/rspec/core/did_you_mean.rb |
Overview
Wrapper around Ruby’s DidYouMean::SpellChecker
when available to provide file name suggestions.
Class Method Summary
- .new(relative_file_name) ⇒ DidYouMean constructor Internal use only
Instance Attribute Summary
- #relative_file_name readonly Internal use only
Instance Method Summary
-
#call
Internal use only
return a hint if API for ::DidYouMean::SpellChecker not supported :nocov:
-
#formats(probables)
private
Internal use only
:nocov:
- #red_font(mytext) private Internal use only
- #top_and_tail(rspec_format) private Internal use only
Instance Attribute Details
#relative_file_name (readonly)
[ GitHub ]# File 'rspec-core/lib/rspec/core/did_you_mean.rb', line 6
attr_reader :relative_file_name
Instance Method Details
#call
return a hint if API for ::DidYouMean::SpellChecker not supported :nocov:
See additional method definition at line 15.
# File 'rspec-core/lib/rspec/core/did_you_mean.rb', line 26
def call checker = ::DidYouMean::SpellChecker.new(:dictionary => Dir["spec/**/*.rb"]) probables = checker.correct(relative_file_name.sub('./', ''))[0..2] return '' unless probables.any? formats probables end
#formats(probables) (private)
:nocov:
# File 'rspec-core/lib/rspec/core/did_you_mean.rb', line 35
def formats(probables) rspec_format = probables.map { |s, _| "rspec ./#{s}" } red_font(top_and_tail rspec_format) end
#red_font(mytext) (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/did_you_mean.rb', line 45
def red_font(mytext) colorizer = ::RSpec::Core::Formatters::ConsoleCodes colorizer.wrap mytext, :failure end
#top_and_tail(rspec_format) (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/did_you_mean.rb', line 40
def top_and_tail(rspec_format) spaces = ' ' * 20 rspec_format.insert(0, ' - Did you mean?').join("\n#{spaces}") + "\n" end