ruby learning tdd testing minitest rgsoc


Learning Ruby With Tests

  • Intro: motivation and overview
  • : class, method, if … else and a test system
  • Part 2: predicates, variable scopes, initialize

Being both mentor and coach for the amazing HighwayToRails team working at ABSOLVENTA during the Rails Girls Summer of Code 2013, I realised for the first time how many resources there are for those willing to learn the Ruby programming language – resources in written form1, as videos and last but not least many volunteers who are willing to help.

I learned Ruby and RoR to no small degree thanks to the formidable Railscasts by Ryan Bates but it has always been something of a thorn in my side to see that testing was completely left out. While I haven't seen it myself, it was nice to hear that apparently the Rails Tutorial by Michael Hartl includes testing from its very beginning. It was during a lunch break at Soundcloud together with two other RGSoC groups, Team Spree and Rails Grrls plus their respective coaches and mentors, that I overheard the testing bits of the Hartl tutorial were secretly skipped because they seemed to difficult.

1I'm also quite excited to see the Team RailsGrrls' crowd-sourced Learner's Directory to go live!

Too much Vocabulary

I have assisted people in learning Ruby and Ruby on Rails for quite some time now. As an avid test driven developer I am very excited to show people how to test their code but I also struggle with determining the perfect time to do that.

First there's that concept of code that tests code in the first place. And then, of course, you barely understand what a class is (or at least what it looks like in Ruby) and then you're already expected to learn even more syntax to test that thing?

I used to test with Test::Unit (or its pimped-up ActiveSupport version) for many years and now that I've been using Rspec for 1.5 years, I feel that the latter is superior to the other. That's not because I differentiate much between BDD and TDD, but because I like the nesting into contexts and the more plain English approach to define test scenarios. Rspec, however, adds a lot of vocabulary to a beginner's TODO list and I don't think it's the tool of choice to start with.

A »Test-Driven Learning« Series

I have ideas for a hopefully comprehensive guide on howto not only start testing right away, but actually learn Ruby through tests (talk about high expectations now…). It will (probably) consist of three parts and will hopefully not take me weeks on end to complete.

I will keep the vocabulary as low as possible, starting with a single assertion method and slowly evolve into using minitest/spec and eventually Rspec for more sophisticated scenarios. While going test-first through an example, the reader will learn about classes and instances and basic things like String manipulation.

Ideas, comments? Please feel free to leave them below or tweet me.

comments powered by Disqus