Feature #20922
openShould not we omit parentheses in assert calls?
Description
I often see the style of omitting parentheses in assert calls, but it leads to annoying warnings in the following case:
assert_equal -1, val #=> warning: ambiguous first argument; put parentheses or a space even after `-` operator
assert_match /foo/, str #=> warning: ambiguous `/`; wrap regexp in parentheses or add a space after `/` operator
To deal with this warning, it is necessary to add parentheses only to some assert calls.
assert_equal 1, one
assert_equal 0, zero
assert_equal(-1, minus_one)
Obviously, this is not very cool.
I feel that by these warnings, Ruby says "we should not omit parentheses in assert calls". Is this what matz intended?
If it is the intent, I would like to add parentheses on all assert calls in tests of Ruby and default gems.
If it is not the intent, why don't we remove these warnings?
Note that, as far as I recall, I encountered this problem only with assert_equal
and assert_match
.
I don't write parentheses in p
, puts
, attr_reader
, include
, etc., but all of them rarely accept -1
and //
literally as the first argument in real code.
As a milder approach, I came up with an idea to stop the warning only when the method name starts with "assert". It is very ad-hoc, though.