rubocop-minitest
rubocop-minitest copied to clipboard
New cop to check `assert_raises` with generic exceptions is followed by error message check
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 💥
@koic Wdyt on this?
If it is disabled by default, I think it can be accepted. Probably because it is too strict as a default rule.