Skip to content
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

Refactor for RSpec/BeforeAfterAll #1739

Merged
merged 1 commit into from
Nov 14, 2023
Merged

Refactor for RSpec/BeforeAfterAll #1739

merged 1 commit into from
Nov 14, 2023

Conversation

ydah
Copy link
Member

@ydah ydah commented Nov 14, 2023

  • Use Set[...] instead of %i[...]
  • Use RESTRICT_ON_SEND in def_node_matcher

Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • [-] Added tests.
  • [-] Updated documentation.
  • [-] Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

@@ -30,11 +30,11 @@ class BeforeAfterAll < Base
'`use_transactional_fixtures` is enabled, then records created ' \
'in `%<hook>s` are not automatically rolled back.'

RESTRICT_ON_SEND = %i[before after].freeze
RESTRICT_ON_SEND = Set[:before, :after].freeze
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason to use a set?
Seems that for the majority of cops we use %i. If we prefer set:

  • we need to update the rest of the cops
  • we can provide a check in the internal investigations that RESTRICT_ON_SEND is defined as Set

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was to make it easier to reuse in def_node_matcher. If we use %i, it would have to be something like {:#{RESTRICT_ON_SEND.join(' :')}}, wouldn't it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. Thank you 👍


# @!method before_or_after_all(node)
def_node_matcher :before_or_after_all, <<-PATTERN
$(send _ {:before :after} (sym {:all :context}))
$(send _ RESTRICT_ON_SEND (sym {:all :context}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to reuse 👍

- Use `Set[...]` instead of  %i[...]
- Use RESTRICT_ON_SEND in def_node_matcher
@pirj pirj merged commit 6411145 into master Nov 14, 2023
22 checks passed
@pirj pirj deleted the refactor branch November 14, 2023 19:24
@pirj
Copy link
Member

pirj commented Nov 14, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants