summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatthew Boeh <m@mboeh.com>2022-12-05 05:16:27 -0800
committergit <svn-admin@ruby-lang.org>2022-12-05 13:16:33 +0000
commit1602d75c34c39f6d2f5a505a6532c3664288ef06 (patch)
treebbb4f742941938167bfb4412d3444182a041c70e /test
parent74923aaf31ae49cd372f2fe54baa4115a20bfe76 (diff)
[ruby/did_you_mean] Do not suggest #name= for #name and vice versa
(https://github.com/ruby/did_you_mean/pull/180) * Do not suggest #name= for #name and vice versa * Avoid allocating unnecessary MatchData Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com> Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>
Diffstat (limited to 'test')
-rw-r--r--test/did_you_mean/spell_checking/test_method_name_check.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/did_you_mean/spell_checking/test_method_name_check.rb b/test/did_you_mean/spell_checking/test_method_name_check.rb
index d2e46d58f3..4daaf7cec7 100644
--- a/test/did_you_mean/spell_checking/test_method_name_check.rb
+++ b/test/did_you_mean/spell_checking/test_method_name_check.rb
@@ -4,6 +4,8 @@ class MethodNameCheckTest < Test::Unit::TestCase
include DidYouMean::TestHelper
class User
+ attr_writer :writer
+ attr_reader :reader
def friends; end
def first_name; end
def descendants; end
@@ -144,4 +146,20 @@ class MethodNameCheckTest < Test::Unit::TestCase
assert_correction [], error.corrections
assert_not_match(/Did you mean\? +yield/, get_message(error))
end if RUBY_ENGINE != "jruby"
+
+ # Do not suggest `name=` for `name`
+ def test_does_not_suggest_writer
+ error = assert_raise(NoMethodError) { @user.writer }
+
+ assert_correction [], error.corrections
+ assert_not_match(/Did you mean\? writer=/, get_message(error))
+ end
+
+ # Do not suggest `name` for `name=`
+ def test_does_not_suggest_reader
+ error = assert_raise(NoMethodError) { @user.reader = 1 }
+
+ assert_correction [], error.corrections
+ assert_not_match(/Did you mean\? reader/, get_message(error))
+ end
end