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 check assert_raises with generic exceptions is followed by error message check #174

Closed
fatkodima opened this issue Jun 3, 2022 · 3 comments
Labels
feature request Request for new functionality

Comments

@fatkodima
Copy link
Contributor

When testing for generic errors (like ArgumentError, RuntimeError, KeyError, IndexError etc) we need to check for the error message to not get false positives.

def foo(a, b, c)
  raise ArgumentError, "c should be 'foo'" unless c == "foo"
  # ...
end

# bad
assert_raises(ArgumentError) do
  foo(1, 2) # c is missing
end

# good
error = assert_raises(ArgumentError) do
  foo(1, 2)
end

assert_equal "c should be 'foo'", error.message # or assert_match or assert_includes

assert_raises(RuntimeError) is a 💥

@fatkodima
Copy link
Contributor Author

@koic Wdyt on this?

@koic
Copy link
Member

koic commented Jul 28, 2022

If it is disabled by default, I think it can be accepted. Probably because it is too strict as a default rule.

@koic koic added the feature request Request for new functionality label Sep 5, 2023
@koic
Copy link
Member

koic commented Jul 18, 2024

This rule seems too strict to be default, and there appears to be no requests or opinions on it for about two years. Since there has been no activity for several years, I will close this. Thank you for the proposal.

@koic koic closed this as completed Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for new functionality
Projects
None yet
Development

No branches or pull requests

2 participants