diff options
author | Michael Koziarski <michael@koziarski.com> | 2006-07-27 00:10:06 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2006-07-27 00:10:06 +0000 |
commit | 7692191f5ab207ff76cc2558f2a02e299cd51392 (patch) | |
tree | 10c7e0a5ee77351e5c114cb6e6c8dae9d3a5cf1a /activesupport/test | |
parent | 45e319d0f81b8e97bee69ced1db5636075b38f1d (diff) | |
download | rails-7692191f5ab207ff76cc2558f2a02e299cd51392.tar.gz rails-7692191f5ab207ff76cc2558f2a02e299cd51392.tar.bz2 rails-7692191f5ab207ff76cc2558f2a02e299cd51392.zip |
Initial Version of Deprecation for Rails[Koz]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4623 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/deprecation_test.rb | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb new file mode 100644 index 0000000000..c691b5bde0 --- /dev/null +++ b/activesupport/test/deprecation_test.rb @@ -0,0 +1,85 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../lib/active_support/deprecation' + +# Stub out the warnings to allow assertions +module ActiveSupport + module Deprecation + class << self + def issue_warning(message) + @@warning = message + end + def last_warning + @@warning + end + end + end +end + +class DeprecationTestingClass + + def partiallly_deprecated(foo = nil) + if foo.nil? + ActiveSupport::Deprecation.issue_warning("calling partially_deprecated with foo=nil is now deprecated") + end + end + + def not_deprecated + 2 + end + + def deprecated_no_args + 1 + end + deprecate :deprecated_no_args + + def deprecated_one_arg(a) + a + end + deprecate :deprecated_one_arg + + def deprecated_multiple_args(a,b,c) + [a,b,c] + end + deprecate :deprecated_multiple_args + +end + + +class DeprecationTest < Test::Unit::TestCase + def setup + @dtc = DeprecationTestingClass.new + ActiveSupport::Deprecation.issue_warning(nil) # reset + end + + def test_partial_deprecation + @dtc.partiallly_deprecated + assert_warning_matches /foo=nil/ + end + + def test_raises_nothing + assert_equal 2, @dtc.not_deprecated + end + + def test_deprecating_class_method + assert_equal 1, @dtc.deprecated_no_args + assert_deprecation_warning + assert_warning_matches /DeprecationTestingClass#deprecated_no_args/ + end + + def test_deprecating_class_method_with_argument + assert_equal 1, @dtc.deprecated_one_arg(1) + end + + def test_deprecating_class_method_with_argument + assert_equal [1,2,3], @dtc.deprecated_multiple_args(1,2,3) + end + + private + def assert_warning_matches(rx) + assert ActiveSupport::Deprecation.last_warning =~ rx, "The deprecation warning did not match #{rx}" + end + + def assert_deprecation_warning + assert_not_nil ActiveSupport::Deprecation.last_warning, "No Deprecation warnings were issued" + end +end |