Skip to content

Commit

Permalink
🔊 Update #responses deprecation message
Browse files Browse the repository at this point in the history
The same message is used for both the warning and the ArgumentError.
  • Loading branch information
nevans committed Oct 13, 2024
1 parent e6eda54 commit 572f764
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion test/net/imap/test_imap_responses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 572f764

Please sign in to comment.