Skip to content

Commit

Permalink
Merge pull request #1026 from AI-Mozi/add_specs_for_module_undef_inst…
Browse files Browse the repository at this point in the history
…_meth

Add specs for `Module#undefined_instance_methods`
  • Loading branch information
andrykonchin authored May 15, 2023
2 parents 80c98ae + 6a6c490 commit 83b5dda
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions core/module/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions core/module/undefined_instance_methods_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 83b5dda

Please sign in to comment.