Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 5114

Show
Ignore:
Timestamp:
09/15/06 03:56:25 (2 years ago)
Author:
bitsweat
Message:

assert_deprecated matches any warning caught in block

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/deprecation.rb

    r5113 r5114  
    8787    module Assertions 
    8888      def assert_deprecated(match = nil, &block) 
    89         last = collect_deprecations(&block).last 
    90         assert last, "Expected a deprecation warning within the block but received none" 
     89        warnings = collect_deprecations(&block) 
     90        assert !warnings.empty?, "Expected a deprecation warning within the block but received none" 
    9191        if match 
    9292          match = Regexp.new(Regexp.escape(match)) unless match.is_a?(Regexp) 
    93           assert_match match, last, "Deprecation warning didn't match #{match}: #{last}" 
     93          assert warnings.any? { |w| w =~ match }, "No deprecation warning matched #{match}: #{warnings.join(', ')}" 
    9494        end 
    9595      end 
  • trunk/activesupport/test/deprecation_test.rb

    r4978 r5114  
    7979  end 
    8080 
     81  def test_assert_deprecated_matches_any_warning 
     82    assert_deprecated 'abc' do 
     83      ActiveSupport::Deprecation.warn 'abc' 
     84      ActiveSupport::Deprecation.warn 'def' 
     85    end 
     86  rescue Test::Unit::AssertionFailedError 
     87    flunk 'assert_deprecated should match any warning in block, not just the last one' 
     88  end 
     89 
    8190  def test_silence 
    8291    ActiveSupport::Deprecation.silence do