Sha256: 6fb810d72e944bcff173838a9c92f8e60b7dd455b371530342676b44b1ea74a9

Contents?: true

Size: 1.29 KB

Versions: 52

Compression:

Stored size: 1.29 KB

Contents

require 'active_support/deprecation'

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| w =~ match }, "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

52 entries across 50 versions & 8 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.0.7.1/lib/active_support/testing/deprecation.rb
activesupport-5.0.7.2 lib/active_support/testing/deprecation.rb
activesupport-5.0.7.1 lib/active_support/testing/deprecation.rb
activesupport-5.0.7 lib/active_support/testing/deprecation.rb
activesupport-5.0.6 lib/active_support/testing/deprecation.rb
activesupport-5.0.6.rc1 lib/active_support/testing/deprecation.rb
activesupport-5.0.5 lib/active_support/testing/deprecation.rb
activesupport-5.0.5.rc2 lib/active_support/testing/deprecation.rb
activesupport-5.0.5.rc1 lib/active_support/testing/deprecation.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/deprecation.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/deprecation.rb
activesupport-5.0.4 lib/active_support/testing/deprecation.rb
activesupport-5.0.4.rc1 lib/active_support/testing/deprecation.rb
activesupport-5.0.3 lib/active_support/testing/deprecation.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activesupport-5.0.2/lib/active_support/testing/deprecation.rb
lazy_record-0.2.1 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/deprecation.rb
lazy_record-0.2.0 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/deprecation.rb
lazy_record-0.1.9 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/deprecation.rb
lazy_record-0.1.8 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/deprecation.rb
lazy_record-0.1.7 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/deprecation.rb