提交 069b0eaf 编写于 作者: J Jeremy Kemper

assert_deprecated matches any warning caught in block

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5114 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 643571ca
......@@ -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
......
......@@ -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 }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册