Why do I prefer MiniTest than RSpec

2015, Oct 21    

I’m a lucky guy - I usually work alone so nobody is telling me what to use and how to do it. I have the freedom of choice from the very beginning of the project. Usually. There’s only one thing that remains the same: the need for testing. I won’t be writing here why you should test your code because you already know it. Instead of that, I’ll briefly wrap up all my thoughts about MiniTest and RSpec. Before you start further reading I think it’s worth to quote Tenderlove’s conclusion on that:

"A professional developer should be able to work in either one of these because they essentially do the same thing: test your code."

I started to use Ruby and Rails a few years ago. The choice of testing gems and frameworks was really poor, everybody was fascinated about RSpec so I followed the trend and started writing my first tests using it. I didn’t even think that there’s something else, I just used RSpec. One day I’ve realized that I’m actually tired of all the RSpec DSL things. I’ve decided to try something else. There was no other option - I picked up MiniTest and… tadaaaam! Now I use MiniTest for all my Ruby projects. Why?

Top 3 advantages of MiniTest

MiniTest is just Ruby!

Yes! That is the main reason why I much more prefer MiniTest. It is much easier to use and even extend MiniTest as it’s just Ruby.There’s no need to learn any DSL. As I know Ruby I see what’s going on in the code, so more English-like declarations are not very helpful for me. Moreover, the RSpec tests are quite often much more complex and harder to understand.

It’s faster and lighter

RSpec has its dependencies like most of the Ruby gems, so it’s quite natural it just has to be slower. Maybe it’s hard to notice if you have only a few tests, but the more tests you have, the faster MiniTest is when you compare it with RSpec.

It’s bundled with Ruby

In the basic version, it’s just a Ruby module. You don’t need to install anything, you have your MiniTest installed with Ruby. You can install the MiniTest gem and all the other MiniTest derivatives, but to start using MiniTest you only need Ruby to be installed.

Sum up

As you can see my point of view on the MiniTest vs RSpec battle is quite clear. That obviously does not mean that RSpec is not a good option for Ruby testing, but I really much more prefer MiniTest.

And there is one more thing that I just need to mention here: MiniTest is tested with MiniTest! FTW! :-)

There is a lot of online materials about that. If you want to dig in deeper and get some more details I’ve chosen some articles I recommend you as a further reading:

  1. https://blog.engineyard.com/2014/seven-reasons-i-love-minitest”>https://blog.engineyard.com/2014/seven-reasons-i-love-minitest
  2. https://speakerdeck.com/ahawkins/bow-before-minitest”>https://speakerdeck.com/ahawkins/bow-before-minitest
  3. http://tenderlovemaking.com/2015/01/23/my-experience-with-minitest-and-rspec.html”>http://tenderlovemaking.com/2015/01/23/my-experience-with-minitest-and-rspec.html