start | previous | next | finish
I’m starting to take a serious look at Ruby, and like many people who are new to a programming language, it’s difficult to know where to start. Sure I have the “pickaxe” book in hand and my bookmarks are overflowing with Ruby links, but where ever and however I start I would like to be able to see immediate results and I would like to prove to myself that I’m understanding the syntax.
How about testing what I already know? Well, right now I don’t know too much. However, that should make things easier since it will prevent me from wanting to take on too much at once and keeping myself focused on small obtainable goals.
Since I come from the Test Driven Development (TDD) camp, testing is pretty second nature and it is very comforting for me to keep on doing it. Perhaps the question I should be asking is: Where should one start when learning Ruby using TDD?
Since Ruby already has a unit testing framework, the first place we should look is the
Test::Unit module. Hmm.. looks like there is a
TestCase class. In the past when I developed Java applications, I’ve used JUnit extensively so this seems familiar to me. Okay, but what are we going to test first? Well, when you are writing a test you typically need to make an assertion. Right, where is that kept?
After digging around in the ruby docs online, we see that the
Test::Unit::Assertions class contains the assertions used by
Test::Unit:TestCase. Scanning down the document, the first public instance method we encountered is
assert. Well, golly gee whiz. If we were pairing with Donald Rumsfeld then he would tell us to be vigilant and go after that method because its a known-unknown.
Alright, lets start by creating an
AssertionsTest class which will test the
require 'test/unit' class AssertionsTest < Test::Unit::TestCase def test_should_do_something_with_assert # method to be revisited . . . end end
This seems to be a good breaking point. My goal is to treat this as a running example while I’m learning the finer aspects of Ruby. Hopefully readers like yourself will find this to be a useful and educational experience.