-
-
Notifications
You must be signed in to change notification settings - Fork 762
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
RSpec makes define_method public? #873
Conversation
Looks like it is intentionally being made to be this way in memoization_helpers.rb:475 |
That's only making it public in an anonymous module, though. I don't think that affect Regardless, we should fix this. Thanks for reporting it! |
I will try to look into it further, I'd like to help 👍 |
I tried defining another method in the same place that was private (method_undefined) and it became public on Object. I think that definitively makes this the culprit. Any suggestions on how to proceed containing this? |
Other than ditching Ruby? :) I'd say removing line 475 as the following holds true:
|
To me, it feels like a bug in ruby. Regardless, we should fix the code so it doesn't do this. The reason I had put |
MemoizedHelpers::ClassMethods module was making define_method public for ease of use within the module. No longer do this and use send instead. This fixes rspec#873.
I'm guessing I've also added a test to ensure we don't leak it. Review? /cc @myronmarston @samphippen @soulcutter |
Hehe, after reporting this I investigated how visibility works in Ruby and found out the Which, on a side note, is probably a SNAFU everywhere where people expect methods defined via |
Thanks to both of you for working on this! The spec added by @JonRowe is nice (we want specs for this kind of stuff to prevent regressions), but I think I prefer the simplicity of the @thomas-holmes's fix. I had originally made the method public as a convenience...but the solution of redefining |
MemoizedHelpers::ClassMethods module was making define_method public for ease of use within the module. No longer do this and use send instead. This fixes #873.
Ok I've picked across @thomas-holmes' fix, just rerunning the specs then I'll merge it. |
@JonRowe -- thanks! Please add a changelog entry, too. |
Thanks guys! |
…ublic RSpec makes define_method public?
So this is interesting: https://bugs.ruby-lang.org/issues/8284 I started a discussion on the ruby rogues mailing list about this, someone reporte the bug to the ruby issue tracker and it got fixed. Turns out it's been a bug in MRI since ruby 1.0. |
I liked this bit
|
Beats me, but I just stumbled upon a passing test that failed IRL because it used the private
Module.define_method
. Seems that after requiring RSpec, it's not private any more.On Ruby v1.9.3 with RSpec v2.13: