From f7b0a857e97304a5daeb47313759b9bf0d7e2fc9 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 25 Feb 2010 09:32:29 -0800 Subject: Use Object#singleton_class instead of #metaclass. Prefer Ruby's choice. --- activesupport/test/core_ext/object_and_class_ext_test.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'activesupport/test/core_ext') diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index f31e7774e9..00c59d84b8 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -89,7 +89,7 @@ class ClassExtTest < Test::Unit::TestCase end end -class ObjectTests < Test::Unit::TestCase +class ObjectTests < ActiveSupport::TestCase class DuckTime def acts_like_time? true @@ -119,12 +119,16 @@ class ObjectTests < Test::Unit::TestCase assert !duck.acts_like?(:date) end - def test_metaclass - string = "Hello" - string.metaclass.instance_eval do - define_method(:foo) { "bar" } + def test_singleton_class + o = Object.new + assert_equal class << o; self end, o.singleton_class + end + + def test_metaclass_deprecated + o = Object.new + assert_deprecated /use singleton_class instead/ do + assert_equal o.singleton_class, o.metaclass end - assert_equal "bar", string.foo end end -- cgit v1.2.3