Ruby is a cool language. There are a lot of dynamic changes happening in the gem universe. It’s also nice that a fair number of books have been written recently (last ten years) about it. However, following along in even recent books is difficult if you don’t fix the versions of the gems they used. For example, I’ve been trying to follow along with Continuous Testing with Ruby, Rails, and JavaScript from Pragmatic, but almost every line of code has required some finagling.

First I needed to get rspec-autotest, since autotest/zentest and rspec move at different speeds. While autotest itself does work, rspec requires an added gem to glue the two together, or test discovery fails. Second, the version of simplecov generated by the jeweller tool uses one version of json, while other gems (notably the autotest binary handled by rvm and not the one handled by bundler) use a different version. Third, rspec has changed since the book was written. Core developers have moved very strongly in the direction of expectations, while earlier versions used an SUnit-esque should syntax, which is represented in the tests in the book. Basically all the tests described in the book are getting rewritten as I go to make the expect syntax uniform throughout. Additionally, the collections_matcher has been moved out of rspec into an external gem, while it was bundled in core rspec when the book was written. Fourth, the twitter api used in the first sample application has been completely revamped (you need an access token to use the api, which requires a developer key with twitter, which now requires a mobile phone on your account and an sms authentication). Additionally, the Twitter::Search class has been removed, replaced by a method, and most of the arel chaining methods like ‘:per_page’ or :from have been replaced, the call looks more like"from: #{username}", {:result_type => :recent}).take(5) instead of the listed So far (and I’m on only page 25) I’ve also needed to learn about substantial changes to the rspec-mocks api, replacing mock with double, and should_receive with allow().to receive, to squelch some other issues.

All this to get the first 2-3 test cases working. If I did not know what I was doing, either this book would be more frustrating than useful, or I perhaps would not be in the target audience. In the books defence, 2011 was a long time ago, this title is out of print, and would likely receive a facelift before it saw print again. Maybe all the cool kids will have moved to cucumber by that time.

Follow up 2017-01-07

Finished the second chapter, code is at github, might be a bit rough. Ran simplecov, it looks like there’s a method to find nearby followers that doesn’t actually do anything, which was introduced as an example of why zipcodes might be useful. Ran into issues that the text did not cover, particularly with the Mutable Singleton for current locale (one of the tests for assignment was changing the locale to UK, and breaking zip code checks). Had originally fixed this by stubbing out the assignment, but realized that the test for assignment should not do that. Needed to implement a before and after hook to save the state, I had originally just done this right in the test, before I realized I was introducing irrelevant details into the unit test.