diff --git a/lib/net/imap.rb b/lib/net/imap.rb index 07a2f8d6..e7e127e3 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -2496,6 +2496,12 @@ def idle_done end end + RESPONSES_DEPRECATION_MSG = + "Pass a type or block to #responses, " \ + "set config.responses_without_block to :silence_deprecation_warning, " \ + "or use #extract_responses or #clear_responses." + private_constant :RESPONSES_DEPRECATION_MSG + # :call-seq: # responses {|hash| ...} -> block result # responses(type) {|array| ...} -> block result @@ -2590,9 +2596,9 @@ def responses(type = nil) else case config.responses_without_block when :raise - raise ArgumentError, "Pass a block or use #clear_responses" + raise ArgumentError, RESPONSES_DEPRECATION_MSG when :warn - warn("DEPRECATED: pass a block or use #clear_responses", uplevel: 1) + warn(RESPONSES_DEPRECATION_MSG, uplevel: 1) end @responses end diff --git a/test/net/imap/test_imap_responses.rb b/test/net/imap/test_imap_responses.rb index 7e2cbc2f..07e2c9a8 100644 --- a/test/net/imap/test_imap_responses.rb +++ b/test/net/imap/test_imap_responses.rb @@ -99,7 +99,14 @@ def for_each_config_option(imap) end def assert_responses_warn - assert_warn(/Pass a block.*or.*clear_responses/i) do + assert_warn( + / + (?=(?-x)Pass a type or block to #responses\b) + (?=.*config\.responses_without_block.*:silence_deprecation_warning\b) + (?=.*\#extract_responses\b) + .*\#clear_responses\b + /ix + ) do yield end end