instance method collect_deprecations

Ruby on Rails 7.0.10

Since v7.0.10

Available in: v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

collect_deprecations(deprecator = nil)

Returns 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"]

If no deprecator is given, defaults to ActiveSupport::Deprecation.

collect_deprecations do
  CustomDeprecator.warn "custom message"
  ActiveSupport::Deprecation.warn "message"
end # => ["message"]

Parameters

deprecator opt = nil
Source
# File activesupport/lib/active_support/testing/deprecation.rb, line 75
      def collect_deprecations(deprecator = nil)
        deprecator ||= ActiveSupport::Deprecation
        old_behavior = deprecator.behavior
        deprecations = []
        deprecator.behavior = Proc.new do |message, callstack|
          deprecations << message
        end
        result = yield
        [result, deprecations]
      ensure
        deprecator.behavior = old_behavior
      end

Defined in activesupport/lib/active_support/testing/deprecation.rb line 75 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::Testing::Deprecation

Type at least 2 characters to search.

↑↓ navigate · open · esc close