-
-
Notifications
You must be signed in to change notification settings - Fork 763
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
Remove monkey patching #1036
Remove monkey patching #1036
Conversation
Ping! Has anyone had a chance to start to review this yet? |
I haven't yet...too busy with moving still. I'll try to get to it soon. One general comment: there's also #870 where some work was started to make example group alias methods available at the top level. Does this PR fit in with that? I'd like to find a way to integrate that at some point. |
I need to rework this to take advantage of #870 me thinks... |
Ok so I'd like to get this sorted, and then take #870 back on top of this, I don't mind assisting or taking over from @michihuber to get these two across the line. |
So a review would be good, then I'll sort squashing etc, at a minium a change log entry needs adding ;) |
@@ -0,0 +1,44 @@ | |||
Feature: Monkey patching | |||
|
|||
Use the monkey patching to tell RSpec to allow or disallow the top level dsl. |
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.
"the monkey patching" is funny, but should just be "monkey patching" to be correct. I don't mind one way or the other :)
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 actually wonder if we should call this monkey patching at all, perhaps we should state that what this is doing more explicitly? How about:
Tell RSpec to expose the dsl via the global namespace.
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.
yes
You can always undefine the monkey-patched methods as we do in rspec-mocks and rspec-expectations, but that would require bare method defs rather than module inclusion/extension. And actually, I think I prefer the way you have it. Hmm, actually, thinking about it some more: I'm not sure that the way you have it will work for end users. You add the monkey patches before loading the spec files. Most users who will disable this will disable it in So I think we probably want to move to a mechanism like rspec-mocks and rspec-expectatations. See the Overall this is looking great. I want to hold off on merging this until we release our 3.0.0.alpha, though. |
Okay, this has been reworked to change the name to |
Build failure is due to @alindeman's JRuby issue in rspec-mocks :/ |
|
||
Tell RSpec to expose the DSL via the global namespace | ||
|
||
Scenario: by default RSpec allows the top level monkey patching |
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.
should update this text to enable global.
@myronmarston why? |
Scenario: when exposing globally is disabled top level dsl no longer works | ||
Given a file named "spec/example_spec.rb" with: | ||
"""ruby | ||
RSpec.configure { |c| c.expose_globally = false } |
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.
You know, I'm not sure that expose_globally
has the right sense. It's not exposed in the global scope like a global variable is. It's exposed at the top level scope off of main
.
Also, from the config option name it's not clear what is being exposed.
What do you think about expose_dsl_off_of_main
instead?
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's not just main though, it's also off Module
(so you can nest describe inside modules/classes) so it is kind of globally... it's also too wordy for my liking.
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 could go for expose_dsl
though.
@xaviershay -- my primary concern is that I want a release to be consistent, without in-progress, half-done features. #870 is another aspect of this feature, I think, and it feels incomplete without that. As such, I don't want to have this merged and then block our being able to release a solid alpha. Once we ship that first alpha, it's fine to merge things like this that will have later PRs to round-out the features. |
So I rebased this and it broke horrifically. I'm at a loss as to what's changed in master that breaks this, my hunch is that it's something to do with the sandboxing going awry... See the diff or pull down the e.g. HALP |
Did anyone get a chance to look at my other branch? @myronmarston @xaviershay @samphippen |
Not yet -- I'll take a look later this week. |
I pulled your branch now and bisected it. b9adedd is the source commit that introduces the problems. |
Yes, it's also the My investigations have lead me to uncover that somehow |
@JonRowe -- would you like me to take this over or are you still planning to get to the bottom of the problem you're having? |
e.g. * use RSpec.describe as opposed to describe * use RSpec DSL for shared examples
FYI the methods are idempotent just Ruby issues a warning... additionally I've actually noticed the methods protect against this themselves making the configuration check a non issue. I've also moved the initial call to the only place we initialised Configuration. So by default it'll be set but for every other usage of I personally read |
config_1 = Configuration.new | ||
config_2 = Configuration.new | ||
config_1 = Configuration.new.tap { |c| c.expose_globally = false } | ||
config_2 = Configuration.new.tap { |c| c.expose_globally = false } |
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.
Given that new Configuration
instances no longer set expose_globally = true
, I think you no longer have to set expose_globally = false
here (or in any of the other specs), right?
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 you're right, shall we drop them?
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.
Please do. It's noise and it suggests that it's necessary when it's not, which leads to confusion.
Since we want rspec to be warning-free, can you fix it so ruby doesn't issue a warning?
👍
That doesn't seem any clearer to me: If others think it's perfectly clear I'm happy to go with what you have, though. |
They are warning free, thats what the extra protective code is doing, I removed the var check from |
👍 I guess I misread your comment then. Thanks! Anyhow, this is looking good to me. My concern about the |
Oh yeah, one other thing: the |
I added an additional line to the YARD explaining a bit more, I also changed my mind about the name of the config var. |
I've moved the config line back to the sandboxing. My reasoning is that this is the easiest way to ensure consistent state across the spec run with regards to this setting. To me it makes much more sense to protect against this one setting here rather than run anything that touches |
I decided if we need to refactor the specs thwn we can do that later. |
ATM I've defaulted to off in our specs, and on in the cucumbers, but we can discuss that if you disagree.
Thoughts?
/cc @alindeman @myronmarston @samphippen @soulcutter