diff options
Diffstat (limited to 'activesupport/test/core_ext/object_and_class_ext_test.rb')
-rw-r--r-- | activesupport/test/core_ext/object_and_class_ext_test.rb | 34 |
1 files changed, 16 insertions, 18 deletions
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 a1e5ea79db..73121ca966 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -1,6 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/object' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/class' +require File.dirname(__FILE__) + '/../abstract_unit' class ClassA; end class ClassB < ClassA; end @@ -41,24 +39,24 @@ class ClassExtTest < Test::Unit::TestCase assert !defined?(ClassC) assert !defined?(ClassD) end - + def test_subclasses_of assert_equal [ClassJ], Object.subclasses_of(ClassI) ClassI.remove_subclasses assert_equal [], Object.subclasses_of(ClassI) end - + def test_subclasses_of_should_find_nested_classes assert Object.subclasses_of(ClassK).include?(Nested::ClassL) end - + def test_subclasses_of_should_not_return_removed_classes # First create the removed class old_class = Nested.send :remove_const, :ClassL new_class = Class.new(ClassK) Nested.const_set :ClassL, new_class assert_equal "Nested::ClassL", new_class.name # Sanity check - + subclasses = Object.subclasses_of(ClassK) assert subclasses.include?(new_class) assert ! subclasses.include?(old_class) @@ -75,23 +73,23 @@ class ObjectTests < Test::Unit::TestCase suppress(LoadError, ArgumentError) { raise LoadError } suppress(LoadError, ArgumentError) { raise ArgumentError } end - + def test_extended_by foo = Foo.new assert foo.extended_by.include?(Bar) foo.extend(Baz) assert ([Bar, Baz] - foo.extended_by).empty?, "Expected Bar, Baz in #{foo.extended_by.inspect}" end - + def test_extend_with_included_modules_from foo, object = Foo.new, Object.new assert !object.respond_to?(:bar) assert !object.respond_to?(:baz) - + object.extend_with_included_modules_from(foo) assert object.respond_to?(:bar) assert !object.respond_to?(:baz) - + foo.extend(Baz) object.extend_with_included_modules_from(foo) assert object.respond_to?(:bar) @@ -113,17 +111,17 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase assert_equal %w(@bar @baz), @dest.instance_variables.sort %w(@bar @baz).each do |name| - assert_equal @source.instance_variable_get(name).object_id, + assert_equal @source.instance_variable_get(name).object_id, @dest.instance_variable_get(name).object_id end end - + def test_copy_instance_variables_from_with_explicit_excludes @dest.copy_instance_variables_from(@source, ['@baz']) assert !@dest.instance_variables.include?('@baz') assert_equal 'bar', @dest.instance_variable_get('@bar') end - + def test_copy_instance_variables_automatically_excludes_protected_instance_variables @source.instance_variable_set(:@quux, 'quux') class << @source @@ -131,23 +129,23 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase ['@bar', :@quux] end end - + @dest.copy_instance_variables_from(@source) assert !@dest.instance_variables.include?('@bar') assert !@dest.instance_variables.include?('@quux') assert_equal 'baz', @dest.instance_variable_get('@baz') end - + def test_instance_values object = Object.new object.instance_variable_set :@a, 1 object.instance_variable_set :@b, 2 assert_equal({'a' => 1, 'b' => 2}, object.instance_values) end - + def test_instance_exec_passes_arguments_to_block block = Proc.new { |value| [self, value] } assert_equal %w(hello goodbye), 'hello'.instance_exec('goodbye', &block) end - + end |