1 # frozen_string_literal: false
5 class TestSingleton < Test::Unit::TestCase
11 o1 = SingletonTest.instance
17 def test_instance_never_changes
18 a = SingletonTest.instance
19 b = SingletonTest.instance
23 def test_initialize_raises_exception
24 assert_raise NoMethodError do
29 def test_allocate_raises_exception
30 assert_raise NoMethodError do
31 SingletonTest.allocate
35 def test_clone_raises_exception
36 exception = assert_raise TypeError do
37 SingletonTest.instance.clone
40 expected = "can't clone instance of singleton TestSingleton::SingletonTest"
42 assert_equal expected, exception.message
45 def test_dup_raises_exception
46 exception = assert_raise TypeError do
47 SingletonTest.instance.dup
50 expected = "can't dup instance of singleton TestSingleton::SingletonTest"
52 assert_equal expected, exception.message
55 def test_include_in_module_raises_exception
58 exception = assert_raise TypeError do
64 expected = "Inclusion of the OO-Singleton module in module #{mod}"
66 assert_equal expected, exception.message
69 def test_extending_singleton_raises_exception
70 assert_raise NoMethodError do
71 'foo'.extend Singleton
75 def test_inheritance_works_with_overridden_inherited_method
76 super_super_called = false
79 define_singleton_method :inherited do |sub|
80 super_super_called = true
84 inner = Class.new(outer) do
88 tester = Class.new(inner)
90 assert super_super_called
97 def test_class_level_cloning_preserves_singleton_behavior
98 klass = SingletonTest.clone