-
-
Notifications
You must be signed in to change notification settings - Fork 762
Expose ConfigurationOptions to Configuration #832
Conversation
Is there a reason to use |
Yes. It's to indicate that they are not actual I'd be open to a different prefix, or removing the prefix entirely if @dchelimsky / @myronmarston preferred. |
I like making the distinction between options defined on RSpec.configuration and those defined elsewhere, but those options can come from the command line, a file, or even an environment variable, so I like the idea of a prefix, but cmdline is a bit misleading. I don't have any good ideas but if/when I do I'll post them here. |
I didn't know what else to call them, but I agree that |
How about just |
Rather than exposing them directly off of the configuration object, what do you think about exposing a single object off of the configuration object (called something like |
option_for(#{name.inspect}) | ||
end | ||
CODE | ||
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.
FWIW, I always prefer define_method
over eval'ing a string like this. Tenderlove recently wrote up a summary comparison of the two approaches including benchmarks:
http://tenderlovemaking.com/2013/03/03/dynamic_method_definitions.html
We haven't always followed this in the rspec code base, both because we've never really talked about it as a team (and I'm not sure that others share my preference for define_method
) and also because we've been forced to use the eval approach on occasion due to the fact that 1.8.6 (and earlier) didn't allow a define_method
-defined method to accept a block...but moving forward, I'd like to use define_method
unless we have a specific reason not to.
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.
Totally, I'd be happy to switch it, but I was following the convention of the other methods.
I thought about that but @dchelimsky's comment in #732
convinced me otherwise. |
Sounds like I need to read more of the background and not just be a drive-by commenter :). |
@dchelimsky -- can you speak to your reasons for the statement @JonRowe quoted above? I prefer a separate object; to me, programmatically accessing the passed CLI options has quite different semantics from normal |
Several (but not all) of the options can be set in a pre-process scope (e.g. external files like .rspec and/or ENV vars), and in |
@dchelimsky that eloquently put into words what I was thinking in my first comment. I read the initial issue as the need to have access to some of these read only settings (no matter where they were set). However, if there is a perfectly go alternative already in |
Ok, so which should we disregard? Is there harm in exposing these under a prefix for reference purposes? |
But how is that any less confusing than Thinking about this some more...I think it's pretty rare that a user needs to access the command line options (consider that #732 is the first time that a user has ever requested it, as far as I know). The approaches we're talking about here add some maintenance cost in that every time we add a new command line option, we'd have to make sure there's a corresponding method added to |
Me: Huh? re: exposing CLI args via |
Sorry, I completely failed to make my point. The point I was trying to make is that while you are correct that having both
I've been thinking this would only be the options passed at the command line, so it would be
If nothing else, this conversation reveals that there are some semantics of this feature that we need to nail down. |
It's more like this:
See https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/configuration_options.rb#L76-L82 That the ENV options take precedence over the CLI is a legacy support issue: #276 In terms of the issue we're trying to address, if a user wishes to modify options in RSpec.configure based on CLI options, he/she is just as likely to want to be able to drive that from a user-specific options file (project-local or global), so I think exposing options at any level beyond the final merge is not only opening a rather ugly can of worms, it would also limit our options to simplify things down the road. If, in spite of that, there is a decision to press forward, I think we should go all in and offer up an ordered source map e.g. RSpec.configuration.source_for :color
# => [ [ ".rspec", "--no-color" ], [ "/Users/david/.rspec", "--color" ], [ "RSpec.configuration", "true" ] ]
# This would be nicer as an ordered hash, but we'd have to employ special handling for Ruby 1.8 e.g. `ActiveSupport::OrderedHash`. I could see that being useful as a debugging tool when trying to understand option-input precedence, but how often does that need come up? |
Thanks for writing that up, @dchelimsky -- the config system is one of the parts of rspec I've worked in the least. I had forgotten how man layers it has. The ordered source map idea looks nice, but it sounds like a lot of effort for something that would be rarely used. Regardless of what direction we go (or if we do anything at all), I want to make sure that we actually wind up addressing @jasonkarns' issue he was dealing with in #732. (Jason, we'd value your feedback here!) Revisiting my earlier idea to expose the CLI args string (which was clearly naive), would it work to expose the merged options as a hash? |
@myronmarston did you check out #834 ? I feel it might be a better appraoch to solving the simple cases like @jasonkarns' #732 without getting into the complexity @dchelimsky suggested, which I feel might be overkill... |
I also like @JonRowe's solution in #834. That solves my initial issue easily. Originally, all I had wanted to do was to set our Logger level to DEBUG when RSpec was in debugging mode. It didn't matter to me whether RSpec debug mode was triggered via ENV, CLI, or .rspec file. All I was interested in was the final option state after all option parsing/merging was complete. I would hazard a guess that this hits the 80% use-case anytime one wants access to a configuration option. |
Add in a way to expose configuration options into configuration, as a suggested implementation for #732