diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2006-08-08 21:21:04 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2006-08-08 21:21:04 +0000 |
commit | 74165eb6acaca98d4da13409c4e5b5ecc9d260f7 (patch) | |
tree | 024158d20563f34cca52a00b42aaa6c922777559 /activesupport/lib/active_support/deprecation.rb | |
parent | 94a1309194fa5962e33d395ede14e94b237c54f5 (diff) | |
download | rails-74165eb6acaca98d4da13409c4e5b5ecc9d260f7.tar.gz rails-74165eb6acaca98d4da13409c4e5b5ecc9d260f7.tar.bz2 rails-74165eb6acaca98d4da13409c4e5b5ecc9d260f7.zip |
New dependencies implementation
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4728 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/deprecation.rb')
-rw-r--r-- | activesupport/lib/active_support/deprecation.rb | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/deprecation.rb b/activesupport/lib/active_support/deprecation.rb index 5aff753616..d6c9317f06 100644 --- a/activesupport/lib/active_support/deprecation.rb +++ b/activesupport/lib/active_support/deprecation.rb @@ -49,24 +49,30 @@ module ActiveSupport module Assertions def assert_deprecated(match = nil, &block) - last = with_last_message_tracking_deprecation_behavior(&block) + last = collect_deprecations(&block).last assert last, "Expected a deprecation warning within the block but received none" - match = Regexp.new(Regexp.escape(match)) unless match.is_a?(Regexp) - assert_match match, last, "Deprecation warning didn't match #{match}: #{last}" + if match + match = Regexp.new(Regexp.escape(match)) unless match.is_a?(Regexp) + assert_match match, last, "Deprecation warning didn't match #{match}: #{last}" + end end def assert_not_deprecated(&block) - last = with_last_message_tracking_deprecation_behavior(&block) - assert_nil last, "Expected no deprecation warning within the block but received one: #{last}" + deprecations = collect_deprecations(&block) + assert deprecations.empty?, "Expected no deprecation warning within the block but received #{deprecations.size}: \n #{deprecations * "\n "}" end private - def with_last_message_tracking_deprecation_behavior + + def collect_deprecations old_behavior = ActiveSupport::Deprecation.behavior - last_message = nil - ActiveSupport::Deprecation.behavior = Proc.new { |message| last_message = message; old_behavior.call(message) if old_behavior } + deprecations = [] + ActiveSupport::Deprecation.behavior = Proc.new do |message| + deprecations << message + old_behavior.call(message) if old_behavior + end yield - last_message + return deprecations ensure ActiveSupport::Deprecation.behavior = old_behavior end |