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
If you glance at it you'd expect the test to pass or fail. But in reality, it returns after the second line. If you're catching assertionless tests you might catch it, but if not then you'll think it passes even when the assert line never gets hit.
Describe the solution you'd like
A linter that disallows using return in tests.
Note that this should only apply in tests that use test and a block. So while this test is also buggy, it should be accepted, since there is a valid use case for return in a method-based test (I think... I don't use this syntax).
It seems that the problem is in the unintuitive behaviour of the return statement inside a block.
I can still see usefulness of guard statements in tests.
It's hard to say whether this cop is useful for everyone, as it is not designed just for Rails. Therefore, I'll close this issue. Thanks for the suggestion.
Is your feature request related to a problem? Please describe.
Consider this contrived example:
If you glance at it you'd expect the test to pass or fail. But in reality, it returns after the second line. If you're catching assertionless tests you might catch it, but if not then you'll think it passes even when the assert line never gets hit.
Describe the solution you'd like
A linter that disallows using
return
in tests.Note that this should only apply in tests that use
test
and a block. So while this test is also buggy, it should be accepted, since there is a valid use case forreturn
in a method-based test (I think... I don't use this syntax).Describe alternatives you've considered
I'm not sure on any other ways to catch this but would appreciate suggestions.
The text was updated successfully, but these errors were encountered: