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

Changeset 5115

Show
Ignore:
Timestamp:
09/15/06 05:54:18 (2 years ago)
Author:
bitsweat
Message:

assert_deprecated returns result of block

Files:

Legend:

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

    r5114 r5115  
    8787    module Assertions 
    8888      def assert_deprecated(match = nil, &block) 
    89         warnings = collect_deprecations(&block) 
     89        result, warnings = collect_deprecations(&block) 
    9090        assert !warnings.empty?, "Expected a deprecation warning within the block but received none" 
    9191        if match 
     
    9393          assert warnings.any? { |w| w =~ match }, "No deprecation warning matched #{match}: #{warnings.join(', ')}" 
    9494        end 
     95        result 
    9596      end 
    9697 
    9798      def assert_not_deprecated(&block) 
    98         deprecations = collect_deprecations(&block) 
     99        result, deprecations = collect_deprecations(&block) 
    99100        assert deprecations.empty?, "Expected no deprecation warning within the block but received #{deprecations.size}: \n  #{deprecations * "\n  "}" 
     101        result 
    100102      end 
    101103 
     
    107109            deprecations << message 
    108110          end 
    109           yield 
    110           deprecations 
     111          result = yield 
     112          [result, deprecations] 
    111113        ensure 
    112114          ActiveSupport::Deprecation.behavior = old_behavior 
  • trunk/activesupport/test/deprecation_test.rb

    r5114 r5115  
    8888  end 
    8989 
     90  def test_assert_not_deprecated_returns_result_of_block 
     91    assert_equal 123, assert_not_deprecated { 123 } 
     92  end 
     93 
     94  def test_assert_deprecated_returns_result_of_block 
     95    result = assert_deprecated('abc') do 
     96      ActiveSupport::Deprecation.warn 'abc' 
     97      123 
     98    end 
     99    assert_equal 123, result 
     100  end 
     101 
    90102  def test_silence 
    91103    ActiveSupport::Deprecation.silence do 
  • trunk/activesupport/test/reloadable_test.rb

    r4979 r5115  
    9797  def test_include_subclasses_should_warn 
    9898    c = Class.new 
    99     deps = collect_deprecations do 
     99    result, deps = collect_deprecations do 
    100100      c.send :include, Reloadable::Subclasses 
    101101    end 
    102102    assert_equal 1, deps.size 
    103103    assert_match %r{Reloadable::Subclasses}, deps.first 
    104      
     104 
    105105    assert_deprecated_reloadable { c.reloadable? } 
    106106  end 
     
    108108  def test_include_deprecated_should_not_warn 
    109109    c = Class.new 
    110     deps = collect_deprecations do 
     110    result, deps = collect_deprecations do 
    111111      c.send :include, Reloadable::Deprecated 
    112112    end