123456789_123456789_123456789_123456789_123456789_

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

Instance Attribute Summary

Instance Method Summary

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

See additional method definition at line 14.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/did_you_mean.rb', line 23

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)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/did_you_mean.rb', line 30

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 40

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 35

def top_and_tail(rspec_format)
  spaces = ' ' * 20
  rspec_format.insert(0, ' - Did you mean?').join("\n#{spaces}") + "\n"
end