-
-
Notifications
You must be signed in to change notification settings - Fork 278
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 aliases runtime matchers #956
Conversation
2d63428
to
f310907
Compare
|
62c3a15
to
346b685
Compare
346b685
to
44e7d6e
Compare
853e47b
to
bfa1475
Compare
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.
Frankly, it looks great. All code review notes are minor nitpicks.
I'm concerned about two major things:
- performance impact: dynamic way to define matchers may cost us
- consistency: are we going to use this approach for all RSpec's DSL constructs
If there's no significant performance impact (e.g. on Discourse/GitLab specs suite runs), I'll be more than happy to merge this. We'll eventually catch up and rework other DSL elements to use this dynamic configuration.
@sl4vr Do you need some help with this? |
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.
Looks good! 👏
Minor notes, mostly on how to keep the existing cops intact.
Eager to rework the rest in the same way and start hacking on adding the missing DSL pieces.
9590e21
to
89acc68
Compare
Because it highly depends on config and may change yet. |
@bquorning Both this PR's build and #1007 that I've just rebased onto this are green. |
But how come the specs passed when run with the entire suite? Usually it means there is some global state being changed somewhere. |
There is indeed global state, in |
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 PR looks so much better now. I think we are getting very close to merging.
|
||
module ExampleGroups | ||
GROUPS = SelectorSet.new(%i[describe context feature example_group]) |
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.
By the way, how come that we changed from ExampleGroups::GROUPS
to ExampleGroups#regular
and from Examples::EXAMPLES
to Examples#regular
?
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.
Hm. I lost track of this.
To me, "regular" sounds better. But we at least have to mention this in the update_to_v2 document.
@@ -32,7 +32,7 @@ def on_block(node) | |||
|
|||
def in_spec_block?(node) | |||
node.each_ancestor(:block).any? do |ancestor| | |||
Examples::ALL.include?(ancestor.method_name) | |||
Examples.all(ancestor.method_name) |
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 code reads a bit weird. It looks like there’s a question mark missing, i.e. Examples.all?(ancestor.method_name)
, but that’s also not good.
Probably not something we need to fix now, but just an observation.
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.
Indeed. Those new helpers fit patterns more.
I can think of adding an include?
alias for all
to all of them, however, this will not provide a similar interface to Examples.regular
.
Another way is to check if an argument has been passed (used in a pattern), or not. If not - just return a list, and this will make both Examples.all.include?(ancestor.method_name)
and Examples.regular.include?(ancestor.method_name)
possible.
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.
Returning different types (boolean vs array) from the same method also isn’t great. Maybe we should call #all?
from within out patterns? Also not really a great option :-/
I think we should just leave it for now.
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.
d2d1355
to
e515d21
Compare
@sl4vr Thanks a lot for implementing this. It is a huge amount of work, really, I now understand this after making subtle changes. It's time to claim your CoM trophy, but it's not all, you also get this symbolic golden RuboCop statuette: @marcandre Thanks a lot for early-stage reviews, incredible suggestions and making changes to |
Thanks @pirj, you're too kind 😅 |
@pirj thank you for leading and finishing this PR 😅 |
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls. See: - rubocop/rubocop-rspec#1077 - rubocop/rubocop-rspec#956 - palkan#103
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls. See: - rubocop/rubocop-rspec#1077 - rubocop/rubocop-rspec#956 - palkan#103
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls. See: - rubocop/rubocop-rspec#1077 - rubocop/rubocop-rspec#956 Sibling pull requests: - palkan/action_policy#138
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls. See: - rubocop/rubocop-rspec#1077 - rubocop/rubocop-rspec#956 Sibling pull requests: - palkan/action_policy#138
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls. See: - rubocop/rubocop-rspec#1077 - rubocop/rubocop-rspec#956 Sibling pull requests: - palkan/action_policy#138
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls. See: - rubocop/rubocop-rspec#1077 - rubocop/rubocop-rspec#956 - palkan#103
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls. See: - rubocop/rubocop-rspec#1077 - rubocop/rubocop-rspec#956 Sibling pull requests: - palkan/action_policy#138
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls. See: - rubocop/rubocop-rspec#1077 - rubocop/rubocop-rspec#956 - #103
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls. See: - rubocop/rubocop-rspec#1077 - rubocop/rubocop-rspec#956 Sibling pull requests: - palkan/action_policy#138
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls. See: - rubocop/rubocop-rspec#1077 - rubocop/rubocop-rspec#956 Sibling pull requests: - palkan/action_policy#138
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls. See: - rubocop/rubocop-rspec#1077 - rubocop/rubocop-rspec#956 - palkan/action_policy#103
This is an attempt of implementation of issue #333 and evolution of PR #921. Allowing to configure 3rd partly DSLs as valid RSpec syntax.
Configurable language elements:
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).