Noel Rappin Writes Here


Aug 9, 2010: I Shouda Seen This Coming

RSpec, Shoulda, WindyCityRailsNoel RappinComment

Book Status

The Shoulda chapter is draft complete, after a slight restructuring to change the emphasis of the chapter, and a lot of syntax changes. My previous version of the chapter was written before Shoulda went in the direction of RSpec compatibility and so there were a lot of syntax changes that needed to be made, particularly to the way you create Shoulda extensions, which used to be much simpler.


WindyCityRails has extended the early bird pricing through August 11, because of the addition of Ryan Singer from 37signals to the schedule. Those of you who are obsessively following the schedule with an eye on how it affects me -- which, I suppose, is pretty much just me -- now see that my tutorial session no longer overlaps with Yehuda Katz, but does overlap with Ryan Singer.

My tutorial is called "Testing in a Legacy Environment", and will talk about adding TDD/BDD to an existing code base, with a focus on practical ideas and working with an actual fake legacy code base. I think it'll be a lot of fun, and I understand that tickets are still available. So register.


One of the issues that made the Shoulda chapter require some rework is that the Shoulda team has changed how they think of Shoulda. I'm paraphrasing here, but I think it's gone from "RSpec alternative for use with Test::Unit" to "Tool for single-assertion shoulda-style testing in either library. But especially in RSpec."

On the one hand, I really like having Shoulda syntax available in RSpec. It makes RSpec a lot more interesting to me, and I like the way single-assertion style looks in RSpec. That said, and also knowing that the Should team owes me nothing and absolutely needs to write the tool they want, I do think I'll miss having Shoulda as a full alternative to RSpec.

Let me back up. When I first started using Rails, I used Test::Unit because it was most similar to the tools I had been using (JUint, PyUnit, SUnit). As I got integrated into the Rails community, I became aware of RSpec, and thought it looked cool.

My first experience or two with RSpec went badly. RSpec, at that time, was very heavily into a mockist style of testing (or at least that's how it seemed to me), and for whatever reason I really struggled with making mockist testing work for me in any kind of reasonable flow.

If I remember correctly, Shoulda came out while I was in the middle of my first major Rails project as a consultant. I liked the single-assertion style immediately, and also liked the ability to get some RSpec flexibility without having to make the commitment to RSpec. Shoulda was much easier to add to an existing project.

Shoulda got popular quickly, I remember a talk at RailsConf '08 comparing all the testing tools and concluding that Shoulda's big advantage over RSpec was that it was much easier to extend. Shortly after that, as I got into a position where people would ask me questions about testing, "which framework should I use" was a popular first question.

When I started writing the Lulu book, it made perfect sense to have the book not focus on RSpec, since the non-RSpec tools at the time had very close parity to the RSpec feature set. I believed (still do) that it makes sense for a new user to start with the baseline Test::Unit features because they are simpler and because most Rails programmers know them. The fact that there was also already an RSpec book in development, I admit, was also a consideration.

A couple of interrelated things happened over time:

The Test::Unit ecosystem, including Shoulda, Jeremy McAnally's context, and other add-ons like Zebra basically stopped being worked on.

Cucumber became very popular, and integrates with RSpec better than Test::Unit, making the RSpec ecosystem stronger.

I had my first really good experience with RSpec, and I'm now much more comfortable with it than I was. There are a lot of RSpec features I didn't know about before that I love now.

As a result, or at least at the same time, I don't get asked the question about which framework to use any more.

In some ways this is too bad, some people genuinely don't like RSpec syntax, and I think that if somebody was to fork the pre-RSpec version of Shoulda and maintain it, that would still be a viable tool for some members of the community. At the same time, it's not like I'm jumping up and down to be that maintainer, so take that with a grain of salt.

Anyway, this leaves me in a weird place, with a Rails test book that covers RSpec, but isn't really about RSpec. I think that a lot of the advice and tool coverage in the book is applicable to RSpec or Test::Unit users, but I worry that Rails users who are already in the RSpec camp will assume that my book has nothing for them. (Note: I think it does. But then I would, wouldn't I?) But this isn't the only decision I made in the book that looks different a year or so later. (For example, I picked Machinist over factory_girl as factory tool to emphasize. I might have to redo that one also...)

I'm not sure what my point is by now. I like RSpec, and I like Shoulda, and I even like them together. But I also liked them apart. And what makes writing in this community both so much fun and so agonizing is that everything changes all the time.

June 30, 2010: The Triumphant Return of the Monster Link Post

Cucumber, Don Norman, Rails 3, Ruby, Shoulda, Steve Martin, UXD, iPhone, rvm, writingNoel RappinComment

The end of the repair story

At the end, a very positive experience with Apple support. The repair was free, done when they said it would be done, and all told, I spent less than fifteen minutes in the store between both halves of the visit. Plus, they replaced the top part of my pre-unibody MacBook, which was worn down and discolored from my gunky hands, almost as though they didn't want an ugly Mac in the field.

Book Status

With the laptop back, I'm back to work, last night going back over the Style chapter. I think now the plan is to do a slightly smaller next beta that would get out next week, just the Coverage and Style chapters, with the next batch, probably the Legacy and redo of the startup example coming shortly on its heels.

Also, the book has somewhat quietly shown up on Amazon and, I presume, other online outlets.

Of course, the beta is still available at PragProg.


Many, many links, as I catch up on an entire week's worth.

Thoughtbot announces that factory_girl is now split into a separate Rails 3 gem, in much the same way that Cucumber and RSpec are.

Also in Thoughtbot-land, the should_change command has been deprecated from Shoulda.

Jeremy McAnnaly announces the 2010 Ruby Hoedown, after some rescheduling due to the Nashville flooding. Again, it's the low, low, price of free. I'm hoping to break my 0-for-2010 streak on conference proposals with my submission.

Everyday Rails has a good post about getting Rails 3 and RVM working together.

I haven't watched this video yet, but a little Don Norman is a good thing, right? (via Joel Spolsky)

Test Inline is a Ruby library from Eric Anderson to put tests in the Ruby source file. Eric freely admits that this is an experiment, which is good because my experience with this kind of tool (Python doctests) is that it gets messy pretty quickly.

Ever think that Lemmings would make a great iPhone game? Me too. Also, the people who have the rights to the code. Coming soon.

I love Steve Martin. He's posted the rider for his tours. A sample: "BUFFET ... Six-packs of any canned beverage for Steve to compare his abs to."

I've been waiting for this: Lifehacker posts some Handbrake presets for iPad and iPhone 4. Seem decent, but a bigger file size than what I had been doing.

Please don't do this. It's a bad idea and will make your code harder for other Ruby developers to maintain.

Two from David Chelimsky: Having a topic branch when contributing to git projects, and a change in how views are handled in controller tests in RSpec 2.

I really need to watch this presentation from RailsConf on Beautiful Markup by John Athayde.

Speaking of RailsConf, here's a retrospective from John Trupiano of the BohConf "unconference" that happened alongside.

Dan Ingalls was one of the people behind Smalltalk 80, here's an interview with him.

Over at Teach Me To Code, a screencast about setting up a Rails project and writing the first Cucumber feature.

Still in Cucumber, Michael Orr shows how you can use an instance variable to track objects in a Cucumber test. I do this a lot, myself, although I'm not completely convinced that you get a cleaner test suite at the end.

Rands has a great post about his writing process. I love that everybody does this a little differently, although calling what I do a "process" is probably a little much.

Paolo Perrota, author of Metaprogramming Ruby, has a nice note about how great the Ruby community is.

UxMyths seems like a useful site to browse.

Speaking about great writing, I loved, loved the opening of this article by Adam Keys about why he always comes back to TextMate. Also some good comments. I hadn't thought of the issue exactly this way, but it makes perfect sense.

The Time of Day gem lets you treat ActiveRecord time columns without their date information for certain kinds of comparisons.


I think I mentioned that I did a talk at Refresh Chicago last week. It was fun, but we think turnout was down due to the tornado warning over Chicago that night -- it's possible the sirens acted as a deterrent. Well, video of that is not up, but here's a video of the storm that night, featuring lightning striking three Chicago skyscrapers at the same time.

June 16, 2010: What Shoulda We Do?

Agile, Git, PDF, RSpec, Relevance, ShouldaNoel RappinComment

Top Story

Thoughtbot talks about their plans for Shoulda moving forward. The big takeaway is that, while the context library will be separated out for use in Test::Unit, both Shoulda style and Shoulda effort will be focused on RSpec integration.

I have some complicated thoughts about this one. I'm thrilled that Shoulda is being maintained -- it's a tool I've used a lot, and I was starting to get worried. And they should move their open source tool in any direction they want. But, of course, I can't help thinking about how this affects me, and having Shoulda be primarily a complement to, rather than an alternative to, RSpec has an interesting effect on the book I'm in the middle of writing.

It's so funny how these things change. It's been about eighteen months since I started writing what would become Rails Test Prescriptions. At the time, I was not a big fan of RSpec, largely because I didn't like the heavily mocked style that seemed to go along with it. With the emergence of Shoulda and the factory tools, Test::Unit had gained basic functional parity with RSpec. It also seemed like Shoulda/Test::Unit was really starting to gain community mindshare.

So, I wrote the book intending it to be a basically tool-agnostic guide to Rails testing, but with most of the examples in Test::Unit on the grounds that a) Test::Unit is part of the core Ruby and Rails stack, so it's always around, b) it's what the core team uses, c) I personally was using Test::Unit, and d) RSpec already had a book, so it seemed prudent for many reasons to find my own space. Those of you who bought the Lulu version will remember that it has longish chapters on Shoulda and RSpec, treating them more-or-less equally as alternative mature test frameworks.

In the interim, tools have ebbed and flowed. Cucumber came out, with very strong RSpec support (especially at first), starting a bit of a trend of new tools supporting RSpec over Test::Unit. The single-assertion style from Shoulda seemed to gain some traction among RSpec users. I started actually using RSpec more, and liking it.

At the same time, some things haven't changed. I'd still like the book to be framework agnostic to the extent possible. Test::Unit is still the Rails default, and is probably still easier for a somebody new to testing to understand. But I think I have some re-writing in my future.

Oh yeah, other links

Martin Fowler on what makes a good team room for an agile project.

Speaking of RSpec 2, here's one of what I hope will be many posts from David Chelimsky about a new RSpec feature, metadata and filtering.

Gitbox is a new Max OS X interface for Git. Currently seems less full featured than the GitX fork that I use, but it does seem like a nice start.

Relevance announces PDFKit, a new library for PDF generation, along the lines of PrinceXML. I don't see this as a replacement for Prawn at all, though. There will always be cases where direct generation makes more sense. And there will always be cases where conversion makes sense. I think doing a book with Prawn would have been challenging, for example.

Finally, here's a simple little survey of the Ruby community. I note parenthetically that RSpec has 42% of the vote for Preferred Testing Framework, with Shoulda and Test::Unit having a combined 31%.

June 14, 2010, Practice makes less imperfect

Authlogic, Coulton, Mongrel, Rails 3, Shoulda, Steve Jobs, Yehuda, testingNoel Rappin1 Comment
Still catching up on links. The PeepOpen review has morphed into a larger IDE/TextMate piece, hoping to finish that today.

Book Status

Still working on the renovated Style chapter, which will probably combine the chapters that are in the current Table of Contents as "Testing Style and Structure", "Fix Slow Tests", "Rcov", and "Help! My Test Is Failing". The chapter on Legacy testing will remain a separate chapter -- I get asked about how to test legacy projects all the time.

What happens at that point kind of depends where we are on page count -- there are two chapters left that are basically unwritten (Selenium, performance testing), and two chapters that are written but need to be brought up to date (Shoulda, RSpec). Probably more information on this line later this week.

Today In Links

Liked this article from Naresh Jain about deliberately practicing TDD on sample problems to get better. Not sure if I've mentioned it here, but Project Euler is a great source of sample problems if you are mathematically inclined.

I suppose it was inevitable that somebody would write about Steve Jobs' presentation style in the wake of the network issues during the iPhone keynote last week. Still, good advice, even if they handwave over the most useful helpful bit -- "an adoring crowd".

Yehuda posted a short gist about implementing the "acts_as" pattern more simply then is usually done.

Thoughtbot posted a list of the Rails 3 compatibility status of all their open projects. Yay! Most relevant for my immediate purposes, Shoulda has a new release with Rails 3 support and "some dramatic changes". Though I couldn't quite see from the history what they meant. More details coming.

In other Rails 3 news, Jhimy Villar has a workaround for a Rails 3 issue affecting Authlogic. I'm seriously considering moving the Rails Test Prescription examples to Devise on the grounds that a) it's already Rails 3 compatible, b) it seems to have fewer setup steps and c) it seems to stay out of the way a bit more, which is a big plus for my purpose.

Did not mention this last week, but RubyConf X will be Nov 11 - 13 in New Orleans. Never made it to a RubyConf.

Zed Shaw has announced the Mongrel2 project, which is a complete redesign of Mongrel. Not much there yet, but watch this space.


In an interview with Think Geek (via GeekDad), Jonathan Coulton says that the new album he's been teasing for a bit will be produced by John Flansburgh of They Might Be Giants. That should be fun.