-
-
Notifications
You must be signed in to change notification settings - Fork 397
Add specs for Method#original_name and #inspect with Kernel methods #1356
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,4 +40,20 @@ | |
| klass.new.method(:renamed).original_name.should == :my_method | ||
| klass.new.method(:aliased).original_name.should == :my_method | ||
| end | ||
|
|
||
| it "returns the source UnboundMethod's name for Kernel#is_a? and Kernel#kind_of?" do | ||
| klass = Class.new { define_method(:is_a?, ::Kernel.instance_method(:is_a?)) } | ||
| klass.new.method(:is_a?).original_name.should == :is_a? | ||
|
|
||
| klass = Class.new { define_method(:kind_of?, ::Kernel.instance_method(:kind_of?)) } | ||
| klass.new.method(:kind_of?).original_name.should == :kind_of? | ||
| end | ||
|
|
||
| it "preserves the source name when aliasing a define_method'd Kernel method" do | ||
| klass = Class.new do | ||
| define_method(:is_a?, ::Kernel.instance_method(:is_a?)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, this should have another name |
||
| alias_method :renamed_is_a?, :is_a? | ||
| end | ||
| klass.new.method(:renamed_is_a?).original_name.should == :is_a? | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -78,4 +78,30 @@ def obj.bar; end | |||||
| it "shows the metaclass and the owner for a Module instance method retrieved from a class" do | ||||||
| String.method(:include).inspect.should.start_with?("#<Method: #<Class:String>(Module)#include") | ||||||
| end | ||||||
|
|
||||||
| it "shows the original name in parentheses for an aliased method" do | ||||||
| klass = Class.new do | ||||||
| def original_method; end | ||||||
| alias_method :renamed_method, :original_method | ||||||
| end | ||||||
| klass.new.method(:renamed_method).send(@method).should =~ /#renamed_method\(original_method\)/ | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| end | ||||||
|
|
||||||
| it "shows the source UnboundMethod's name in parentheses for a define_method'd method" do | ||||||
| klass = Class.new { define_method(:renamed_is_a?, ::Kernel.instance_method(:is_a?)) } | ||||||
| klass.new.method(:renamed_is_a?).send(@method).should =~ /#renamed_is_a\?\(is_a\?\)/ | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, |
||||||
| end | ||||||
|
|
||||||
| it "does not annotate a directly looked-up Kernel method with a shared internal name" do | ||||||
| Object.new.method(:is_a?).send(@method).should_not =~ /\(kind_of\?\)/ | ||||||
| Object.new.method(:kind_of?).send(@method).should_not =~ /\(is_a\?\)/ | ||||||
|
Comment on lines
+96
to
+97
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
| end | ||||||
|
|
||||||
| it "shows the source name when aliasing a define_method'd Kernel method" do | ||||||
| klass = Class.new do | ||||||
| define_method(:is_a?, ::Kernel.instance_method(:is_a?)) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be good to give this one another name for clarity and to make it more interesting |
||||||
| alias_method :renamed_is_a?, :is_a? | ||||||
| end | ||||||
| klass.new.method(:renamed_is_a?).send(@method).should =~ /#renamed_is_a\?\(is_a\?\)/ | ||||||
| end | ||||||
| end | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,4 +30,30 @@ | |
| it "does not show the defining module if it is the same as the origin" do | ||
| UnboundMethodSpecs::A.instance_method(:baz).send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::A#baz" | ||
| end | ||
|
|
||
| it "shows the original name in parentheses for an aliased method" do | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This duplication for UnboundMethod is not ideal. One way to fix it would be to use a separate shared spec |
||
| klass = Class.new do | ||
| def original_method; end | ||
| alias_method :renamed_method, :original_method | ||
| end | ||
| klass.instance_method(:renamed_method).send(@method).should =~ /#renamed_method\(original_method\)/ | ||
| end | ||
|
|
||
| it "shows the source UnboundMethod's name in parentheses for a define_method'd method" do | ||
| klass = Class.new { define_method(:renamed_is_a?, ::Kernel.instance_method(:is_a?)) } | ||
| klass.instance_method(:renamed_is_a?).send(@method).should =~ /#renamed_is_a\?\(is_a\?\)/ | ||
| end | ||
|
|
||
| it "does not annotate a directly looked-up Kernel method with a shared internal name" do | ||
| Object.instance_method(:is_a?).send(@method).should_not =~ /\(kind_of\?\)/ | ||
| Object.instance_method(:kind_of?).send(@method).should_not =~ /\(is_a\?\)/ | ||
| end | ||
|
|
||
| it "shows the source name when aliasing a define_method'd Kernel method" do | ||
| klass = Class.new do | ||
| define_method(:is_a?, ::Kernel.instance_method(:is_a?)) | ||
| alias_method :renamed_is_a?, :is_a? | ||
| end | ||
| klass.instance_method(:renamed_is_a?).send(@method).should =~ /#renamed_is_a\?\(is_a\?\)/ | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give the new method another name otherwise this doesn't test anything, same below