diff options
Diffstat (limited to 'test/did_you_mean')
-rw-r--r-- | test/did_you_mean/core_ext/test_name_error_extension.rb | 7 | ||||
-rw-r--r-- | test/did_you_mean/helper.rb | 4 | ||||
-rw-r--r-- | test/did_you_mean/test_ractor_compatibility.rb | 102 |
3 files changed, 3 insertions, 110 deletions
diff --git a/test/did_you_mean/core_ext/test_name_error_extension.rb b/test/did_you_mean/core_ext/test_name_error_extension.rb index 91871cda9a..9dc08dbde3 100644 --- a/test/did_you_mean/core_ext/test_name_error_extension.rb +++ b/test/did_you_mean/core_ext/test_name_error_extension.rb @@ -1,7 +1,7 @@ require_relative '../helper' class NameErrorExtensionTest < Test::Unit::TestCase - SPELL_CHECKERS = DidYouMean.spell_checkers + SPELL_CHECKERS = DidYouMean::SPELL_CHECKERS class TestSpellChecker def initialize(*); end @@ -9,14 +9,13 @@ class NameErrorExtensionTest < Test::Unit::TestCase end def setup - @original_spell_checker = DidYouMean.spell_checkers['NameError'] - DidYouMean.correct_error(NameError, TestSpellChecker) + @org, SPELL_CHECKERS['NameError'] = SPELL_CHECKERS['NameError'], TestSpellChecker @error = assert_raise(NameError){ doesnt_exist } end def teardown - DidYouMean.correct_error(NameError, @original_spell_checker) + SPELL_CHECKERS['NameError'] = @org end def test_message diff --git a/test/did_you_mean/helper.rb b/test/did_you_mean/helper.rb index 7cb7b10282..d8aa41c3d1 100644 --- a/test/did_you_mean/helper.rb +++ b/test/did_you_mean/helper.rb @@ -4,10 +4,6 @@ module DidYouMean module TestHelper class << self attr_reader :root - - def ractor_compatible? - defined?(Ractor) && RUBY_VERSION >= "3.1.0" - end end if File.file?(File.expand_path('../lib/did_you_mean.rb', __dir__)) diff --git a/test/did_you_mean/test_ractor_compatibility.rb b/test/did_you_mean/test_ractor_compatibility.rb deleted file mode 100644 index 1a9e63997f..0000000000 --- a/test/did_you_mean/test_ractor_compatibility.rb +++ /dev/null @@ -1,102 +0,0 @@ -require_relative './helper' - -return if not DidYouMean::TestHelper.ractor_compatible? - -class RactorCompatibilityTest < Test::Unit::TestCase - include DidYouMean::TestHelper - - class ::Book; end - class FirstNameError < NameError; end - - def test_class_name_suggestion_works_in_ractor - error = Ractor.new { - begin - Boook - rescue NameError => e - e.corrections # It is important to call the #corrections method within Ractor. - e - end - }.take - - assert_correction "Book", error.corrections - end - - def test_key_name_suggestion_works_in_ractor - error = Ractor.new { - begin - hash = { "foo" => 1, bar: 2 } - - hash.fetch(:bax) - rescue KeyError => e - e.corrections # It is important to call the #corrections method within Ractor. - e - end - }.take - - assert_correction ":bar", error.corrections - assert_match "Did you mean? :bar", error.to_s - end - - def test_method_name_suggestion_works_in_ractor - error = Ractor.new { - begin - self.to__s - rescue NoMethodError => e - e.corrections # It is important to call the #corrections method within Ractor. - e - end - }.take - - assert_correction :to_s, error.corrections - assert_match "Did you mean? to_s", error.to_s - end - - if defined?(::NoMatchingPatternKeyError) - def test_pattern_key_name_suggestion_works_in_ractor - error = Ractor.new { - begin - eval(<<~RUBY, binding, __FILE__, __LINE__) - hash = {foo: 1, bar: 2, baz: 3} - hash => {fooo:} - fooo = 1 # suppress "unused variable: fooo" warning - RUBY - rescue NoMatchingPatternKeyError => e - e.corrections # It is important to call the #corrections method within Ractor. - e - end - }.take - - assert_correction ":foo", error.corrections - assert_match "Did you mean? :foo", error.to_s - end - end - - def test_can_raise_other_name_error_in_ractor - error = Ractor.new { - begin - raise FirstNameError, "Other name error" - rescue FirstNameError => e - e.corrections # It is important to call the #corrections method within Ractor. - e - end - }.take - - assert_not_match(/Did you mean\?/, error.message) - end - - def test_variable_name_suggestion_works_in_ractor - error = Ractor.new { - in_ractor = in_ractor = 1 - - begin - in_reactor - rescue NameError => e - e.corrections # It is important to call the #corrections method within Ractor. - e - end - }.take - - assert_correction :in_ractor, error.corrections - assert_match "Did you mean? in_ractor", error.to_s - end -end |