Skip to content

Commit

Permalink
Fix collect_deprecations documentation and add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebarrie committed Feb 15, 2023
1 parent 3ddb970 commit 8db8409
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions activesupport/lib/active_support/testing/deprecation.rb
Expand Up @@ -67,19 +67,21 @@ def assert_not_deprecated(deprecator = nil, &block)
result
end

# Returns an array of all the deprecation warnings emitted by the given
# Returns the return value of the block and an array of all the deprecation warnings emitted by the given
# +deprecator+ during the execution of the yielded block.
#
# collect_deprecations(CustomDeprecator) do
# CustomDeprecator.warn "message"
# end # => ["message"]
# :result
# end # => [:result, ["message"]]
#
# If no +deprecator+ is given, defaults to ActiveSupport::Deprecation.
#
# collect_deprecations do
# CustomDeprecator.warn "custom message"
# ActiveSupport::Deprecation.warn "message"
# end # => ["message"]
# :result
# end # => [:result, ["message"]]
def collect_deprecations(deprecator = nil)
deprecator ||= ActiveSupport::Deprecation
old_behavior = deprecator.behavior
Expand Down
10 changes: 10 additions & 0 deletions activesupport/test/deprecation_test.rb
Expand Up @@ -45,6 +45,16 @@ def setup
end
end

test "collect_deprecations returns the return value of the block and the deprecations collected" do
result = collect_deprecations(@deprecator) do
@deprecator.warn
:result
end
assert_equal 2, result.size
assert_equal :result, result.first
assert_match "DEPRECATION WARNING:", result.last.sole
end

test "Module::deprecate" do
klass = Class.new(Deprecatee)
klass.deprecate :zero, :one, :multi, deprecator: @deprecator
Expand Down

0 comments on commit 8db8409

Please sign in to comment.