Search

I Have Books

Master Space and Time With JavaScript


Download Book 1 For Free


Or…


Buy the rest of the book


Rails Test Prescriptions

B&N Affiliate Link
Pragmatic Link

On The Blog

Blog Index
The journal that this archive was targeting has been deleted. Please update your configuration.
Navigation

Rails Test Prescriptions Blog

Tuesday
Aug312010

August 31, 2010: Bundled Mockingjays

Book Status



Editing the RSpec chapter, which I expect to be done today, it's all done except for a couple of hard questions from the editor which last-night me decided to leave for this-morning me, so that last-night me could finish Mockingjay. Thanks, last-night me!

A Bundler Question



I'm not sure whether this is a feature-request or an I-don't know what I'm doing request.

I've been using Bundler with a Rails 2.3.8 project, and it's been working just fine for the most part, I like it. There's one issue. The project also involves active development on a gem (so that business logic classes can be shared among multiple projects), and I'm not sure how to handle the case in Bundler.

The gem is a separate git repo. In development, the gem is specified in Bundler as a path, so that a developer can work on both without having to push the gem back to the central repo. In staging, though, the gem is specified via git based on the staging branch, and in production it's specified via git based on the master branch.

What I would like to do is specify the same gem as having different sources in different groups, something like


group :production do
"common_gem", :git => "git_repo"
end
group :development do
"common_gem", :path => "dev path"
end


But bundler won't let me do that because all it sees is the duplicate definition.

Has anybody had a similar issue? Right now, we're resolving this via checkin scripts that ensure that various branches have the right gemfile when deployed. But it's an awkward solution.

Mockingjay



Okay, I did finish it. I'm mostly amazed at how the Hunger Games books somehow became this year's YA Book That It's Okay For Grownup's To Read. (It's even got a multi-grownup book discussion on Slate). Trying to decide how I feel about the book, and this may not be the place to go on at length. Still, recommended -- even with some flaws, the series is energetic and interesting.
Monday
Aug302010

Aug 30, 2010: Rails 3 has landed

Top Story



As you probably know, both Rails 3 and Bundler went final over the weekend. The Rails 3 release notes are up, as well as extensive coverage on the Rails Guides page. I'll also mention Jeremy McAnally's Rails 3 Upgrade handbookhttp, and Gregg Pollack's list of great Rails 3 documentation sources. And, just for the hell of it, here's the post I wrote back when Rails 3 was first announced. Somehow, this is not the first Google result for the phrase "Merby Overlords"

In other news



I do mean to write about Obtiva's Master Class with Alistair Cockburn, but that's going to take way more concentration than I can muster this morning. For the moment, it's enough to say that it was fun, interesting, and enlightening.

In honor, this link that Alistair tweeted over the weekend, the Half-Arsed Agile Manifesto. Anybody who doesn't recognize themselves in that a little bit has never actually tried Agile.

Link Out



By the way, I loved doing the post based on search engine entries into the site... you'll see that again, as it was relatively easy, kind of funny, and marginally useful, and that's pretty much what I aspire to.

If you're into programming abstractions and/or you want to learn about Lisp, Magnus Holm has an introduction to S-Expressions for Rubyists.

And if you are into crazy Ruby metaprogramming, Lance Pollard has a long look at instance_eval. It's nice to see a metaprogramming example that's actually motivated from a use case.

Highly prolific conference blogger Jake Scruggs was at RubyKaigi this week, here's day one of his report. Day two. Day three.
Friday
Aug272010

Aug 27, 2010: Seek and You Shall Find

I always feel a little bad for the people who come to this site via search. There aren't very many of them, mind you, but it always feels like they are destined to be disappointed if they are coming here to actually get information.

In that sprit, I'm going to respond to some of the search terms that WordPress says have brought people to this site in the last 48 hours. Better late then never, right?

Is there anything better than Rubymine


how to install plugin with rubymine



Funny you should ask because I've been voluntarily using RubyMine over TextMate on my current project (the Cucumber support sealed the deal). It's not perfect, and it's not as good a pure editor as TextMate, let alone Vim. But I come to form the idea that the things that RubyMine is good at -- mostly project navigation, and easy running of tests -- are things I do all the time. The things that Vim or TextMate are better at -- helping me put text on the page more quickly -- well, it's not like I don't type all the time, but the advanced features of those editors are things I need less frequently. So RubyMine works best for me right now, despite some flaws that still remain.

As for plugins, I think you need to start at the preference screen.

Ackmate no results



Have you tried adding the file type you are interested in to the options field or an .ackrc file, a la http://wiki.github.com/protocool/AckMate/

Moving from authlogic to devise



Recommended. Well, starting a new project with devise. I'm not sure I'd mess with a working project.

Scrivener Dropbox Support



As far as I can tell, you're out of luck for a simple solution until Scrivener 2.0 comes out, at least if you want to be able to edit the files on Dropbox outside of Scrivener.

Rails 3 Html5



Yes.

Jasmine Rails


rspc testing javascript


jasmine docs testing


jasmine rails how to



Seems like there's some interest here. Mostly I just wish everything would sit still for a few months so I could finish the book. But what with Relevance saying they aren't supporting Blue Ridge in favor of Jasmine, I'm pretty much forced to try to redo the chapter in Jasmine. Which looks nice, but has not quite progressed to the documentation writing phase, as far as I can tell. Still, I expect this to be Beta 8 of the book, sometime in early September.

Jruby auth authlogic



Hmm... never tried it, but I think it'll work

capybara csv test



Not sure you need capybara to test CSV output, but this question actually might have been answered by a post on this blog. Hurray.

how to get bullet points in pages ipad



Press the "i" button in the toolbar to get the inspector, then select list from the nav bar in the inspector window.

In a related story, Apple snuck in an iWork update yesterday that adds output to ePub to Mac Pages suitable for the iBooks store, along with a document that can serve as a template to make things look right -- the ePub support looks for particular paragraph styles. Nice to see that, especially nice to see that without having to pay for an upgrade.

rspec testing css



I think in an RSpec view test, you're expected to use the Webrat have_selector matcher these days.

rails text editor ipad



Haven't found anything I like specifically for coding yet, but Droptext is okay for general text. Still looking for an editor with programmer style tools that works with Dropbox.

chronic rails 3



As far as I know, they work together fine.

rails testing


rails unit shoulda



Hey, I have a book you might be interested in...
Thursday
Aug262010

August 26, 2010: Some New Stuff

Book Status



RSpec chapter draft handed in to edit. It's going to need a better conclusion. A lot changed in this one, relative to the Lulu version -- this is probably the chapter most affected by my own personal experience since it's original version.

Links



Haven't done a link set in a while, this is going to be kind of random.

Still seats available for both WindyCityRails in general, and for my tutorial in specific. But the sponsor list has filled up.

Motorola bought 280 North, best known for their Cappuccino JavaScript framework, and the 280 Slides application. Apparently, Motorola plans to use them to make web apps aimed at Android devices. Should be an interesting culture clash.

I've been looking through the Rails 3 unobtrusive JavaScript stuff trying to figure out new practices. The Trevor Turk blog has a code snippet for setting up a form that submits when a checkbox is clicked. Like it. Love to see more examples like this, it really shows how clean the Rails 3 structures will be.

Ever wish the Ruby Date and DateTime classes were faster? Course you have. Here's home_run, a C implementation of the Date and DateTime classes that claims a 20 - 200 time speedup. The Readme page shows how to use the home_run classes instead of the standard ones, if you are feeling adventurous.

I love stories of tracking down obscure bugs, and Yehuda Katz has a great one about bundler, rvm, and various shell interactions. Debugging is maybe the important skill, so watch an expert's process at work.

Speaking of rvm and it's awesomeness, here's a quick guide to putting rvm, bundler, and passenger together on a Rails deploy.

Here's a little test snippet to solve the problem of how to test an abstract controller by adding a small controller in the test page and creating a route for it.

Tuesday
Aug242010

August 24, 2010: Um.. Hi?

It's very easy to let this blog habit slip through your fingers. You go from, "put something up every weekday", to "nobody reads this on Friday", to "I'm tired this mornng", to "wow, I haven't posted in a week, and nobody noticed, why post today". Anyway, here's a post.

Book Status



Beta 6 came out last week. I'm now going through the RSpec chapter, which is taking longer than I thought. It's not just because of the changes between RSpec 1 and RSpec 2, though tracking down those changes has been part of it. It's also that it's been about 18 months since I wrote the Lulu version of the chapter. In that time, I've used RSpec a lot, and used it differently than I had before, so a lot of the tone and conclusions of the chapter need to change. Anyway, if I get lucky and there's a strong tailwind, the draft will be done today.

Updates



I assume that everybody reading this knows that since the last time I posted, new versions of Ruby (1.9.2 final), Bundler (1.0rc6) and Rails (3.0rc2) are all out the door. I really wish I had some time to play with Ruby 1.9.2. I think it's probably not appropriate to have the fake legacy app for my WindyCityRails tutorial (tickets still available...) be in Rails and Ruby 1.9.2. Probably not a lot of legacy Rails 3 apps yet.

Other Book Recommendations



It's been a while since I recommended random books here, so I'm gonna.

Packing for Mars, by Mary Roach.



Roach is nearly unique, she writes science books on odd corners of the world with precision and wit, kind of a cross between Malcolm Gladwell and Dave Barry.

This book is about space travel, particularly the various research on the mundane details of how the human body and mind live in the wildly unnatural environment of space. Chapters include what happens to astronauts who can't exercise, or can't bathe for weeks, or whether free-fall zero-g has long-term effects. Oh, and the engineering achievement of space toilets.

Love this book. Funny, not shy about it's subject matter, but not juvenile. As with all Roach's books, she's unfaillingly respectful toward what might otherwise seem like crazy scientific pursuits. And you'll never look at a group of astronauts the same way again.

The Fuller Memorandum, by Charles Stross



Programmers who are SF geeks who have not read Stross' Laundry books are advised to start. Now. (Hint, if you are a person who would laugh at a reference to Knuth's lost fourth book, covering computational demonology, your in the target group) It's a series where computer programs can be used to summon Lovecraftian horror monsters from the etherial depths, and the civil service that protects us. So it's a crazy mix of horror, spy novel, mundane office politics, and programming textbook.

Stross knows the coding well enough to make the book geek-convincing. Or as geek-convincing as you can get when talking about iPhone apps that act as magical wards or summon demons. So this is your typical "IT-guy needs to save the world from demons" book.

Wednesday
Aug182010

Elements, and other iPad Text Editor Stuff

I have something like eight different apps on my iPad which are text editors or note takers of one form or another. Plus I know of at least one more that I'm waiting for.

It's possible I have a problem.

I really want to be able to use my iPad as a writing tool -- the best apps are super responsive, and I like the ergonomics of using it with the Bluetooth keyboard. Making the iPad a useful writing or editing tool makes it much more useful for me.

Which brings me to Elements, the latest in my string of writing apps. (The name comes from Strunk & White's Elements of Style). Elements is a text editor that backs to your Dropbox account, in many ways similar to DropText.

There are a couple of differences:


  • Elements does not expose your entire Dropbox, instead it maintains its own folder and synchronizes it. This is a big DropText advantage, since one of my big use cases involves using files that are already stored elsewhere in my Dropbox.

  • Elements is limited to text files. And I mean really limited. If you put a file with an extension other than .txt in the Elements folder from another machine, Elements will ignore it. Another big problem for me, since it means I can't edit book files from Elements without pre-placing them in the Elements folder and change their names before I start.



That said, I like Elements for its other features.


  • Elements supports TextExpander. Yay. All the HTML tags in this post are thankful. (Of course I'm writing this in Elements...)

  • Elements auto-syncs back to Dropbox every minute or so. Droptext, I think, requires a manual save.

  • Elements allows you to change font and font size. Double yay. (One setting for all files.) I like messing with fonts, and I normally prefer a larger size than most applications provide by default. Especially in my normal iPad typing position.

  • You can email your file out, which makes it a plausible blog tool via WordPress to email.

  • It maintains a word count overlay, which is handy.

  • It has a little scratch pad, which I think is common to all files, and doesn't seem to by synched. Still, I suppose it's kind of dandyish.

  • Subjectively, it feels more polished than Droptext (it's also more expensive). The UI is a little cleaner.



So... Elements seems to be a nice tool for my blog use case, but a lot of other uses I have require general access to Dropbox. (Though I suppose it'll depend on whatever Scrivener's Dropbox support eventually looks like). So far, though, I like it.

Still waiting for the great programmer's editor, though. Or even the one that looks good enough to try...



Monday
Aug162010

August 16, 2010: I Still Like Boring Software Development

Book Status



Beta 6 is out and available for sale here. The major addition is the new Shoulda chapter. It's also available from Amazon. Note that the ship date for the print book seems to have moved to November.

Next up is the RSpec chapter, which will probably be Beta 7 sometime in the next week to ten days. After that, most likely a new chapter on test performance / performance testing. I also need to figure out what to do with an existing short bit on Autotest that doesn't seem to fit anywhere. After that, we'll see where we are in time and length.

The Boring Software Manifesto



It was fun to see my old Boring Software Manifesto linked at the bottom of this PragMag article on Software Manifestoes. I should revisit the Boring Manifesto, I think.

Links



If you are like me, then you are paying attention to Rails 3 but haven't done any significant production projects yet. You may have seen odd references to a snowman. Sam Ruby presents a brief but clear explanation of why Frosty is now a part of Rails URLs.

One of my favorite Mac programs is Scrivener, and I wish that my writing projects lent themselves to using it more often. In this great post, Scrivener developer Keith Blount explains all the features that won't be in Scrivener 2.0. One feature that will, though, is Dropbox integration, so that a Scrivener project can be worked remotely via, say, Droptext on an iPad.

Chronic is one of my favorite Ruby gems -- it leads to a great client demo when you type "a week from next tuesday" into a calendar text box. Aaron Sumner has an overview of using Chronic and Chronic Duration for date and time parsing.

Ezra Zygmuntowicz is leaving Engine Yard after four years, and takes a blog-posts worth of time to reminsce.

Finally, Greg Moreno has been updating a Rails project to Rails 3, and documenting the process. Part 1. Part 2. Part 3.
Friday
Aug132010

Creating, Sending, and Verifying CSV files using Comma

Here's something I haven't done in a while -- a genuine code blog entry. I needed to add a simple CSV file output, here's how I did it, tests and all.

I used two gems, FasterCSV, which I assume that most of you are familiar with, and Comma, which is a nice little DSL for specifying CSV formats. (Thanks again to Jason Pearl for reminding me what the gem was called...).

My Cucumber test for the feature looked like this (details have been changed to protect the innocent...)


Background:
Given I have valid adminstrative credentials
And I have a user named "Charlie"
And I have a user named "Bravo"


Scenario: CSV Downloads
When I go to the admin user page
And I follow the link "CSV Report"
Then I should see the table data:
| Name | Assigned Number | Email |
| Charlie | 123435 | charlie@brandeis.edu |
| Bravo | 132134 | bravo@brandeis.edu |


Just one note on this is that both the assigned number (which you can imagine as an id given to to the user by some other entity, such as a social security number) and the email, are deterministic and generated by the step definition called by the background task.

The downside of this Cuke test is that it's a little more explicit than I normally like, since the numbers and the email are kind of magical here. That said, the ability to test the tabular CSV data from a Cuke table is powerful enough that this still seemed like the best way. Other opinions welcome.

The only step here that is undefined and interesting is the last one. And you might think it'd be complicated, but in fact it's super easy:


Then /^I should see the table data:$/ do |table|
actual_table = FasterCSV.parse(page.body)
table.diff!(actual_table)
end


This does some complicated things compactly. The result of the eventual controller action is the text of the CSV file, and goes in page.body (since I'm using Capybara). FasterCSV parses that back into an array of arrays, and then I used Cucumber's table compare method table#diff to compare the parsed CSV table to the table I passed in from the feature file. In theory, Cucumber provides a pretty output if the tables don't match, but in practice I find I'm currently getting an error in the formatter.

This is nice, with the minor downside that the tables need to be an exact match. If that's not feasible, then you can do more complex logic there to compare tables.

Next up was the model test, which I wrote more or less like this.


it "should produce expected csv" do
@user_1 = Factory.build(:user, :name => "Fred", :assigned_number => 1,
:email => "fred@fred.com")
@user_2 = Factory.build(:user, :name => "Barney", :assigned_number => 2,
:email => "b@b.com")
@user_1.to_comma(:admin).should == ["Fred", "1", "fred@fred.com"]
User.users_to_display.to_comma(:admin).should ==
"Name,Assigned Number,Email\nBarney,2,b@b.com\,Fred,1,fred@fred.com\n"
end


This test uses factory_girl to create two users, then uses to_comma to invoke the Comma gem, first on a single user, then on a list of users. As you can see, Comma is smart enough to return an array of data for a single object, but a CSV formatted string when given a list.

Technically, I think the last line is unnecessary, because assuming the first part of the test passes and I know that the list generating function works then I'm really just testing Comma. Of course, since I'm using Comma for the first time, testing it once seems appropriate.

It's also worth noting that I'm showing the final form of these tests, I did a little test based exploration to see what the format was going to be. So I ran the test and just outputted the result of the to_comma, then wrote the test to match the format that I saw. Obviously, in that case you need to make sure that the format is what you want it to be, not just what the code outputs.

The Comma gem makes the model code super easy.


comma(:admin) do
name
assigned_number
email
end


The comma method sets up a comma format, the optional symbol names the format relative to any other comma formats specified for the class. Within the block, the basic idea is that each expression specifies a column of the CSV file, header and all. In this case, I'm using the basic form, which uses attributes of the current instance. Although I'm not doing it here, Comma lets you specify a custom header name, and also allows you to call arbitrary methods of associated objects. I like it, it's short, easy to read, and to the point.

Comma also lets you easily use the CSV format in a controller. Here's what the controller method looks like:


def index
@users = User.users_to_display
respond_to do |format|
format.html #default
format.csv do
send_data(@users.to_comma(:admin),
:filename => "users.csv", :type => "text/csv")
end
end
end


I didn't add a controller test, on the grounds that there is no now controller logic and controller behavior is covered by the Cucumber test and the actual output is also covered by the model test (a previous controller test verifies that users_to_display is called correctly.

And that's it. Turned out to be pretty easy.
Thursday
Aug122010

August 12, 2010: Quick program note

In case I don't get to a longer post today, just a quick book status note. The Shoulda chapter is essentially done, I've cleared the errata that people found (some really good catches this time...) It will go out as Beta 6 probably on Monday, although we might get lucky and get it out sooner.
Wednesday
Aug112010

August 11, 2010: An Abundance of Options

Book Status



Shoulda chapter fixes made. The next decision is whether to push that as a beta by itself, or wait until the RSpec chapter is also done.

Also



Today is the last day to get early bird pricing for WindyCityRails.

Book Status



I did not know that Ruby 1.9 had its own coverage tool. Aaron Patterson shows how to use that tool and a little code to create useful output for coverage testing.

I'm really happy to see some discussion of what good style is for Cucumber tests. Jonas Nicklas argues in favor of what I call in the book the implicit style of testing. He closes with "A step description should never contain regexen, CSS or XPath selectors, any kind of code or data structure". I think that's got it right. I was just deciding not to add a Cucumber/Factory add-on to my project and decided not too for reasons articulated pretty well by Jonas. The goal of Cucumber is not to write as few step-definitions as possible.

Dane Harrigan discusses handling Rails exceptions from Ajax calls. It involves what may be the first actual use case of an around_filter I've ever seen.

Xavier Shay argues that database constraints make it easier for new developers to understand your code. Hmm... I tend to be not a fan of database constraints. Or more accurately, I tend to be very cognizant of the development costs of adding database constraints, so I only add them when they seem necessary. It's hard to argue, though with the idea that the code and database should not actually conflict.

The Silence is Foo blog gives an almost obsessive amount of love to the splat operator. Yay! The splat operator is one of my favorite corners of Ruby (as it was one of my favorite corners of Python). Even so, I learned a couple of new splat tricks from this article.

I'll close here with a little debate on choices in Ruby and Rails. Kevin Gisi has a satirical little number on how hard it is to be a new Ruby developer and choose among the various options for everything. Peter Cooper at Rails inside offers not a rebuttal exactly, but a slightly different take on the issue. Kevin is obviously writing tongue-in-cheek, so you can't exactly get worked up about him going overboard, and I agree with Peter's take that things could be improved with better presentation. I do think that both Ruby and Rails have gotten a bit less novice friendly (as many projects do over time as complexity gets added). I don't think it's an unsolvable problem, but we can always make it easier for new people to come on board.



Monday
Aug092010

Aug 9, 2010: I Shouda Seen This Coming

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.

Promotion



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.

Editiorializing



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.
Wednesday
Aug042010

August 4, 2010: A couple of useful things

Book Satus



Still patching the Shoulda chapter together. Realized yesterday that Machinist is in the middle of a version 2 upgrade, which, along with some factory_girl changes probably means I have some tweaking to do in that chapter.

I haven't run the buy links in a while. You can get the beta ebook and pre-order from Pragmatic and the book is also available from Amazon.

WindyCityRails



Early Bird pricing for WindyCityRails is scheduled to end today. I'm doing the PM tutorial on "Testing In A Legacy Environment". Please sign up, I'd hate to talk to myself. Also watch WindyCityRails for another speaker announcement that should be coming up very soon. There's already a great lineup, and they run a super-great conference.

Links



This is handy given what I've been doing this week. Christoph Olszowka has made a bash completion script for RVM commands. I wonder if it will work in my zsh shell.

Speaking of useful tips, on the off chance that anybody stumbles across this who doesn't read John Gruber, he has a useful OS X service for opening all the URL's in a selected text as separate Safari tabs.

Former Apple engineer Sachin Agarwal, now at Posterous, lists some things he learned about project management from his time at Apple.
Tuesday
Aug032010

August 3, 2010: The Most Efficient Cargo Cult Money Can Buy

Book Status



Spent yesterday's book time rearranging the Shoulda chapter so as to be more focused on the general ideas than the specific Shoulda interpretation. Today's job is making sure it all still flows.

Links



So I have something like a half-dozen half-finished blog posts. Until the day some of those become fully finished, here's a few links.

Simone Carletti has list of practices to follow in your Rails 2.3 app to make it more compatible for an eventual upgrade to Rails 3. I literally just used this article yesterday, building a new Rails 2.3 app with Bundler, rails_xss, and a couple of other nifty things.

Yes, that's why I tweeted yesterday about the awesomeness of RVM. It was the first time I needed to keep Rails 3 and Rails 2 on my system, so the first time I created a project specific gemset -- you can find some articles with instructions in previous link posts. Easy to create, easy to share, easy to set up everybody's development environment.

This list from Istvan Hoka of Mac OS X tools for Ruby development is a little quirky, but a good overview of what's available.

I really want to start using Passenger 3. A couple of days ago the Passenger team released another preview post with more cool features. They deliberately bury the lede, though, as they close the post with a strong hint that some of the features will be held for a premium for-pay version. More power to them, I say -- free plus paid extras sounds like a good model for them.

Following up on the gems he released a few days ago, James Golick describes his rollout tool for conditionally adding new features. It uses Redis to determine user status for the purposes of conditionally executing code.

I thought about this tweet from Yehuda Katz for a while:



Am I crazy, or is it too easy to cargo-cult crazy practices from StackOverflow, resulting in compounded problems and error reports?



I see where he's getting this, but I'm not sure that Stack Overflow is all that qualitatively different than picking up advice on the internet in general. It's just a more efficient way to cargo cult, which would make a great slogan.
Monday
Aug022010

XP or not XP, that is the question. The answer is XP.

While I'm commemorating anniversaries this summer, I just remembered another one.

Ten years ago this summer was when I first read the original Kent Beck "white book", Extreme Programming Explained, which is one of only a couple of books that completely changed the way I approach whatever it is that I do. Considering that I've spent most of the last ten years practicing, advocating for, and writing about XP and Agile development, it's not an overstatement to say that Kent's book, and the ideas about how to be a professional programmer, changed my professional life.

Here's the setup.

I spent most of the winter, spring, and early summer of 2000 working on a largish web project for a Fortune 500 company that you've definitely heard of, but which made a regular practice of scaring the hell out of any vendors who might want to ever advertise the fact of their association.

This company was large enough to have a technical conference/fair for the IT departments of its various subsidiaries. I remember attending as a vendor, and being in a presentation from the company's legal department that prominently featured the comment, "you vendors have the silly idea that your liability is limited to the size of your contract with us".

Anyway... the project was a collaboration among several subsidiaries that had never worked together before. Not only was this the largest project I had been on by far, but there were also about a half dozen customer companies that all had different ideas about how the project should run -- it wasn't unusual to have conference calls with about three dozen client representatives to about five of us. I always kind of thought that the reason our tiny web company was picked for the project was to act as an impartial referee.

Unsurprisingly, we made every mistake there was. We picked tools that were not adequate to the task, and although our application design wasn't bad, regressions were a constant feature of our staging deployments. The customer kept changing the goals of the site, not to mention tiny details, and we had no way to organize or manage the changes. We had an ongoing argument with one of the internal teams who wanted us to change our entire database schema. Our own management grabbed half the development team to completely redo the interface less than a week before the deadline.

We did deliver on time, but only after my one-and-only real death march to date, over a month of 70-80 hour weeks. (At which point the customer froze the site and didn't deploy, but only looked at it internally for two weeks. Never did learn why.)

In the wake of the initial delivery, my company did some retrospective sessions. I had heard about XP a little at that point, and was looking for some way to vocalize my feeling that the project had been a structural failure, even though we had more or less delivered on time. Which is how I came to read the book in the first place.

Unsurprisingly, XP's emphasis on sustainability, clear descriptions of priority and responsibility, testing, refactoring, and quality code resonated with me pretty strongly. It seemed like a rebuttal to every pain point we had in the project. I remember reading directly from the book at a retrospective meeting, prompting some wisecrack from a manager about my academic bookishness. Guilty, I guess.

With one thing and another, it was several years before I was in a position to impose a full Agile/XP project structure on a project. Until then, what I was able to do was test -- even in places where that wasn't part of the team's normal process. The fact that test-first seemed so helpful made the whole Agile structure seem more plausible, and when I was finally able to put an Agile project in place, I was ready to make all new mistakes.
Friday
Jul302010

July 30, 2010: I Always Thought It Was An Animal Native To The Rain Forest

Book Status



Beta 5 came out on Wednesday. Currently trying to figure out how to structure the Shoulda chapter in light of the direction that project has gone in since I wrote about it for the Lulu book.

Friday Links



One significant change in Rails 3 is that, because of the way Bundler works, the code for your gems is not part of the project. And if you are using RVM, each project might have a different gemset, and different directory to find those gems. Brian Cardarella has a simple script that will open a new tab in your terminal window and take it to the gem directory for the current project. OS X only, because it uses AppleScript. I will use this.

Mike Burns from Thoughtbot gives us a just-so story for the digital age, How grep got its name. I always thought it was the sound you make when you try and figure out how to use it, "Oh Grep!"

Derek Kastner of Brighter Planet has an interesting look at how to use more advanced features of Bundler to to manage gem dependencies when building a gem, and creating the gemspec. Definitely something I would not have figured out on my own.

Matt Aimonetti, after doing a little Ruby memory quiz/rant on Twitter last night has published a longer blog post about Ruby's object allocation. This is interesting, and makes me wonder if it would be possible to build a Ruby runtime optimized for long-running processes. Still, make it work, make it right, make it clean, only then make it fast -- it's much easier to optimize clean code.

Louis Rose has a short snippet or three on using Timecop and Chronic to manage time-based Cucumber scenarios. Read through to the updates to avoid a couple of gotchas. Chronic, by the way is one of my favorite gems to use in projects, because clients often like the demo of being able to type in "next Tuesday" in a date field.

Finally, Yehuda Katz has what is maybe the first "I switched to Vim" story that makes me actually think about switching to Vim. Seems like a useful approach and set of tips.

Wednesday
Jul282010

July 28, 2010: Mathematical Navels

Book Status



Beta 5 still in progress. Probably today. No other news to report.

And In Other News, My Navel Is Still There



It's been a little more than three months since I started doing these more-or-less daily blog posts here, which is far and away the longest I've ever sustained daily blogging.

The original idea of this was that it was going to be my daily standup for the Rails Test Prescriptions book, which would force me to do something on the book almost daily since I'd be reporting on it. Given that this was meant to be a stand-up, three months seems like a reasonable amount of time to have an agile retrospective, right? The secondary goal was as a place for potential book readers to go to learn about the book, get a sense of whether I have anything interesting to say, all that standard author stuff.

Retrospect Away


  • It's been useful to me to have this place to mention book progress, and I do think it's helped me keep momentum.

  • I started doing the link posts because I erroneously thought that a previous source of link posts had stopped. I like doing it, though I've recently been a bit more careful about only putting a link up if I have more than a couple of sentences worth of stuff to say about it. To some extent, this has led to fewer posts, which partially defeats the purpose.

  • I always wish I had more time to spend on these posts.

  • Traffic is still rather low, although it's growing somewhat slowly. I'm a strikingly bad self-marketer, but there's probably something I could do to improve traffic. (Better content!)



Okay, one link. Well, two



Kevin Kelly is keeping a list of nominations of the best magazine articles of all time. It's striking how many David Foster Wallace articles there are -- he's one of my all-time favorite non-fiction writers (ironic, since he's primarily known for fiction). You can always tell when I've been reading Wallace, because the number of footnotes and meta-commentary in my writing goes way up. If you've never read Wallace, math fans might like Everything and More, which is a (really) long essay on infinity. It's digressive, filled with meta-writing about how he's trying to explain stuff, and I think it's pretty awesome. Though I note from the Amazon reviews that a lot of people like it less than I do.

While I'm in the neighborhood, I saw a link yesterday to a book called Street Fighting Mathematics, by Sanjoy Mahajan. Haven't read it yet, but it's based on an MIT course in quick and rough math problem solving, which sure sounds like it'd be useful.


Tuesday
Jul272010

July 27, 2010: No Rails Release Shall Escape My Sight

Book Status



Beta 5 should be out today, with the legacy and the Rails 3. Next up are the Shoulda and RSpec chapters, starting with figuring out how to handle the changes in Shoulda since I last wrote the chapter.

Rails



I'm sure all of you within the interest circle of this blog already know that Rails 3.0 RC 1 was released yesterday. Part of me wants to say "finally", but that really isn't fair. Doesn't look like there are dramatic changes from Beta 4, but check out the release notes.

And another thing



So Larry Doyle, author of the Go Mutants! book that I reviewed yesterday, re-tweeted me this morning, which I suppose means he read the review. That kind of thing always surprises me more than it should, given how often I Google my own name...

Links



Okay, nobody else is going to care, but here is Ryan Reynolds from ComicCon reciting the Green Lantern Oath for a small fan during the panel discussion of the upcoming movie. Green Lantern was, somehow, my favorite character when I was a kid, and it's great to see Reynolds do the line without a hint of ironic winking.

37Signals posts some information on their production database setup. This kind of thing is incredibly useful, but for obvious reasons kind of hard to come by. So, thanks.

Thoughtbot announced the release of Flutie, which is a "not CSS framework" distributed as a Rails engine. It seems like a set of intelligent CSS defaults that can be used to make something look good by a non CSS-guru developer, but which still allows a CSS expert to use a site layout framework on top. Looks helpful.

This is a couple of months old from Takaaki Kato, but it's a nice series of TextMate tips for Rails developers. I'd add that I've always had trouble with ProjectPlus -- it's always had performance problems for me. A very handy set of tips, though.




Monday
Jul262010

July 26, 2010: A Hammer, A Nail, and A Giant Squid

Book Status



Beta 5 should be out early this week, featuring a mostly new chapter on testing legacy projects, and also updating the code setup and the initial walkthrough chapters to Rails 3. Over the next couple betas any remaining Rails 3 incompatibilities will also be fixed.

Book Reviews



Something new for you on a Monday, a couple of novels that I liked in the last couple of weeks.

Kraken, by China Mieville. I'm a huge Mieville fan, so I was excited for this one.

The story starts when the preserved remains of a giant squid are stolen from a London museum, and the curator of the museum is dragged into a world where an apocalyptic squid cult is one of the least weird things going on. It's much more loose and jokey than Mieville's other stuff, something like a cross between Mieville's (oustanding) YA novel Un Lun Dun, Gaiman's Neverwhere, with the magical sub-world, and a Tim Powers novel a la Last Call or Expiration Date, filled with supernatural creatures who obey obscure and and convoluted supernatural worlds.

Overall the book is a lot of fun -- Mieville freely calls it a "shaggy god" story, which should give you an idea of the tone. It's not perfect; it takes forever to get started, and the flip side of loose and jokey is that sometimes Mieveille spends a lot of time on characters or conceits that don't tie in. But there are at least five really outstanding, audacious ideas or moments in the book, and for all that it's loose verbally, the plot comes together nicely at the end. Plus Mieville unironically uses the phrase "squid pro quo". So how can you go wrong?

Go Mutants!, by Larry Doyle. Doyle is a former Simpsons writer who has written a satirical mash up of pretty much every 50's B movie. I mean all of them. You've got your alien wanting to take over the user, a radioactive ape, a woman who's head is on a pan, atomic cars, teenage angst, flying saucers. There's a lot going on, and if you don't like one of the jokes, wait about a paragraph and there's another one coming.

Most of the jokes land, and liked the book a lot more than I thought I would once it became clear where it was going. It's got some heart, and some satirical bite. It's a little too willing to compromise tone for a quick joke to be truly great, but it's fun, and if you've sat through enough MST3K to see a lot of the referenced movies, you'll probably like it. It's got some clever alternate history bits too, for example, the initial alien contact takes place at the Polo Grounds, interrupting the famous "The Giants Win The Pennant" moment.

Links



The Rails Best Practices web site opened up, which is affiliated with the rails-bestpractices gem. Vote for best practices, and they might wind up incorporated in the gem. As I write this, leading the pack is "N+1 Queries" -- presumably avoiding them. Don't see testing yet, though, he said, banging that thing that looks like a nail with that hammer...

Speaking of tools, the Software Craftsmanship North America 2010 conference is October 15 and 16 at the Mariott Chicago O'Hare. Speakers include Dave Astels, Michael Feathers, and "Uncle Bob" Martin.

Aaron Sumner at Everyday Rails has a meta-tutorial of resources for various Rails command line tools, including the Rails command, generators, Rake, and the Unix command line. Take a look if you'd like to get better at navigating from the console.

Tim Bray from OSCON has a true essay on what all of us owe to Perl and to Desperate Perl Hackers. He's right about what Perl has brought, although it'd still be about my eleventeenth choice of language to use.

I have kind of mixed feelings about this Emma Lindsay post at Thoughtbot's Giant Robot's blog. It's about taking time in a TDD process to consider the overall design of the code. Which you should do, but which I think is already part of the TDD process. I completely agree with the workflow laid out in the post.

Two quibbles. I disagree with the sentence "Test Driven Development rests on the assumption that you basically know the optimal way to make your tests pass in advance." -- I've used TDD many times when I had no idea how the tests were going to pass, it works great in that case. Where TDD falls down is when you don't know the output of the code -- if you know the output, but don't know the algorithm then TDD works fine. Also, the list of TDD steps doesn't include a refactoring step, which is where, in practice, most of these design decisions would take place. All that said, writing a quick spike is sometimes needed to figure out the problem you want to solve and the tests you need to write.



Thursday
Jul222010

July 22, 2010: Catching Up

Me Me Me



Video of my recent talk at Refresh Chicago: You Got Your Agile in My UXD is now online. I haven't actually watched this version all the way through, but I apologize in advance for looking like a drowned rat -- it was raining that night. (Not, of course, in the room where the talk was...)

Book Status



Now working on switching the early "tutorial" chapters to favor Rails 3. I think that we're going to use Rails 3 on these walkthroughs and have a sidebar or something about significant Rails 2 differences. For other parts of the book, we'll not significant Rails 3/ Rails 2 differences where they exist -- a lot of stuff is relatively unchanged.

Catching up



Since I'm already in a self-promotion mode, and I don't have many links to share, I'll just mention a few things:

The book is still on sale at Pragmatic and Amazon.

I'm teaching a 4-day Advanced Ruby on Rails class at Obtiva central from Aug 30 to Sep 2.

If 4-days is too much, I'm doing a 3 hour tutorial on testing legacy applications at WindyCityRails 2010.

Enjoy your day. Tomorrow will be less self-promotional.
Wednesday
Jul212010

July 21, 2010: This Code Belongs In A Museum

Status



Not much to tell, really. Spent some time getting RVM set up, since I think I'll need it to manage simultaneously building the Rails 2 and Rails 3. Now I have a working version of the startup appendix that uses Rails 3 and Devise. I can't speak to using Devise in practice yet, but the immediate goal of making the setup less complicated was definitely accomplished. The big question now is how much to support Rails 2 in the walk-through chapters. I'm leaning toward just having the walk-through chapters be Rails 3 with only occasional notes on how Rails 2 differs.

Links



Apple has allowed the code for the 1984-era MacPaint and QuickDraw to be released to a museum where anybody can download and peruse. QuickDraw is all in assembler, and MacPaint is a mix of Pascal and Assembler. At a quick glance, the striking thing about the MacPaint Pascal is that it actually seems quite readable. The layout is consistent, it's commented, variable names have meaning, that kind of thing. Certainly miles ahead of any Pascal code I wrote back when I wrote Pascal code...

This is kind of a cute way to find hidden puts statements by raising exceptions. The project I'm on actually monkey patches puts to add a line to the output saying what file and what line of code the put statement is on. Surprisingly useful.

Claudio Maral has a couple of examples of cleaning up controller code by moving logic to the model.

Oh -- Droptext got updated. It's a universal iOS app for 99 cents that lets you edit files on Dropbox. This release, I think, makes the app functional. Some crash bugs were squashed, and you can now specify alternative text extensions. It's still pretty simple (I'd love to be able to change the display font, and I'd really love TextExpander integration), but it works and I'll definitely be giving it more of a spin.

The Ruby Hoedown has announced its speaker list for September 3 and 4. I've never been, but I've heard good things, and you won't find a major conference that's less costly.