class RSpec::Core::DidYouMean
@private Wrapper around Ruby’s ‘DidYouMean::SpellChecker` when available to provide file name suggestions.
Attributes
Public Class Methods
Source
# File lib/rspec/core/did_you_mean.rb, line 8 def initialize(relative_file_name) @relative_file_name = relative_file_name end
Public Instance Methods
Source
# File lib/rspec/core/did_you_mean.rb, line 15 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
provide probable suggestions :nocov: - not installed on CI
Private Instance Methods
Source
# File 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
:nocov:
Source
# File lib/rspec/core/did_you_mean.rb, line 45 def red_font(mytext) colorizer = ::RSpec::Core::Formatters::ConsoleCodes colorizer.wrap mytext, :failure end
Source
# File 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