Tuesday, February 10, 2009

MWRC speaker interview: Ben Mabey

Our next MWRC mini-interview is with Ben Mabey (@bmabey or on github). Ben is well known in the Ruby testing community. He's made a number of presentations at URUG meetings, and is going to be doing a presentation on "Outside-In Development with Cucumber" at this years MountainWest RubyConf. Come see Ben and the rest of our presenter, but register soon so we don't fill up with out you.

What experiences have sold you on testing in general?

Ben When I started doing Rails in 2005 I tried my best to TDD my models and write Rails functional tests. Having tests greatly lowered my stress level when I was deploying applications. Unfortunately my earlier test suites fell into disrepair as I became the victim of many common TDD pitfalls. It wasn’t until I was more experienced and had read a lot about the subject that it started to dawn on me that TDD was really about design. Once I realized this, there were big benefits. On my most recent project we had a really cool experience when we were asked to add new functionality to the system. What seemed like a difficult and time consuming task turned out to be quite easy and we accomplished it by writing a 50-line class that delegated to other (already existing) objects. Testing our objects in isolation and refactoring constantly yielded a very flexible and reusable design. It was neat to see how our design emerged out of the red-green-refactor cycle.

What experiences have sold you on BDD?

Ben My best experiences with BDD started when I began working outside-in with the RSpec Story Runner back in October of 2007. (Cucumber is a rewrite of that project which smoothed out the rough edges and has added some really sweet extensions to the grammar.) Recently, I sat down with a stakeholder and reviewed some concrete examples in table form using Cucumber’s Scenario Outline feature. Through the conversation we were able to clear up some misconceptions I had of how the app was expected to work. As a result, it saved me a good deal of time since the actual requirements were far less complex than my original interpretation. I then used these executable examples to drive my entire development process. I have found that BDD not only helps in writing well designed code but helps in preventing unneeded code from ever being written! My presentation will focus on the outside-in approach and how Cucumber fits into this process.

How much emphasis do you place on code coverage?

Ben I use code coverage stats as an indicator, not a dictator. Meaning, if I come into a project and find low code coverage I lose confidence in the system and in the ability the tests give me to refactor quickly. However, if an app has high coverage (even 100%) I don’t assume every part of the project is well tested. I have run across situations where RCov gives you 100% line coverage but by simply looking at the code and tests it is obvious that large paths of functionality are not being tested. I highly recommend Jason Rudolph’s series on how to fail with 100% test coverage.

What about other measures of code quality?

Ben I am a big fan of Jake Scruggs’ Metric-fu library. I like to set it up on all my projects and have it run on a CI server (I generally use CC.rb). The Metric-fu plugin is a collection of useful tools to analyze ruby code. My favorite tools included are flog (an ABC metric based tool) and Saikuro (cyclomatic complexity). I like them because they point out long or complex methods that are prime candidates for refactoring. While not a code metric tool per se, I also really like kablame which will use your SCM’s blame command to identify who is writing the tests and shame those who are not. Outside of these metric tools I also think tests are a great indication of code quality and design; if code is hard to test then the design is probably lacking.

Other than your own, what MWRC presentation are you most looking forward to?

Ben I am really amazed by the presentations MWRC has lined up this year. The past two years have been great and this year looks to be just as good, if not better. As a TDD/BDD junkie I am really excited to see Brian Marick present. I have heard great things about his presentations and I’m hoping to learn a lot. I also keep wondering what tricks James Britt has in store and can’t wait to try some of them on my own Nintendo Wii. I am of course also very excited to see Jim Weirich speak again- I always walk out of his presentations feeling like a better programmer.

Click here to Tweet this article


Jake Scruggs said...

Always good to hear about people using and liking metric_fu. Uh, but the link you provided is incorrect. The project home page is http://metric-fu.rubyforge.org/ and it's github home is:

gnupate said...

Hi Jake, thanks for the updates