Class CoreEx::Object::TestSingletonClass
In: lib/core_ex/object/singleton_class.rb
Parent: ::Test::Unit::TestCase

Methods

Public Instance methods

[Source]

# File lib/core_ex/object/singleton_class.rb, line 44
        def setup
          @string = 'foo'
        end

[Source]

# File lib/core_ex/object/singleton_class.rb, line 48
        def teardown
        end

[Source]

# File lib/core_ex/object/singleton_class.rb, line 61
        def test_define_and_undef_singleton_method
          assert_nothing_raised do
            @string.send(:define_singleton_method, :foo) { 42 }
          end
          assert_equal 42, @string.foo
          assert_raise(NoMethodError) { @string.dup.foo }
          assert_nothing_raised do
            @string.send(:undef_singleton_method, :foo)
          end
          assert_raise(NoMethodError) { @string.foo }
        end

[Source]

# File lib/core_ex/object/singleton_class.rb, line 51
        def test_singleton_class
          assert_nothing_raised do
            assert_kind_of Class, @string.singleton_class, 'not a class'
          end
          assert_equal @string.singleton_class.object_id,
                       @string.singleton_class.object_id, 'not the same object id'
          assert_equal ::String, @string.singleton_class.ancestors.first,
                       'bad super class'
        end

[Validate]