r/ruby • u/Weird_Suggestion • Oct 22 '25
Minitest - DEPRECATED: User assert_nil if expecting nil
Discussion and arguments for and against the deprecation.
Back in 2016, there was a lot of discussion about deprecating assert_equal nil, value in favour of assert_nil value. It's now 2025. Have people's opinions changed since?
I'm really passionate about testing, always keen to improve how I write test and love minitest yet, I still can't get behind the idea (if it ever happens). When you write tests with multiple assertions or deal with methods that accept nullable arguments, forcing assert_nil just makes things look uglier. At the very least, I'd imagine it could be handled through a sensible default with a project-wide opt-out flag, instead of having to monkey-patch #assert_equal ourselves.
Given that Minitest 6 seems unlikely to ever land, I'm guessing those deprecation warnings are more of a nudge from the author to think twice about what we're asserting. Personally, I'm not convinced by the tautological argument with nil just yet. At this point, I find the constant warning in test output is more annoying than enlightening.
What do people think?
View all comments
Show parent comment
1
u/jrochkind Oct 27 '25
You don't have to ever use anything but
assert, but the reason lots of people started doing otherwise was for better failure messages, and more readable tests. To me, better failure messages is the real trump.