diff --git a/activesupport/lib/active_support/deprecation.rb b/activesupport/lib/active_support/deprecation.rb index 22a50f7e8b5df740f73d33f6e587abd62a248905..e4e1d187a5c8f690d2fef553ee9127bebb6a42a5 100644 --- a/activesupport/lib/active_support/deprecation.rb +++ b/activesupport/lib/active_support/deprecation.rb @@ -86,11 +86,11 @@ def #{target}_with_deprecation#{punctuation}(*args, &block) module Assertions def assert_deprecated(match = nil, &block) - last = collect_deprecations(&block).last - assert last, "Expected a deprecation warning within the block but received none" + 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_match match, last, "Deprecation warning didn't match #{match}: #{last}" + assert warnings.any? { |w| w =~ match }, "No deprecation warning matched #{match}: #{warnings.join(', ')}" end end diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index 12fe5f3bf20d2b4d991b6e84b1e71c0226ff0506..a7d833f49d23e4ad68a410d0a66d1d50dbde5937 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -78,6 +78,15 @@ def test_assert_deprecation_without_match end end + def test_assert_deprecated_matches_any_warning + assert_deprecated 'abc' do + ActiveSupport::Deprecation.warn 'abc' + ActiveSupport::Deprecation.warn 'def' + end + rescue Test::Unit::AssertionFailedError + flunk 'assert_deprecated should match any warning in block, not just the last one' + end + def test_silence ActiveSupport::Deprecation.silence do assert_not_deprecated { @dtc.partially }