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

New cop: Minitest/HooksGrouping #214

Closed
fatkodima opened this issue Dec 30, 2022 · 2 comments · Fixed by #232
Closed

New cop: Minitest/HooksGrouping #214

fatkodima opened this issue Dec 30, 2022 · 2 comments · Fixed by #232
Labels
enhancement New feature or request

Comments

@fatkodima
Copy link
Contributor

Or there is a better name for this cop.
It will check that setup/teardown are before all the test cases, and that setup is before teardown. It adds consistency and enforces the expectation of these methods to go first (to be easily noticeable/etc).

# bad
class SomethingTest < Minitest::Test
  def setup; end
  def test_something; end
  def teardown; end
end

# bad
class SomethingTest < Minitest::Test
  def teardown; end
  def setup; end
  def test_something; end
end

# good
class SomethingTest < Minitest::Test
  def setup; end
  def teardown; end
  def test_something; end
end
@koic
Copy link
Member

koic commented Dec 30, 2022

Yeah, the naming is difficult too, there is a better name 😅 Anyway, I think it's worth opening up to the style guide first:
https://github.com/rubocop/minitest-style-guide

@koic koic added the enhancement New feature or request label Dec 30, 2022
@tejasbubane
Copy link
Contributor

tejasbubane commented Dec 30, 2022

Better name would be Minitest/HooksOrder similar to Style/RequireOrder, Style/KeywordParametersOrder, Rails/ActiveRecordCallbacksOrder, etc.

Additionally I think it should check for all hooks including the before and after methods:

# bad
class SomethingTest < Minitest::Test
  def after_teardown; end
  def before_teardown; end
  def setup; end
  def before_setup; end
  def after_setup; end
  def teardown; end
end

# good
class SomethingTest < Minitest::Test
  def before_setup; end
  def setup; end
  def after_setup; end
  def before_teardown; end
  def teardown; end
  def after_teardown; end
end

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

Successfully merging a pull request may close this issue.

3 participants