I read an interesting article on why the string type is broken this week. It was written in 2013 but still seems to apply in 2021. Ruby, my main programming language, fairs pretty well in most of the test cases put forth, but the issues are well worth being aware of.
…you read with exasperation or amusement the multiple errors in a story, and then turn the page to national or international affairs, and read as if the rest of the newspaper was somehow more accurate about Palestine than the baloney you just read. You turn the page, and forget what you know.” - Michael Crichton (1942-2008)
Another tweet by Nate Hopkins caught my eye too. He asked about RSpec’s
Why does RSpec support “let” syntax? Is it simply to squash parts of a before hook into a single line or is there some practical utility? I currently see it as only serving to obfuscate things.
I have come to strongly agree with Nate’s assertion that they only serve to obfuscate things. I’ve written many tests using the
letsyntax myself and everything is great at the beginning. The problem comes as the test file grows and you can no longer see the whole test in one go. You’ll find that a
letat the top of the file is affecting a test on line 1000, and tracking all over the file to reason about the test becomes very tiresome.
These days I much prefer a longer, simpler style of tests where all dependencies are shown up front and center with nothing hidden. Tests which provide design feedback - if you have a lot of dependencies to setup a test, you have a complicated object. This information is often hidden with
You may experience push back from team members writing tests in this style. People will say they are verbose - they are. And not very DRY - they’re not. But in my view, they they tend to make the whole test more understandable, and are cut and pasteable when a base for new tests is required. They lead to more maintainable tests in my experience.