Sha256: 6a1039e2308c565e31221d7631732f2f3de517c5fb77697d0f6a26e8d4c82323

Contents?: true

Size: 1.33 KB

Versions: 6578

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,578 entries across 6,522 versions & 75 rubygems

Version Path
mux_ruby-3.20.0 vendor/bundle/ruby/3.2.0/gems/rspec-core-3.11.0/lib/rspec/core/did_you_mean.rb
mux_ruby-3.19.0 vendor/bundle/ruby/3.2.0/gems/rspec-core-3.11.0/lib/rspec/core/did_you_mean.rb
cybrid_api_bank_ruby-0.121.24 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_organization_ruby-0.121.24 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_id_ruby-0.121.24 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_bank_ruby-0.121.23 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_organization_ruby-0.121.23 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_id_ruby-0.121.23 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_bank_ruby-0.121.22 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_organization_ruby-0.121.22 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_id_ruby-0.121.22 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_bank_ruby-0.121.21 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_organization_ruby-0.121.21 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_id_ruby-0.121.21 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_organization_ruby-0.121.20 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_bank_ruby-0.121.20 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_id_ruby-0.121.20 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
ory-client-1.15.7 vendor/bundle/ruby/3.1.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_organization_ruby-0.121.18 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb
cybrid_api_id_ruby-0.121.18 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.1/lib/rspec/core/did_you_mean.rb