From 62ef3835238e733f9faaef121730d81caf254990 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 20 Jan 2015 01:58:52 +0000 Subject: [PATCH] test_module.rb: more tests * test/ruby/test_module.rb: more tests for multiple prepend. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_module.rb | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 8413c4782b..f2694d7b35 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1725,15 +1725,25 @@ class TestModule < Test::Unit::TestCase assert_equal('hello!', foo.new.hello, bug9236) end - def test_multiple_prepend + def test_prepend_each_classes m = labeled_module("M") - c1 = labeled_class("C1") { - prepend m - } - c2 = labeled_class("C2", c1) { - prepend m - } - assert_equal([m, c2, m, c1], c2.ancestors[0, 4]) + c1 = labeled_class("C1") {prepend m} + c2 = labeled_class("C2", c1) {prepend m} + assert_equal([m, c2, m, c1], c2.ancestors[0, 4], "should be able to prepend each classes") + end + + def test_prepend_no_duplication + m = labeled_module("M") + c = labeled_class("C") {prepend m; prepend m} + assert_equal([m, c], c.ancestors[0, 2], "should never duplicate") + end + + def test_prepend_in_superclass + m = labeled_module("M") + c1 = labeled_class("C1") + c2 = labeled_class("C2", c1) {prepend m} + c1.class_eval {prepend m} + assert_equal([m, c2, m, c1], c2.ancestors[0, 4], "should accesisble prepended module in superclass") end def test_class_variables