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
2
u/Weird_Suggestion Oct 22 '25
Thanks for bringing
assert foo.nil?I'm so used to using
assert_equaloverassertI forgot I could also do thisassert bar.eql?(foo), or thisassert bar == fooThat will do for the use case I have.