I am one of the RSpec developers and have never used minitest, so consider my biases when reading this answer.
Overall, RSpec's power comes from the fact that it redefines so many testing concepts into first-class objects. Where Test :: Unit and Minitest use simple methods to create statements, RSpec uses first-class mapping objects that support negation, self-description, and more. RSpec examples are first-class objects that support rich metadata; minitest / spec compiles it blocks simple methods that do not support the same rich metadata. RSpec supports specifying general behavior using a first-class construct (shared example groups) that accepts arguments; w / minitest you can use inheritance or mixin to reuse tests , but it does not have the same first-class support. RSpec has an explicit formatting API (and there are many third-party developers who use it); I donβt know how minitest has the same first-class formatter API.
As someone who constantly tests and practices TDD all day, I find that the power of RSpec gives me very useful information. Many people believe that this is too much, and there is additional cognitive cost for additional abstractions.
Here are some RSpec features that I think minitest lacks:
before(:all) (note that this is a powerful RSpec custom function that is rarely used, I have used it several times over many years of using RSpec)around(:each) hooks- Common example groups
- General contexts
- Rich metadata support that can be used to control the launch of these examples, which include group group contexts, which include example group modules, etc.
- Integrated support for a wide range of mocking functions w / rspec-mocks; Minitest :: Mock is much simpler and more limited in comparison.
- RSpec has rspec-fire , which is awesome.
Benefits of using Minitest:
- It is built into the standard library, so you do not need to install anything.
- It can be used in
def test_blah or it 'blah' styles. - The code base is very small and simple. RSpec, by virtue of this older age and additional features, is more in comparison.
- Minitest loads faster than RSpec (this is about 4 code files compared to RSpec, which has many files distributed over 3 precious stones), but note that RSpec is by no means slow; in most of my projects these days, I get test feedback from RSpec in a second (and often in less than 500 ms).
All in all, it's a bit like Sinatra vs. Rails, and I think Minitest and RSpec are both great options, depending on your needs.
Last: if there are certain aspects of Minitest that you like better, but other things that you like best in RSpec, you can easily mix and match them. I wrote a blog post about this if you're interested.
Myron Marston Sep 18 '12 at 16:00 2012-09-18 16:00
source share