File tree Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -2501,6 +2501,7 @@ def idle_done
2501
2501
#
2502
2502
# Calling without a block is unsafe and deprecated. Future releases will
2503
2503
# raise ArgumentError unless a block is given.
2504
+ # See Config#responses_without_block.
2504
2505
#
2505
2506
# Previously unhandled responses are automatically cleared before entering a
2506
2507
# mailbox with #select or #examine. Long-lived connections can receive many
@@ -2525,7 +2526,12 @@ def responses(type = nil)
2525
2526
elsif type
2526
2527
raise ArgumentError , "Pass a block or use #clear_responses"
2527
2528
else
2528
- # warn("DEPRECATED: pass a block or use #clear_responses", uplevel: 1)
2529
+ case config . responses_without_block
2530
+ when :raise
2531
+ raise ArgumentError , "Pass a block or use #clear_responses"
2532
+ when :warn
2533
+ warn ( "DEPRECATED: pass a block or use #clear_responses" , uplevel : 1 )
2534
+ end
2529
2535
@responses
2530
2536
end
2531
2537
end
Original file line number Diff line number Diff line change @@ -85,6 +85,19 @@ def self.[](config) # :nodoc: unfinished API
85
85
# | _original_ | +5+ seconds |
86
86
attr_accessor :idle_response_timeout , type : Integer
87
87
88
+ # :markup: markdown
89
+ #
90
+ # Controls the behavior of Net::IMAP#responses when called without a
91
+ # block. Valid options are `:warn`, `:raise`, or
92
+ # `:silence_deprecation_warning`.
93
+ #
94
+ # | Starting with version | The default value is |
95
+ # |-----------------------|--------------------------------|
96
+ # | v0.4.13 | +:silence_deprecation_warning+ |
97
+ # | v0.5 | +:warn+ |
98
+ # | _eventually_ | +:raise+ |
99
+ attr_accessor :responses_without_block
100
+
88
101
# Creates a new config object and initialize its attribute with +attrs+.
89
102
#
90
103
# If +parent+ is not given, the global config is used by default.
@@ -100,6 +113,7 @@ def initialize(parent = Config.global, **attrs)
100
113
debug : false ,
101
114
open_timeout : 30 ,
102
115
idle_response_timeout : 5 ,
116
+ responses_without_block : :silence_deprecation_warning ,
103
117
) . freeze
104
118
105
119
@global = default . new
Original file line number Diff line number Diff line change @@ -1105,10 +1105,22 @@ def test_responses
1105
1105
assert_equal ( 1 , imap . responses ( "RECENT" , &:last ) )
1106
1106
assert_raise ( ArgumentError ) do imap . responses ( "UIDNEXT" ) end
1107
1107
# Deprecated style, without a block:
1108
- # assert_warn(/Pass a block.*or.*clear_responses/i) do
1109
- # assert_equal(%i[Answered Flagged Deleted Seen Draft],
1110
- # imap.responses["FLAGS"]&.last)
1111
- # end
1108
+ imap . config . responses_without_block = :raise
1109
+ assert_raise ( ArgumentError ) do imap . responses end
1110
+ imap . config . responses_without_block = :warn
1111
+ assert_raise ( ArgumentError ) do imap . responses ( "UIDNEXT" ) end
1112
+ assert_warn ( /Pass a block.*or.*clear_responses/i ) do
1113
+ assert_equal ( %i[ Answered Flagged Deleted Seen Draft ] ,
1114
+ imap . responses [ "FLAGS" ] &.last )
1115
+ end
1116
+ # TODO: assert_no_warn?
1117
+ imap . config . responses_without_block = :silence_deprecation_warning
1118
+ assert_raise ( ArgumentError ) do imap . responses ( "UIDNEXT" ) end
1119
+ stderr = EnvUtil . verbose_warning {
1120
+ assert_equal ( %i[ Answered Flagged Deleted Seen Draft ] ,
1121
+ imap . responses [ "FLAGS" ] &.last )
1122
+ }
1123
+ assert_empty stderr
1112
1124
end
1113
1125
end
1114
1126
You can’t perform that action at this time.
0 commit comments