-
-
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
Update lib/rspec/core/example_group.rb #790
Conversation
"action" alias for describe: The purpose of this is to declare a description of some kind of action which is performed repeatedly on many sub-items with out "abusing" context and without needing to alias it_behaves_like and calling that repeatedly. One situation where this would be useful would be an auditing database trigger that inserts a record into an auditing table for each column of the record that the trigger was fired on. Currently it would be done something like this: describe "My Trigger" do context "When an update is done on a record" do it_performs "an audit", "COLUMN_ONE" it_performs "an audit", "COLUMN_TWO" it_performs "an audit", "COLUMN_THREE" end end Which outputs along the lines of: My Trigger When an update is done on a record performs an audit On COLUMN_ONE performs an audit On COLUMN_TWO performs an audit On COLUMN_THREE What the action alias would do is allow you to declare that a required action should take place, but to not repeat this for every item the action should happen for. Which would allow for the following: describe "My Trigger" do context "When an update is done on a record" do action "performs an audit" do include_examples "test the audit results", "COLUMN_ONE" include_examples "test the audit results", "COLUMN_TWO" include_examples "test the audit results", "COLUMN_THREE" end end end Which would output along the lines of: My Trigger When an update is done on a record performs an audit On COLUMN_ONE On COLUMN_TWO On COLUMN_THREE While there my be other benefits to this, the main purpose behind this idea is to improve readability.
I can see the readability benefits in your specific case, but I'm dubious of the general applicability of I was also just thinking about the fact that we have https://www.relishapp.com/rspec/rspec-core/docs/configuration/alias-example-to What do you think about adding an Thoughts? |
I that that alias_describe_to is a PERFECT solution. Better than adding a new alias to core. That possibility did not occur to me. Yes, lets proceed with that. |
I'd recommend |
I think it's a great idea, btw. |
I agree--that's more consistent and reads better. Sent from my iPhone On Feb 7, 2013, at 9:05 AM, David Chelimsky notifications@github.com wrote:
|
So alias_example_group_to would be something like this? def self.alias_example_group_to(alias)
alias_method alias, :describe
end |
I'd actually recommend making
Another issue to consider here: WDYT? |
Yeah, that way even |
One thing we'll want with https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/configuration.rb#L546-L570
I agree with scoping the methods created by this to only nested groups and not at the top level.
FWIW, it seemed much more important to provide a way to not pollute the top level back before my change in de01e05 -- that kept |
I'd be very wary of producing top-level methods with |
I also think we can preserve |
Right...I was trying to agree with this when I said:
I dislike
Currently we have only |
Very few people will choose to use |
Who knows what situation someone might think up. And could happen that someone wants implement entirely different aliases based on some type of DSL. |
True. I'm still concerned about treating one of the entries of the metadata hash differently, but I'm not sure what (if anything) can be done about that. @EarthCitizen -- do you plan to submit a PR for this? (I'd like to close this one since the solution we've discussed is entirely different). |
Closing the issue. Much better solution presented. |
There's actually a PR up for this now: #870. |
Sounds good. |
"action" alias for describe:
The purpose of this is to declare a description of some kind of action which is performed repeatedly on many sub-items with out "abusing" context and without needing to alias it_behaves_like and calling that repeatedly.
One situation where this would be useful would be an auditing database trigger that inserts a record into an auditing table for each column of the record that the trigger was fired on.
Currently it would be done something like this:
Which outputs along the lines of:
What the action alias would do is allow you to declare that a required action should take place, but to not repeat this for every item the action should happen for. Which would allow for the following:
Which would output along the lines of:
While there my be other benefits to this, the main purpose behind this idea is to enhance readability.