-
-
Notifications
You must be signed in to change notification settings - Fork 753
Undefine methods before redefining them #1584
Conversation
@@ -185,6 +185,7 @@ def output_stream=(value) | |||
# @macro add_setting | |||
# Load files matching this pattern (default: `'**/*_spec.rb'`) | |||
add_setting :pattern | |||
undef :pattern= |
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.
Why is this one after the add_setting call. Does this one actually fix the warning?
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.
It fixes it because there's a definition of pattern=
below. I think there's a better approach, though: rather than using add_setting
, use define_reader
. add_setting
is for cases where we want both the reader and writer methods generated but we want only the reader here.
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.
Oh, right, I was confused a bit. Let me update this; just attr_reader
make sense.
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.
We actually need define_reader
to be used -- our settings need that for the semantics of spec_helper
settings being overridable when CLI options are used.
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.
Oh, gotcha. I read that one wrong the first time.
@sikachu Can you make a little gist which highlights these warnings? It'd be good to see them in action. Also, it'd be nice if we could add some tests to this pull request to check that those warnings are actually no longer happening. Can you take a look at that? |
Thanks @sikachu. We definitely want to be warning free. We already run our specs with What do you think about setting |
@samphippen -- here's the output you asked about:
|
@@ -207,6 +207,7 @@ class Procsy | |||
Proc.public_instance_methods(false).each do |name| | |||
define_method(name) { |*a, &b| @proc.__send__(name, *a, &b) } | |||
end | |||
undef :run |
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.
I think a better solution to this is to add a next if name.to_sym == :run
in the Example.public_instance_methods(false).each do |name|
loop. Then there's no reason to undef it.
Yeah, I'll fix those issues and add |
Don't worry about it. |
If you run RSpec test suite and turn on Ruby warnings (`ruby -w`), there are several warnings about method redefined: * /lib/rspec/core/configuration.rb:191: warning: method redefined; discarding old pattern= * /lib/rspec/core/example.rb:210: warning: method redefined; discarding old run * /lib/rspec/core/example.rb:204: warning: previous definition of run was here By `undef` these method first we can silence those warnings from Ruby.
@samphippen @myronmarston code is updated. How does it look now? |
@@ -201,7 +201,9 @@ class Procsy | |||
attr_reader :example | |||
|
|||
Example.public_instance_methods(false).each do |name| | |||
define_method(name) { |*a, &b| @example.__send__(name, *a, &b) } | |||
unless name.to_sym == :run |
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.
I tend to prefer using a next
guard clause, but that's just subjective preference :). Not a merge blocker.
Looks good, I'll merge when green. |
Undefine methods before redefining them
Thanks, @sikachu! |
Undefine methods before redefining them
[ci skip]
[ci skip] --- This commit was imported from rspec/rspec-core@4df38c6.
If you run RSpec test suite and turn on Ruby warnings (
ruby -w
), there are several warnings about method redefined:By
undef
these method first we can silence those warnings from Ruby.