Sha256: 6382557b2393f1291df78afdeb22f964292746ff265a3a030c8f1df1ba06c256

Contents?: true

Size: 1.33 KB

Versions: 23

Compression:

Stored size: 1.33 KB

Contents

require "active_support/deprecation"
require "active_support/core_ext/regexp"

module ActiveSupport
  module Testing
    module Deprecation #:nodoc:
      def assert_deprecated(match = nil, deprecator = nil, &block)
        result, warnings = collect_deprecations(deprecator, &block)
        assert !warnings.empty?, "Expected a deprecation warning within the block but received none"
        if match
          match = Regexp.new(Regexp.escape(match)) unless match.is_a?(Regexp)
          assert warnings.any? { |w| match.match?(w) }, "No deprecation warning matched #{match}: #{warnings.join(', ')}"
        end
        result
      end

      def assert_not_deprecated(deprecator = nil, &block)
        result, deprecations = collect_deprecations(deprecator, &block)
        assert deprecations.empty?, "Expected no deprecation warning within the block but received #{deprecations.size}: \n  #{deprecations * "\n  "}"
        result
      end

      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
    end
  end
end

Version data entries

23 entries across 23 versions & 3 rubygems

Version Path
activesupport-5.1.7 lib/active_support/testing/deprecation.rb
activesupport-5.1.7.rc1 lib/active_support/testing/deprecation.rb
activesupport-5.1.6.2 lib/active_support/testing/deprecation.rb
activesupport-5.1.6.1 lib/active_support/testing/deprecation.rb
activesupport-5.1.6 lib/active_support/testing/deprecation.rb
tdiary-5.0.8 vendor/bundle/gems/activesupport-5.1.5/lib/active_support/testing/deprecation.rb
activesupport-5.1.5 lib/active_support/testing/deprecation.rb
activesupport-5.1.5.rc1 lib/active_support/testing/deprecation.rb
pract6-0.1.0 .gem/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/testing/deprecation.rb
activesupport-5.1.4 lib/active_support/testing/deprecation.rb
activesupport-5.1.4.rc1 lib/active_support/testing/deprecation.rb
activesupport-5.1.3 lib/active_support/testing/deprecation.rb
activesupport-5.1.3.rc3 lib/active_support/testing/deprecation.rb
activesupport-5.1.3.rc2 lib/active_support/testing/deprecation.rb
activesupport-5.1.3.rc1 lib/active_support/testing/deprecation.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.1.2/lib/active_support/testing/deprecation.rb
activesupport-5.1.2 lib/active_support/testing/deprecation.rb
activesupport-5.1.2.rc1 lib/active_support/testing/deprecation.rb
activesupport-5.1.1 lib/active_support/testing/deprecation.rb
activesupport-5.1.0 lib/active_support/testing/deprecation.rb