You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
ActiveSupport's assert_changes is often misused to check if an expression's value has changed by a specific delta during the execution of a block. For example:
assert_changes(-> { value }, 1) do
value += 1
end
However, the second argument to assert_changes is actually the message emitted on assertion failure, NOT the expected change delta. assert_changes uses from: and to: named arguments to accept specific change values.
It may be difficult to identify this mistake, as the assertion will pass as long as the expression changes by ANY value.
FYI assert_difference is probably what developers are looking for - it actually does accept an expected delta.
Describe the solution you'd like
Cop should prevent use of non-string message parameters for assert_changes.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
ActiveSupport's assert_changes is often misused to check if an expression's value has changed by a specific delta during the execution of a block. For example:
However, the second argument to
assert_changes
is actually themessage
emitted on assertion failure, NOT the expected change delta.assert_changes
usesfrom:
andto:
named arguments to accept specific change values.It may be difficult to identify this mistake, as the assertion will pass as long as the expression changes by ANY value.
FYI assert_difference is probably what developers are looking for - it actually does accept an expected delta.
Describe the solution you'd like
Cop should prevent use of non-string message parameters for
assert_changes
.The text was updated successfully, but these errors were encountered: