From 6a6c4904cc504defef2227f1e2215d88e5333b6d Mon Sep 17 00:00:00 2001 From: AI-Mozi Date: Fri, 12 May 2023 14:58:37 +0200 Subject: [PATCH] Add specs for `Module#undefined_instance_methods` --- core/module/fixtures/classes.rb | 26 +++++++++++++++++++ .../module/undefined_instance_methods_spec.rb | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 core/module/undefined_instance_methods_spec.rb diff --git a/core/module/fixtures/classes.rb b/core/module/fixtures/classes.rb index bc6b940a6..a434e7b0b 100644 --- a/core/module/fixtures/classes.rb +++ b/core/module/fixtures/classes.rb @@ -596,6 +596,32 @@ def foo private :foo end EmptyFooMethod = m.instance_method(:foo) + + # for undefined_instance_methods spec + module UndefinedInstanceMethods + module Super + def super_included_method; end + end + + class Parent + def undefed_method; end + undef_method :undefed_method + + def parent_method; end + def another_parent_method; end + end + + class Child < Parent + include Super + + undef_method :parent_method + undef_method :another_parent_method + end + + class Grandchild < Child + undef_method :super_included_method + end + end end class Object diff --git a/core/module/undefined_instance_methods_spec.rb b/core/module/undefined_instance_methods_spec.rb new file mode 100644 index 000000000..3be860d05 --- /dev/null +++ b/core/module/undefined_instance_methods_spec.rb @@ -0,0 +1,26 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +describe "Module#undefined_instance_methods" do + ruby_version_is "3.2" do + it "returns methods undefined in the class" do + methods = ModuleSpecs::UndefinedInstanceMethods::Parent.undefined_instance_methods + methods.should == [:undefed_method] + end + + it "returns inherited methods undefined in the class" do + methods = ModuleSpecs::UndefinedInstanceMethods::Child.undefined_instance_methods + methods.should include(:parent_method, :another_parent_method) + end + + it "returns methods from an included module that are undefined in the class" do + methods = ModuleSpecs::UndefinedInstanceMethods::Grandchild.undefined_instance_methods + methods.should include(:super_included_method) + end + + it "does not returns ancestors undefined methods" do + methods = ModuleSpecs::UndefinedInstanceMethods::Grandchild.undefined_instance_methods + methods.should_not include(:parent_method, :another_parent_method) + end + end +end