3 module Deprecation
#:nodoc:
4 def assert_deprecated(match
= nil, &block
)
5 result
, warnings
= collect_deprecations(&block
)
6 assert
!warnings
.empty
?, "Expected a deprecation warning within the block but received none"
8 match
= Regexp
.new(Regexp
.escape(match
)) unless match
.is_a
?(Regexp
)
9 assert warnings
.any
? { |w
| w
=~ match
}, "No deprecation warning matched #{match}: #{warnings.join(', ')}"
14 def assert_not_deprecated(&block
)
15 result
, deprecations
= collect_deprecations(&block
)
16 assert deprecations
.empty
?, "Expected no deprecation warning within the block but received #{deprecations.size}: \n #{deprecations * "\n "}"
21 def collect_deprecations
22 old_behavior
= ActiveSupport
::Deprecation.behavior
24 ActiveSupport
::Deprecation.behavior
= Proc
.new
do |message
, callstack
|
25 deprecations
<< message
28 [result
, deprecations
]
30 ActiveSupport
::Deprecation.behavior
= old_behavior
37 require 'test/unit/error'
42 # Silence warnings when reporting test errors.
43 def message_with_silenced_deprecation
44 ActiveSupport
::Deprecation.silence
do
45 message_without_silenced_deprecation
49 alias_method_chain
:message, :silenced_deprecation
54 # Using miniunit, ignore.