summaryrefslogtreecommitdiff
path: root/test/did_you_mean/core_ext/test_name_error_extension.rb
diff options
context:
space:
mode:
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.rb27
1 files changed, 17 insertions, 10 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 9dc08dbde3..116c7cd7b9 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,9 @@
require_relative '../helper'
class NameErrorExtensionTest < Test::Unit::TestCase
- SPELL_CHECKERS = DidYouMean::SPELL_CHECKERS
+ include DidYouMean::TestHelper
+
+ SPELL_CHECKERS = DidYouMean.spell_checkers
class TestSpellChecker
def initialize(*); end
@@ -9,18 +11,23 @@ class NameErrorExtensionTest < Test::Unit::TestCase
end
def setup
- @org, SPELL_CHECKERS['NameError'] = SPELL_CHECKERS['NameError'], TestSpellChecker
+ @original_spell_checker = DidYouMean.spell_checkers['NameError']
+ DidYouMean.correct_error(NameError, TestSpellChecker)
@error = assert_raise(NameError){ doesnt_exist }
end
def teardown
- SPELL_CHECKERS['NameError'] = @org
+ DidYouMean.correct_error(NameError, @original_spell_checker)
end
def test_message
- assert_match(/Did you mean\? does_exist/, @error.to_s)
- assert_match(/Did you mean\? does_exist/, @error.message)
+ if Exception.method_defined?(:detailed_message)
+ assert_match(/Did you mean\? does_exist/, @error.detailed_message)
+ else
+ assert_match(/Did you mean\? does_exist/, @error.to_s)
+ assert_match(/Did you mean\? does_exist/, @error.message)
+ end
end
def test_to_s_does_not_make_disruptive_changes_to_error_message
@@ -28,8 +35,8 @@ class NameErrorExtensionTest < Test::Unit::TestCase
raise NameError, "uninitialized constant Object"
end
- error.to_s
- assert_equal 1, error.to_s.scan("Did you mean?").count
+ get_message(error)
+ assert_equal 1, get_message(error).scan("Did you mean?").count
end
def test_correctable_error_objects_are_dumpable
@@ -40,9 +47,9 @@ class NameErrorExtensionTest < Test::Unit::TestCase
e
end
- error.to_s
+ get_message(error)
- assert_equal "undefined method `sizee' for #<File:test_name_error_extension.rb (closed)>",
- Marshal.load(Marshal.dump(error)).original_message
+ assert_match(/^undefined method [`']sizee' for /,
+ Marshal.load(Marshal.dump(error)).original_message)
end
end