I’ve been enjoying my reading of the Refactoring Ruby Edition book. I’ve also found some new learning resources that have been very exciting to participate in. I plan on resuming my reading of the Refactoring Ruby book, but today I wanted to share something that I’ve just started playing with.
One of my pairing friends I met during my time learning at AirPair, Russell Baker, pointed me to Pat Maddox’s RubySteps. I’ve only been a member for a week or so, but the lessons over there have been extremely informative, a perfect mixture of challenge and size, not to mention they’ve been a blast to walk through!
One of the other exercises I’ve just started doing to learn Ruby better is to walk through the Core API with testing. In the past, I’ve used Rspec nearly exclusively for TDD, except during my walk-thru of Ruby Koans. But this time around, I thought it would be neat to try out a new testing framework.
Taken from the seattlerb/minitest Github page, here is an excerpt that I think explains minitest well:
minitest provides a complete suite of testing facilities supporting
TDD, BDD, mocking, and benchmarking.
And another excerpt a few paragraphs below is the reason that impulsed me to minitest a try:
minitest doesn’t reinvent anything that ruby already provides, like:
classes, modules, inheritance, methods. This means you only have to
learn ruby to use minitest and all of your regular OO practices like
extract-method refactorings still apply.
Minitest has been included in the Ruby standard library since 1.9, and is a modern, lightweight replacement for Ruby 1.8’s Test::Unit framework.
Here is a short list of features minitest provides:
- minitest/autorun – the easy & explicit way to run all your tests
- minitest/unit – a very fast, simple & clean test system
- minitest/spec – a very fast, simple & clean spec system
- minitest/mock – a simple & clean mock/stub system
- minitest/benchmark – a cool way to assert your algorithm’s performance
- minitest/pride – show your pride in testing! (adds color to test outputs)
Now that we’re starting to get the lay of the land, lets take minitest out for a spin!
Minitest in Action
So yeah, I’ve started out with Ruby’s Array class. But before we get into that, let me show you how I set up my environment.
Heres a layout of the steps I took:
Create the library testing directory &
cdinto the new directory
Add sub folders as necessary, I started with Ruby’s Array Class, and then create your test file.
Now that we have that squared away, we can type
cd ..(two periods) in order to step up our file tree all the way to root, which in this example is called
In your text editor of choice (mine is currently Sublime Text 2), open your newly created
Gemfileand add the following.
Next, we install our gems
And lastly we can run minitest to make sure we’re connected properly
In my next post, I’ll be covering minitest in greater detail. How to pretty up our test output, how write and run test, etc… I also have some pretty neat resources I’ve found on google, like an assertion cheat sheet, and a surprise that reminds me of the shoulda and shoulda-matchers gem I use when testing with Rspec.
Here are a couple of resources for today that I found while digging around.
- Simple Testing in Ruby Using Minitest (19 minute youtube video)
- If you’re wanting to learn Ruby, TDD, Rails, and OOP in a fun and consistent way, Check out RubySteps
- A sneak peak at some things I’ll be covering in future posts on minitest (by: The Ruby Learning Blog and Steve Klabnik)