-
-
Notifications
You must be signed in to change notification settings - Fork 753
Aliasing API for #describe #870
Conversation
@@ -604,6 +604,13 @@ def alias_example_to(new_name, *args) | |||
RSpec::Core::ExampleGroup.alias_example_to(new_name, extra_options) | |||
end | |||
|
|||
def alias_example_group_to(new_name, *metadata_and_opts) | |||
top_level_method = !!metadata_and_opts.delete(:toplevel_alias) |
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.
This has the side effect of modifying the passed in hash. Consider a case like this:
RSpec.configure do |c|
focused_options = { focus: true, toplevel_alias: true }
c.alias_example_group_to :focus, focused_options
c.alias_example_group_to :focused, focused_options
end
The 2nd one will not work properly because the first one modifies the passed in options.
I think it's better to dup the hash before deleting from it.
@michihuber -- fantastic work. This is very well written! A few additional thoughts:
RSpec.shared_examples_for "some behavior" do
end
RSpec.describe MyClass do
end
|
Thanks for your detailed comments, @myronmarston, much appreciated! I totally missed #790, but reread it now. You weren't sure about toplevel support, what do you think about it now? I think the overhead is reasonable, but it would introduce a "reserved" metadata key, as you pointed out above. What about a different method? I wanted to get input about where the DSL should be included in first, I'll add it to RSpec. I'll fix the stuff you commented on (and the failing specs) in the next few days. |
From my side, a 3.0 release without 1.8.6 is fine, but I'd make the necessary changes of course if somebody needs it earlier. |
I like the feature a lot now, because it gives us the possibility of having a zero-monkey-patching RSpec. That's really cool. As for the reserved metadata key...I'm on the fence about it. We already have a couple of those (e.g.
Maybe...problem is, that suggests that the alias is only at the top level. More thought is needed, I think. |
I also like the idea of having zero monkey patching :) but I think we'd definitely want an easy way to access the DSL if top level was turned off.. I'm not sure I like polluting RSpec directly though... maybe we could go with something like Also, crazy thought but could we disable mixing in describe to the top level, but then have the runner eval _spec files within the context of that DSL? Thus removing monkey patching but also allowing a legacy style? |
I've addressed most of @myronmarston's comments. Some open questions:
|
What problem do you see with "polluting"
This is a very interesting idea that has never occurred to me! (That's the great thing about bringing new folks on board; they bring new ideas...) However, I'm concerned about the repercussions of such a change:
|
Fair enough, I just edge away from everything being on the top level, but I guess a
Hmm. We could make main available to people to work around this, altho I feel it's very edge case?
They should continue to work as is inside RSpec, as everything would be nested... Support files would also continue to be defined from main.
Agreed.
Like I said it was a crazy thought, I was mostly concerned with how we could remove monkey patching whilst preserving existing functionality for our users. |
@michihuber want to try rebasing this now the monkey patching PR is merged? |
BTW, regarding whether or not this config option should add top-level describe alias: I think that should depend on the setting @JonRowe added in #1036. That'll be cleaner than forcing the user to pass a particular hash key to specify that. We should probably also make |
Sure, I’ll update this to use @JonRowe’s new setting in the upcoming week. On Saturday 7 December 2013 at 17:42, Myron Marston wrote:
|
@myronmarston, I think it might be useful to allow making What about two different config methods instead of a reserved hash key? I proposed Maybe finding a new method name might be worthwhile and less confusing than expose_globally changing scope and content. |
@michihuber you'll note there will need to be some rejigging to make my code work with custom aliases, so it'd be nice to refactor it to add the default aliases but also any custom ones in the same mechanism |
Why is that useful? It's unclear to me. FWIW, |
Sure, that makes sense. On Monday 16 December 2013 at 01:10, Myron Marston wrote:
|
Close in favor of #1236. |
This adds the ability to configure aliases for #describe with default metadata, as requested in #493.
ExampleGroup.describe
to.example_group
(and aliases it back to.describe
).Configuration#alias_example_group_to
, which accepts default metadata and a:toplevel_alias
option.--toplevel-off
flag, which avoids extending the main object with the DSL methods (i.e. #describe and defined aliases).