aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/lib/active_support/deprecation.rb10
-rw-r--r--activesupport/test/deprecation_test.rb12
-rw-r--r--activesupport/test/reloadable_test.rb6
3 files changed, 21 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/deprecation.rb b/activesupport/lib/active_support/deprecation.rb
index e4e1d187a5..50aff7582d 100644
--- a/activesupport/lib/active_support/deprecation.rb
+++ b/activesupport/lib/active_support/deprecation.rb
@@ -86,17 +86,19 @@ module ActiveSupport
module Assertions
def assert_deprecated(match = nil, &block)
- warnings = collect_deprecations(&block)
+ result, warnings = collect_deprecations(&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(&block)
- deprecations = collect_deprecations(&block)
+ result, deprecations = collect_deprecations(&block)
assert deprecations.empty?, "Expected no deprecation warning within the block but received #{deprecations.size}: \n #{deprecations * "\n "}"
+ result
end
private
@@ -106,8 +108,8 @@ module ActiveSupport
ActiveSupport::Deprecation.behavior = Proc.new do |message, callstack|
deprecations << message
end
- yield
- deprecations
+ result = yield
+ [result, deprecations]
ensure
ActiveSupport::Deprecation.behavior = old_behavior
end
diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb
index a7d833f49d..bbcee24f5c 100644
--- a/activesupport/test/deprecation_test.rb
+++ b/activesupport/test/deprecation_test.rb
@@ -87,6 +87,18 @@ class DeprecationTest < Test::Unit::TestCase
flunk 'assert_deprecated should match any warning in block, not just the last one'
end
+ def test_assert_not_deprecated_returns_result_of_block
+ assert_equal 123, assert_not_deprecated { 123 }
+ end
+
+ def test_assert_deprecated_returns_result_of_block
+ result = assert_deprecated('abc') do
+ ActiveSupport::Deprecation.warn 'abc'
+ 123
+ end
+ assert_equal 123, result
+ end
+
def test_silence
ActiveSupport::Deprecation.silence do
assert_not_deprecated { @dtc.partially }
diff --git a/activesupport/test/reloadable_test.rb b/activesupport/test/reloadable_test.rb
index 18120b39a7..eca21295b4 100644
--- a/activesupport/test/reloadable_test.rb
+++ b/activesupport/test/reloadable_test.rb
@@ -96,18 +96,18 @@ class ReloadableTest < Test::Unit::TestCase
def test_include_subclasses_should_warn
c = Class.new
- deps = collect_deprecations do
+ result, deps = collect_deprecations do
c.send :include, Reloadable::Subclasses
end
assert_equal 1, deps.size
assert_match %r{Reloadable::Subclasses}, deps.first
-
+
assert_deprecated_reloadable { c.reloadable? }
end
def test_include_deprecated_should_not_warn
c = Class.new
- deps = collect_deprecations do
+ result, deps = collect_deprecations do
c.send :include, Reloadable::Deprecated
end
assert_equal 0, deps.size