Skip to content

Commit 7e74549

Browse files
authored
Merge pull request rails#47397 from etiennebarrie/fix-collect_deprecations-doc
Fix `collect_deprecations` documentation and add a test
2 parents 69aaaf7 + 8db8409 commit 7e74549

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

activesupport/lib/active_support/testing/deprecation.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,21 @@ def assert_not_deprecated(deprecator = nil, &block)
6767
result
6868
end
6969

70-
# Returns an array of all the deprecation warnings emitted by the given
70+
# Returns the return value of the block and an array of all the deprecation warnings emitted by the given
7171
# +deprecator+ during the execution of the yielded block.
7272
#
7373
# collect_deprecations(CustomDeprecator) do
7474
# CustomDeprecator.warn "message"
75-
# end # => ["message"]
75+
# :result
76+
# end # => [:result, ["message"]]
7677
#
7778
# If no +deprecator+ is given, defaults to ActiveSupport::Deprecation.
7879
#
7980
# collect_deprecations do
8081
# CustomDeprecator.warn "custom message"
8182
# ActiveSupport::Deprecation.warn "message"
82-
# end # => ["message"]
83+
# :result
84+
# end # => [:result, ["message"]]
8385
def collect_deprecations(deprecator = nil)
8486
deprecator ||= ActiveSupport::Deprecation
8587
old_behavior = deprecator.behavior

activesupport/test/deprecation_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ def setup
4545
end
4646
end
4747

48+
test "collect_deprecations returns the return value of the block and the deprecations collected" do
49+
result = collect_deprecations(@deprecator) do
50+
@deprecator.warn
51+
:result
52+
end
53+
assert_equal 2, result.size
54+
assert_equal :result, result.first
55+
assert_match "DEPRECATION WARNING:", result.last.sole
56+
end
57+
4858
test "Module::deprecate" do
4959
klass = Class.new(Deprecatee)
5060
klass.deprecate :zero, :one, :multi, deprecator: @deprecator

0 commit comments

Comments
 (0)