Sha256: f090c65807a90113c82511f8e8b5f6e8f067b0bd879bcffdfc32b0d246f72564

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

require_relative 'test_helper'

class SimilarMethodFinderTest < Minitest::Test
  class User
    def friends; end
    def first_name; end
    def descendants; end

    private

    def friend; end

    class << self
      def load; end
    end
  end

  module UserModule
    def from_module; end
  end

  def setup
    user = User.new.extend(UserModule)

    @error_from_instance_method = assert_raises(NoMethodError){ user.flrst_name }
    @error_from_private_method  = assert_raises(NoMethodError){ user.friend }
    @error_from_module_method   = assert_raises(NoMethodError){ user.fr0m_module }
    @error_from_class_method    = assert_raises(NoMethodError){ User.l0ad }
  end

  def test_similar_words
    assert_suggestion @error_from_instance_method.finder.similar_words, :first_name
    assert_suggestion @error_from_private_method.finder.similar_words,  :friends
    assert_suggestion @error_from_module_method.finder.similar_words,   :from_module
    assert_suggestion @error_from_class_method.finder.similar_words,    :load
  end

  def test_did_you_mean?
    assert_match "Did you mean? #first_name",  @error_from_instance_method.did_you_mean?
    assert_match "Did you mean? #friends",     @error_from_private_method.did_you_mean?
    assert_match "Did you mean? #from_module", @error_from_module_method.did_you_mean?
    assert_match "Did you mean? .load",        @error_from_class_method.did_you_mean?
  end

  def test_similar_words_for_long_method_name
    error = assert_raises(NoMethodError){ User.new.dependents }
    assert_suggestion error.finder.similar_words, :descendants
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
did_you_mean-0.9.5 test/similar_method_finder_test.rb
did_you_mean-0.9.4 test/similar_method_finder_test.rb
did_you_mean-0.9.2 test/similar_method_finder_test.rb
did_you_mean-0.9.0 test/similar_method_finder_test.rb