summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-17 16:12:28 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-17 16:12:28 +0000
commitc4b21f736ebb339fc46760f800851a7eed444c47 (patch)
tree9b91a296b71a5a44a0e9bbb57dda46af94845140 /test/ruby
parent5d3b8d0d5491096a10ae332db759b01c89a10f9d (diff)
merge revision(s) r49222,r49480,r49493: [Backport #10765]
method.h: UNDEFINED_REFINED_METHOD_P * method.h (UNDEFINED_REFINED_METHOD_P): macro to tell if refined original method is defined. * vm_method.c (remove_method): When remove refined method, raise a NameError if the method is not defined in refined class. But if the method is defined in refined class, it should keep refined method and remove original method. Patch by Seiei Higa. [ruby-core:67722] [Bug #10765] * class.c (method_entry_i, class_instance_method_list, rb_obj_singleton_methods): should not include methods of superclasses if recur is false. [ruby-dev:48854] [Bug #10826] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@49992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_refinement.rb77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index f34a7deb54..dc2d31c867 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -1281,6 +1281,83 @@ class TestRefinement < Test::Unit::TestCase
end;
end
+ def test_remove_refined_method
+ assert_separately([], <<-"end;")
+ bug10765 = '[ruby-core:67722] [Bug #10765]'
+
+ class C
+ def foo
+ "C#foo"
+ end
+ end
+
+ module RefinementBug
+ refine C do
+ def foo
+ "RefinementBug#foo"
+ end
+ end
+ end
+
+ using RefinementBug
+
+ class C
+ remove_method :foo
+ end
+
+ assert_equal("RefinementBug#foo", C.new.foo, bug10765)
+ end;
+ end
+
+ def test_remove_undefined_refined_method
+ assert_separately([], <<-"end;")
+ bug10765 = '[ruby-core:67722] [Bug #10765]'
+
+ class C
+ end
+
+ module RefinementBug
+ refine C do
+ def foo
+ end
+ end
+ end
+
+ using RefinementBug
+
+ assert_raise(NameError, bug10765) {
+ class C
+ remove_method :foo
+ end
+ }
+ end;
+ end
+
+ module NotIncludeSuperclassMethod
+ class X
+ def foo
+ end
+ end
+
+ class Y < X
+ end
+
+ module Bar
+ refine Y do
+ def foo
+ end
+ end
+ end
+ end
+
+ def test_instance_methods_not_include_superclass_method
+ bug10826 = '[ruby-dev:48854] [Bug #10826]'
+ assert_not_include(NotIncludeSuperclassMethod::Y.instance_methods(false),
+ :foo, bug10826)
+ assert_include(NotIncludeSuperclassMethod::Y.instance_methods(true),
+ :foo, bug10826)
+ end
+
private
def eval_using(mod, s)