Class: RSpec::Core::DidYouMean

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/did_you_mean.rb

Overview

Wrapper around Ruby’s ‘DidYouMean::SpellChecker` when available to provide file name suggestions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relative_file_name) ⇒ DidYouMean

Returns a new instance of DidYouMean.



8
9
10
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/did_you_mean.rb', line 8

def initialize(relative_file_name)
  @relative_file_name = relative_file_name
end

Instance Attribute Details

#relative_file_nameObject (readonly)

Returns the value of attribute relative_file_name.



6
7
8
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/did_you_mean.rb', line 6

def relative_file_name
  @relative_file_name
end

Instance Method Details

#callObject

return a hint if API for ::DidYouMean::SpellChecker not supported



14
15
16
17
18
19
20
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/did_you_mean.rb', line 14

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