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/core_ext/test_name_error_extension.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/core_ext/test_name_error_extension.rb')
-rw-r--r-- | test/did_you_mean/core_ext/test_name_error_extension.rb | 48 |
1 files changed, 48 insertions, 0 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 new file mode 100644 index 0000000000..dc571a8f4c --- /dev/null +++ b/test/did_you_mean/core_ext/test_name_error_extension.rb @@ -0,0 +1,48 @@ +require_relative '../helper' + +class NameErrorExtensionTest < Test::Unit::TestCase + SPELL_CHECKERS = DidYouMean::SPELL_CHECKERS + + class TestSpellChecker + def initialize(*); end + def corrections; ["does_exist"]; end + end + + def setup + @org, SPELL_CHECKERS['NameError'] = SPELL_CHECKERS['NameError'], TestSpellChecker + + @error = assert_raise(NameError){ doesnt_exist } + end + + def teardown + SPELL_CHECKERS['NameError'] = @org + end + + def test_message + assert_match(/Did you mean\? does_exist/, @error.to_s) + assert_match(/Did you mean\? does_exist/, @error.message) + end + + def test_to_s_does_not_make_disruptive_changes_to_error_message + error = assert_raise(NameError) do + raise NameError, "uninitialized constant Object" + end + + error.to_s + assert_equal 1, error.to_s.scan("Did you mean?").count + end + + def test_correctable_error_objects_are_dumpable + error = + begin + Dir.chdir(__dir__) { File.open('test_name_error_extension.rb').sizee } + rescue NoMethodError => e + e + end + + error.to_s + + assert_equal "undefined method `sizee' for #<File:test_name_error_extension.rb>", + Marshal.load(Marshal.dump(error)).original_message + end +end |