Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 640db96

Browse files
committed
Fix up did_you_mean nastiness
1 parent 830cbae commit 640db96

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/syntax_tree/basic_visitor.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ def corrections
3333
).correct(visit_method)
3434
end
3535

36-
DidYouMean.correct_error(VisitMethodError, self)
36+
# In some setups with Ruby you can turn off DidYouMean, so we're going to
37+
# respect that setting here.
38+
if defined?(DidYouMean) && DidYouMean.method_defined?(:correct_error)
39+
DidYouMean.correct_error(VisitMethodError, self)
40+
end
3741
end
3842

3943
class << self

test/visitor_test.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,18 @@ def initialize
4040
end
4141
end
4242

43-
def test_visit_method_correction
44-
error = assert_raises { Visitor.visit_method(:visit_binar) }
45-
assert_match(/visit_binary/, error.message)
43+
if defined?(DidYouMean) && DidYouMean.method_defined?(:correct_error)
44+
def test_visit_method_correction
45+
error = assert_raises { Visitor.visit_method(:visit_binar) }
46+
message =
47+
if Exception.method_defined?(:detailed_message)
48+
error.detailed_message
49+
else
50+
error.message
51+
end
52+
53+
assert_match(/visit_binary/, message)
54+
end
4655
end
4756
end
4857
end

0 commit comments

Comments
 (0)