
Issue #20922 has been updated by mame (Yusuke Endoh). Status changed from Open to Rejected Discussed at the dev meeting. @matz said he was not going to remove this warning. Several ideas to prevent a warning were raised. Parenthesizing only the first argument prevents the warning. This solution works today, and usable for `{}` as well. ``` assert_equal (-1), minus_one assert_match (/foo/), str ``` Assigning the first argument to a varaible also works. ``` re = /foo/ assert_match re, str ``` A new idea is to prevent a warning when there are *two* spaces, but not accepted. ``` assert_equal -1, minus_one ``` Finally, writing the method call parentheses only where necessary ``` assert_equal 1, one assert_equal 0, zero assert_equal(-1, minus_one) ``` is the most reasonable solution. :sad: ---------------------------------------- Feature #20922: Should not we omit parentheses in assert calls? https://bugs.ruby-lang.org/issues/20922#change-110975 * Author: mame (Yusuke Endoh) * Status: Rejected ---------------------------------------- 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. -- https://bugs.ruby-lang.org/