diff options
author | Brandon Dunne <bdunne@redhat.com> | 2015-10-13 14:10:14 -0400 |
---|---|---|
committer | Brandon Dunne <bdunne@redhat.com> | 2015-10-14 07:49:39 -0400 |
commit | 6c98fbd9c3cc28ccbfc1b46a9ce3d58fdb19f3c8 (patch) | |
tree | c1cc494cb2b4a3c7fb62f275b84f8a6b0f96f468 /activesupport/lib/active_support/testing | |
parent | 31af8c90b60dc475fd80d2919bfb874b4acc4507 (diff) | |
download | rails-6c98fbd9c3cc28ccbfc1b46a9ce3d58fdb19f3c8.tar.gz rails-6c98fbd9c3cc28ccbfc1b46a9ce3d58fdb19f3c8.tar.bz2 rails-6c98fbd9c3cc28ccbfc1b46a9ce3d58fdb19f3c8.zip |
Fix bug where custom deprecators are not used.
Add tests for ActiveSupport::Deprecation.deprecate_methods
Modify ActiveSupport::Testing::Deprecation to allow a custom deprecator
Leverage ActiveSupport::Testing::Deprecation assert_deprecated
Update documentation for ActiveSupport::Deprecation.deprecate_methods
Use cases:
Using the default deprecator => "removed from Rails X.Y"
Passing a custom deprecator in the options hash => "removed from MyGem next-release"
Deprecating methods directly from custom deprecator => "removed from MyGem next-release"
Diffstat (limited to 'activesupport/lib/active_support/testing')
-rw-r--r-- | activesupport/lib/active_support/testing/deprecation.rb | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/testing/deprecation.rb b/activesupport/lib/active_support/testing/deprecation.rb index 6c94c611b6..5dfa14eeba 100644 --- a/activesupport/lib/active_support/testing/deprecation.rb +++ b/activesupport/lib/active_support/testing/deprecation.rb @@ -3,8 +3,8 @@ require 'active_support/deprecation' module ActiveSupport module Testing module Deprecation #:nodoc: - def assert_deprecated(match = nil, &block) - result, warnings = collect_deprecations(&block) + 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) @@ -13,22 +13,23 @@ module ActiveSupport result end - def assert_not_deprecated(&block) - result, deprecations = collect_deprecations(&block) + 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 - old_behavior = ActiveSupport::Deprecation.behavior + def collect_deprecations(deprecator = nil) + deprecator ||= ActiveSupport::Deprecation + old_behavior = deprecator.behavior deprecations = [] - ActiveSupport::Deprecation.behavior = Proc.new do |message, callstack| + deprecator.behavior = Proc.new do |message, callstack| deprecations << message end result = yield [result, deprecations] ensure - ActiveSupport::Deprecation.behavior = old_behavior + deprecator.behavior = old_behavior end end end |