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 to narrow down assert_raises bodies #109

Closed
fatkodima opened this issue Aug 7, 2020 · 1 comment · Fixed by #177
Closed

New cop to narrow down assert_raises bodies #109

fatkodima opened this issue Aug 7, 2020 · 1 comment · Fixed by #177
Labels
enhancement New feature or request

Comments

@fatkodima
Copy link
Contributor

# bad
assert_raises(...) do
  some_other_code
  do_something
end

# good
some_other_code

assert_raises(...) do
  do_something
end

It is a good practice to make assert_raises bodies as small as possible, so that:

  1. it is obvious which method call is tested for error
  2. and when multiple calls inside assert_raises can raise the same kind of an exception, there won't be false positives and the right method is tested

So this cop will suggest that assert_raises body contains only 1 top level node and it should of send/csend type.

@koic Wdyt on this?

@koic
Copy link
Member

koic commented Apr 28, 2021

This looks good to me. I think this cop can accept blocks (block type) as follows.

# good
assert_raises(...) do
  do_something do
    foo
    bar
  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.

2 participants