Ruby Testing
Ruby Testing
I’ve begun a journey to pick up my old friend Ruby in my spare time. One of the first places I thought about starting was back with testing. Testing in software is something I’ve always wanted to get better at and I always thought Ruby had a great ecosystem for testing.
From the Beginning
Let’s start from the beginning. Ruby has a few different testing frameworks. looking at https://www.ruby-toolbox.com/categories/testing_frameworks?display=full&order=score we can see the top three most popular frameworks are:
- rspec
- minitest
- test-unit
rspec
Rspec describes itself as a behavior-driven development testing framework. This resonates with me as I am a big fan of testing behavior and not implementation. A lot of times in test suites you see that the tests are tied directly with the implementation of the code and when you change the implementation of the code now you need to change your test. Rspec provides a DSL that pushes you naturally towards testing behavior and not implementation details of your code.
Taking a look we see that rspec
seems to have a lot less maintenance going on in the last three
years. It seems like it has had a few new maintainers stepping up to take it over. I’m okay with
it not having many commits. It doesn’t mean it’s dead. Likely just in a decent state.
minitest
Minitest has more commits in the last three years and seems to be nearly just as popular as Rspec. I’ve used minitest before since it is the default testing framework of rails. Actually now that I think about it, it’s the only Ruby testing framework I’ve used.
I like that it’s small, easy to read, and it fits more with my mental model of testing frameworks in other languages. You also don’t need to learn a whole new testing DSL for minitest. This is why, I assume, most new projects use this by default.
test-unit
Test-unit out of the three is the least popular by far. According to it’s documentation it is a testing framework based on XUnit principals. I’ll admit I haven’t read a lot of Kent Beck’s work but I probably should.
What’s Next
I’m going to pick up rspec. I’ve never used it before and I’m excited to dig in! Again, I really like that you are testing the behavior of your software. It’s in the name. Spec. You’re testing your software according to the specification. 😄 In another blog post I’ll share my learnings and thoughts for picking up rspec.