diff options
author | Kevin Deisz <kevin.deisz@gmail.com> | 2019-10-29 10:08:37 -0400 |
---|---|---|
committer | Yuki Nishijima <yk.nishijima@gmail.com> | 2019-11-30 21:08:19 -0500 |
commit | 171803d5d34feb1b4244ca81b9db0a7bc2171c85 (patch) | |
tree | 664ee644da144f28152097fbe5ea43329bfc0576 /test/did_you_mean/spell_checking/test_class_name_check.rb | |
parent | a2fc6a51dd2e1a153559038795e1e2509f9c6a94 (diff) |
Promote did_you_mean to default gem
At the moment, there are some problems with regard to bundler + did_you_mean because of did_you_mean being a bundled gem. Since the vendored version of thor inside bundler and ruby itself explicitly requires did_you_mean, it can become difficult to load it when using Bundler.setup. See this issue: https://github.com/yuki24/did_you_mean/issues/117#issuecomment-482733159 for more details.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2689
Diffstat (limited to 'test/did_you_mean/spell_checking/test_class_name_check.rb')
-rw-r--r-- | test/did_you_mean/spell_checking/test_class_name_check.rb | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/test/did_you_mean/spell_checking/test_class_name_check.rb b/test/did_you_mean/spell_checking/test_class_name_check.rb new file mode 100644 index 0000000000..388dbe89a7 --- /dev/null +++ b/test/did_you_mean/spell_checking/test_class_name_check.rb @@ -0,0 +1,79 @@ +require_relative '../helper' + +module ACRONYM +end + +class Project + def self.bo0k + Bo0k + end +end + +class Book + class TableOfContents; end + + def tableof_contents + TableofContents + end + + class Page + def tableof_contents + TableofContents + end + + def self.tableof_contents + TableofContents + end + end +end + +class ClassNameCheckTest < Test::Unit::TestCase + include DidYouMean::TestHelper + + def test_corrections + error = assert_raise(NameError) { ::Bo0k } + assert_correction "Book", error.corrections + end + + def test_corrections_include_case_specific_class_name + error = assert_raise(NameError) { ::Acronym } + assert_correction "ACRONYM", error.corrections + end + + def test_corrections_include_top_level_class_name + error = assert_raise(NameError) { Project.bo0k } + assert_correction "Book", error.corrections + end + + def test_names_in_corrections_have_namespaces + error = assert_raise(NameError) { ::Book::TableofContents } + assert_correction "Book::TableOfContents", error.corrections + end + + def test_corrections_candidates_for_names_in_upper_level_scopes + error = assert_raise(NameError) { Book::Page.tableof_contents } + assert_correction "Book::TableOfContents", error.corrections + end + + def test_corrections_should_work_from_within_instance_method + error = assert_raise(NameError) { ::Book.new.tableof_contents } + assert_correction "Book::TableOfContents", error.corrections + end + + def test_corrections_should_work_from_within_instance_method_on_nested_class + error = assert_raise(NameError) { ::Book::Page.new.tableof_contents } + assert_correction "Book::TableOfContents", error.corrections + end + + def test_does_not_suggest_user_input + error = assert_raise(NameError) { ::Book::Cover } + + # This is a weird require, but in a multi-threaded condition, a constant may + # be loaded between when a NameError occurred and when the spell checker + # attemps to find a possible suggestion. The manual require here simulates + # a race condition a single test. + require_relative '../fixtures/book' + + assert_empty error.corrections + end +end |