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 @@ -114,6 +114,19 @@ def self.[](config) # :nodoc: unfinished API
114
114
# | v0.4 | +true+ <em>(support added)</em> |
115
115
attr_accessor :sasl_ir , type : :boolean
116
116
117
+ # :markup: markdown
118
+ #
119
+ # Controls the behavior of Net::IMAP#responses when called without a
120
+ # block. Valid options are `:warn`, `:raise`, or
121
+ # `:silence_deprecation_warning`.
122
+ #
123
+ # | Starting with version | The default value is |
124
+ # |-----------------------|--------------------------------|
125
+ # | v0.4.13 | +:silence_deprecation_warning+ |
126
+ # | v0.5 | +:warn+ |
127
+ # | _eventually_ | +:raise+ |
128
+ attr_accessor :responses_without_block
129
+
117
130
# Creates a new config object and initialize its attribute with +attrs+.
118
131
#
119
132
# If +parent+ is not given, the global config is used by default.
@@ -130,6 +143,7 @@ def initialize(parent = Config.global, **attrs)
130
143
open_timeout : 30 ,
131
144
idle_response_timeout : 5 ,
132
145
sasl_ir : true ,
146
+ responses_without_block : :silence_deprecation_warning ,
133
147
) . freeze
134
148
135
149
@global = default . new
Original file line number Diff line number Diff line change @@ -1122,10 +1122,22 @@ def test_responses
1122
1122
assert_equal ( 1 , imap . responses ( "RECENT" , &:last ) )
1123
1123
assert_raise ( ArgumentError ) do imap . responses ( "UIDNEXT" ) end
1124
1124
# Deprecated style, without a block:
1125
- # assert_warn(/Pass a block.*or.*clear_responses/i) do
1126
- # assert_equal(%i[Answered Flagged Deleted Seen Draft],
1127
- # imap.responses["FLAGS"]&.last)
1128
- # end
1125
+ imap . config . responses_without_block = :raise
1126
+ assert_raise ( ArgumentError ) do imap . responses end
1127
+ imap . config . responses_without_block = :warn
1128
+ assert_raise ( ArgumentError ) do imap . responses ( "UIDNEXT" ) end
1129
+ assert_warn ( /Pass a block.*or.*clear_responses/i ) do
1130
+ assert_equal ( %i[ Answered Flagged Deleted Seen Draft ] ,
1131
+ imap . responses [ "FLAGS" ] &.last )
1132
+ end
1133
+ # TODO: assert_no_warn?
1134
+ imap . config . responses_without_block = :silence_deprecation_warning
1135
+ assert_raise ( ArgumentError ) do imap . responses ( "UIDNEXT" ) end
1136
+ stderr = EnvUtil . verbose_warning {
1137
+ assert_equal ( %i[ Answered Flagged Deleted Seen Draft ] ,
1138
+ imap . responses [ "FLAGS" ] &.last )
1139
+ }
1140
+ assert_empty stderr
1129
1141
end
1130
1142
end
1131
1143
You can’t perform that action at this time.
0 commit comments