-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
find-method does not search methods created by 'extend' #2274
Comments
adfoster-r7
changed the title
find-method does not search include extended methods
find-method does not search methods created by 'extend'
Mar 29, 2023
I think these are the tests that I would like to have passing: diff --git a/spec/commands/find_method_spec.rb b/spec/commands/find_method_spec.rb
index 7be22752..e489d909 100644
--- a/spec/commands/find_method_spec.rb
+++ b/spec/commands/find_method_spec.rb
@@ -1,6 +1,13 @@
# frozen_string_literal: true
describe "find-method" do
+
+ MyMixin = Module.new do
+ def mixin_method
+ "linus"
+ end
+ end
+
MyKlass = Class.new do
def hello
"timothy"
@@ -19,6 +26,14 @@ describe "find-method" do
end
end
+ MyKlassWithMixin = Class.new(MyKlass) do
+ include MyMixin
+ end
+
+ MyInstanceWithMixin = MyKlass.new.tap do |instance|
+ instance.extend(MyMixin)
+ end
+
describe "find matching methods by name regex (-n option)" do
it "should find a method by regex" do
expect(pry_eval(binding, "find-method hell MyKlass")).to match(
@@ -26,6 +41,18 @@ describe "find-method" do
)
end
+ it "should find included methods by regex" do
+ expect(pry_eval(binding, "find-method mix MyKlassWithMixin")).to match(
+ /MyMixin.*?mixin_method/m
+ )
+ end
+
+ it "should find extended methods by regex" do
+ expect(pry_eval(binding, "find-method mix MyInstanceWithMixin")).to match(
+ /MyMixin.*?mixin_method/m
+ )
+ end
+
it "should NOT match a method that does not match the regex" do
expect(pry_eval(binding, "find-method hell MyKlass")).not_to match(
/MyKlass.*?goodbye/m
@@ -40,6 +67,18 @@ describe "find-method" do
)
end
+ it "should find included methods by regex" do
+ expect(pry_eval(binding, "find-method -c linus MyKlassWithMixin")).to match(
+ /MyMixin.*?mixin_method/m
+ )
+ end
+
+ it "should find extended methods by regex" do
+ expect(pry_eval(binding, "find-method -c linus MyInstanceWithMixin")).to match(
+ /MyMixin.*?mixin_method/m
+ )
+ end
+
it "should NOT match a method that does not match the regex" do
expect(pry_eval(binding, "find-method timothy MyKlass")).not_to match(
/MyKlass.*?goodbye/m But currently the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scenario:
Two objects:
The
find-method
implementation doesn't work with theextend
mixin scenario, only theinclude
scenarioCurrent output:
Expected output:
Ruby itself is able to resolve the methods on the instance as expected:
Versions
The text was updated successfully, but these errors were encountered: