diff options
author | Daniel Pepper <pepper.daniel@gmail.com> | 2023-06-04 21:29:32 -0700 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-06-05 04:29:37 +0000 |
commit | 542c70aab748cf17960cc2a0959ba490983ceae6 (patch) | |
tree | da953635871d99535bfc62fc130b6905b5e7154d /test/test_singleton.rb | |
parent | 3fe0f8c68bf2cd861b7061de8a662885e5aa5234 (diff) | |
download | ruby-542c70aab748cf17960cc2a0959ba490983ceae6.tar.gz |
[ruby/singleton] Simplify implementation of `Singleton#instance`.
(https://github.com/ruby/singleton/pull/9)
- Add more tests to cover rails' usage.
Diffstat (limited to 'test/test_singleton.rb')
-rw-r--r-- | test/test_singleton.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/test_singleton.rb b/test/test_singleton.rb index b3c48bb5f5..e474a0ccc5 100644 --- a/test/test_singleton.rb +++ b/test/test_singleton.rb @@ -94,6 +94,23 @@ class TestSingleton < Test::Unit::TestCase assert_same a, b end + def test_inheritance_creates_separate_singleton + a = SingletonTest.instance + b = Class.new(SingletonTest).instance + + assert_not_same a, b + end + + def test_inheritance_instantiation + klass = Class.new do + include Singleton + + public_class_method :new + end + + assert Class.new(klass).new + end + def test_class_level_cloning_preserves_singleton_behavior klass = SingletonTest.clone @@ -101,4 +118,8 @@ class TestSingleton < Test::Unit::TestCase b = klass.instance assert_same a, b end + + def test_class_level_cloning_creates_separate_singleton + assert_not_same SingletonTest.instance, SingletonTest.clone.instance + end end |