A Testers Guide To RailsConf 2009

Testing was a popular topic at RailsConf this year, with a lot of sessions on various testing tools and a lot of prominent interest in testing process.

Here’s a quick look at the sessions that were interesting from a testing perspective. And also my session, which was from a testing perspective as well. Where applicable, links go to the presentation slides.

Testing, Design, and Refactoring, Jim Weirich and Joe O’Brien.

This was a tutorial session that I caught a tiny piece of. Weirich has a well-deserved reputation for running great training sessions, and this one seemed effective.

Don’t Mock Yourself Out, David Chelimsky

Saw this one. Chelimsky, who is the lead developer of RSpec, gave a nice overview of how to use mock objects, and even better, how to use them well.

He also introduced a couple of new tools. One was stub_chain, a new feature of the RSpec mock framework. The use case here is when you had to create a series of mock objects to cover a long chain of objects. In the old way, you needed to create a bunch of intermediate objects that you didn’t much care about:

  member = stub_model(User)
  friends = stub()
  friend = stub_model(User)

The new way, with stub_chain, is much more direct.

  friend = stub_model(User)
  User.stub_chain(:find, :friends, :favorite).and_return(friend)

In both cases User.find(1).friends.favorite will return friend.

Another new tool is Stubble, an API for easily mocking ActiveRecord objects. Right now it works with RSpec, but Chelimsky hopes that it will work with other frameworks soon. Within a stubbing block, the ActiveRecord class specified has find, save, and the like stubbed out so that it will not need to contact the database.

  stubbing(Registration) do
    post 'create'
    response.should redirect_to(registrations_path)

These tools, along with some other comments at the conference, lead me to think I need to give RSpec another serious try.

In Praise of Non-Fixtured Data, Kevin Barnes

Missed this one.

JavaScript Testing In Rails: Fast, Headless, In-Browser. Pick Any Three.
Larry Karnowski, Jason Rudolph

Only caught the tail end of this one. The tool being discussed here is Blue Ridge, which seems to be a composite tool making it easy to use some JavaScript test frameworks together.

Below and Beneath TDD: Test Last Development and Other Real-World Test Patterns Presentation, by Me

This was my talk. It was pretty process heavy and code-light. I’m going to try to work the substance of it into the book sometime over the next few weeks. Anyway, people came, they said nice things, and overall I was pleased with how it went.

Quality Code With Cucumber, Aslak Hellesøy

I didn’t make it to this session, although I heard very good things about it from other attendees (though I did get to briefly meet Aslak during the conference). Cucumber was all over RailsConf, mentioned in several different sessions, it clearly has a lot of momentum as a useful tool.

Using metric_fu to make your Rails Code Better, Jake Scruggs

I only realized when looking at the slides that this was a descendent of the talk that Scruggs gave at last years WindyCityRails conference. It’s a good talk, and metric_fu is a useful tool.

Working Effectively With Legacy Rails Code, Pat Maddox, BJ Clark

Very well done session that had some suggestions that went beyond what I currently have in the book, although they started with similar advice. A couple of their suggestions include:

  • Silo code by making it a webservice.
  • Refactor back to what Rails already does.
  • Make everything a framework. Write micro frameworks.
  • Use “nice” metaprogramming
  • Use existing frameworks, then maintenance is somebody else’s problem.
  • Look for ways to modify code behavior without changing API, like new parameters with default values
  • Use selenium recordings as a last-ditch way of testing.

Robert Martin

This link is to the video of the talk. This talk is included in the testing roundup because of Martin’s full-throated support of test-driven development as a professional duty. I very much enjoyed this talk, though I’ll freely admit that it was very much a preaching to the choir kind of a thing. (Not only did Martin strongly endorse TDD, but his diagnosis of what killed Smalltalk was very similar to rants I’ve been doing for years. You’ll just have to take my word for that.)

Testing BoF session

After some dancing back and forth over room assignments, I settled in with a couple of dozen other people for a discussion of testing that largely centered around the best way to get started and the best way to get unstuck. I had fun, but then I got to shoot my mouth off for an hour, so that may largely be redundant.

Webrat: Rails Acceptance Testing Evolved, Bryan Helmkamp

Solid session on Webrat that went far enough beyond beginner material that I felt that I learned some useful stuff about using Webrat in either Cucumber or Rails integration tests.

Overall, a very strong and helpful conference, even with just testing sessions counted. I’ll try and get another post up with more personal comments later this week.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.