I recently went along to a meeting of the Melbourne Ruby User Group, the first user group type of meeting I’ve been to for years. ThoughtWorks now hosts the meetings and supplies pizza and soft drinks, so I really have no excuse not to attend given my interest in Ruby and Rails. For some reason I didn’t expect to get much out of the experience, but I was wrong. Two chaps, including Mark from RedBubble gave a slick presentation of their experience at RailsConf 2007, which sounded like a blast – I gained a lot of context of the direction of the Rails community and industry from their presentation. After pizza Pete Yandell discussed using RSpec with rails to unit test controllers, and showed an interesting technique he has devised to separate the stub behaviour of faked collaborators from the assertions about stub methods were actually called.
It took me a moment to grok, but it’s a clever thought – with jmock in java the expectation e.g.
.expects("blah") is always in the same place as the outcome of the call e.g.
.will(returnValue(foo). Pete has implemented an RSpec modification that means you can create the stub behaviour of a collaborator first, call the real code under test, then assert after the fact that the calls to the collaborator were made correctly. It does make the test code a lot easier to read, although it still doesn’t quite feel right. Nifty I’ll have to have a think about that.
I guess I didn’t expect such a good technical talk at a user group like this, I hope it’s like this all the time. It was good to hear Steve Hayes piping in from the background with wise words also. I enjoyed going along to the group – I’ll try to go along again next month. Especially as we did go for beers afterwards…
Correction: the two chaps presenting on railsconf were not both from redbubble.Â Sorry Marcus, thanks Steve.