From 15231a85c55de9d1deb6c628557b57559ecf81c7 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 28 Oct 2024 23:58:12 +0900 Subject: [PATCH] Suppress smaller `max_snippet_width` warning --- test/test_error_highlight.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/test_error_highlight.rb b/test/test_error_highlight.rb index a59550b..09f29dc 100644 --- a/test/test_error_highlight.rb +++ b/test/test_error_highlight.rb @@ -1358,8 +1358,18 @@ def test_errors_on_extremely_small_terminal_window def test_errors_on_terminal_window_smaller_than_min_width custom_max_width = 5 original_max_width = ErrorHighlight::DefaultFormatter.max_snippet_width + min_snippet_width = ErrorHighlight::DefaultFormatter::MIN_SNIPPET_WIDTH - ErrorHighlight::DefaultFormatter.max_snippet_width = custom_max_width + warning = nil + original_warn = Warning.method(:warn) + Warning.define_singleton_method(:warn) {|s| warning = s} + begin + ErrorHighlight::DefaultFormatter.max_snippet_width = custom_max_width + ensure + Warning.singleton_class.remove_method(:warn) + Warning.define_singleton_method(:warn, original_warn) + end + assert_match "'max_snippet_width' adjusted to minimum value of #{min_snippet_width}", warning assert_error_message(NoMethodError, <<~END) do undefined method `time' for #{ ONE_RECV_MESSAGE }