aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/deprecation_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-08-01 11:12:38 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-08-01 11:12:38 +0000
commit7d017781393b72a5257dbbfc99b124a7a0c492f1 (patch)
treefe08d7d97f58e320476450e0f8e450bc4a1693a9 /activesupport/test/deprecation_test.rb
parent4f017bb1b02089846fc26c873599a1026b674be5 (diff)
downloadrails-7d017781393b72a5257dbbfc99b124a7a0c492f1.tar.gz
rails-7d017781393b72a5257dbbfc99b124a7a0c492f1.tar.bz2
rails-7d017781393b72a5257dbbfc99b124a7a0c492f1.zip
Deprecation: easier to work with warning behavior as procs; default behaviors for each environment so users needn't update env.rb; and testing pleasure with assert_deprecated, assert_not_deprecated. Test prints to , dev logs, production ignores.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4647 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/deprecation_test.rb')
-rw-r--r--activesupport/test/deprecation_test.rb115
1 files changed, 45 insertions, 70 deletions
diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb
index c691b5bde0..5fb0c5b042 100644
--- a/activesupport/test/deprecation_test.rb
+++ b/activesupport/test/deprecation_test.rb
@@ -1,85 +1,60 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../lib/active_support/deprecation'
+require File.dirname(__FILE__) + '/abstract_unit'
-# 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
+class Deprecatee
+ def partially(foo = nil)
+ ActiveSupport::Deprecation.warn 'calling with foo=nil is out' if foo.nil?
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
-
+ def not() 2 end
+ def none() 1 end
+ def one(a) a end
+ def multi(a,b,c) [a,b,c] end
+ deprecate :none, :one, :multi
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
+ # Track the last warning.
+ @old_behavior = ActiveSupport::Deprecation.behavior
+ @last_message = nil
+ ActiveSupport::Deprecation.behavior = Proc.new { |message| @last_message = message }
+
+ @dtc = Deprecatee.new
end
-
- def test_deprecating_class_method
- assert_equal 1, @dtc.deprecated_no_args
- assert_deprecation_warning
- assert_warning_matches /DeprecationTestingClass#deprecated_no_args/
+
+ def teardown
+ ActiveSupport::Deprecation.behavior = @old_behavior
end
-
- def test_deprecating_class_method_with_argument
- assert_equal 1, @dtc.deprecated_one_arg(1)
+
+ def test_inline_deprecation_warning
+ assert_deprecated(/foo=nil/) do
+ @dtc.partially
+ end
end
-
- def test_deprecating_class_method_with_argument
- assert_equal [1,2,3], @dtc.deprecated_multiple_args(1,2,3)
+
+ def test_undeprecated
+ assert_not_deprecated do
+ assert_equal 2, @dtc.not
+ end
end
-
- private
- def assert_warning_matches(rx)
- assert ActiveSupport::Deprecation.last_warning =~ rx, "The deprecation warning did not match #{rx}"
+
+ def test_deprecate_class_method
+ assert_deprecated(/none is deprecated/) do
+ assert_equal 1, @dtc.none
+ end
+
+ assert_deprecated(/one is deprecated/) do
+ assert_equal 1, @dtc.one(1)
+ end
+
+ assert_deprecated(/multi is deprecated/) do
+ assert_equal [1,2,3], @dtc.multi(1,2,3)
+ end
end
-
- def assert_deprecation_warning
- assert_not_nil ActiveSupport::Deprecation.last_warning, "No Deprecation warnings were issued"
+
+ def test_nil_behavior_is_ignored
+ ActiveSupport::Deprecation.behavior = nil
+ assert_deprecated(/foo=nil/) { @dtc.partially }
end
end