Sha256: 6a1039e2308c565e31221d7631732f2f3de517c5fb77697d0f6a26e8d4c82323
Contents?: true
Size: 1.33 KB
Versions: 6579
Compression:
Stored size: 1.33 KB
Contents
module RSpec module Core # @private # Wrapper around Ruby's `DidYouMean::SpellChecker` when available to provide file name suggestions. class DidYouMean attr_reader :relative_file_name def initialize(relative_file_name) @relative_file_name = relative_file_name end if defined?(::DidYouMean::SpellChecker) # provide probable suggestions 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 else # return a hint if API for ::DidYouMean::SpellChecker not supported def call "\nHint: Install the `did_you_mean` gem in order to provide suggestions for similarly named files." end end private def formats(probables) rspec_format = probables.map { |s, _| "rspec ./#{s}" } red_font(top_and_tail rspec_format) end def top_and_tail(rspec_format) spaces = ' ' * 20 rspec_format.insert(0, ' - Did you mean?').join("\n#{spaces}") + "\n" end def red_font(mytext) colorizer = ::RSpec::Core::Formatters::ConsoleCodes colorizer.wrap mytext, :failure end end end end
Version data entries
6,579 entries across 6,523 versions & 75 rubygems