Kerry Buckley

What’s the simplest thing that could possibly go wrong?

Archive for July, 2007

Unimplemented specs in RSpec


One of RSpec‘s many neat features is the ability to insert placeholder specs. These allow you to list a whole bunch of expected behaviour up front, without having to implement either the specs or the code, and without creating a huge swath of failing specs. All you need to do is omit the body of the specify or it block. Here’s a trivial example:

describe "The string 'foo'" do
  before do
    @foo = 'foo'
  it "should be three characters long" do
    @foo.size.should == 3
  it "should be capitalised to 'Foo'"
$ spec -f s foo_spec.rb                     

The string 'foo'
- should be three characters long
- should be capitalised to 'Foo' (NOT IMPLEMENTED)

Finished in 0.011201 seconds

2 examples, 0 failures, 1 not implemented

Technorati Tags: ,

Written by Kerry

July 29th, 2007 at 10:36 am

Posted in Ruby


one comment

I signed up to FaceBook a few weeks ago to see what all the fuss was about, and I’m still not sure I really understand.

OK, so it’s yet another social networking site, and it’s probably better than most of the rest. You can use it to store your photos (like Flickr) or videos (like YouTube), or to post regular status updates (like Twitter) And it’s got lots of ‘fun’ little applications, if you’re into that kind of thing. It’s got an API too, so it seems to have gained something of a reputation for being an open platform.

But how open is it?

I can show my Flickr photos on FaceBook, but as far as I can tell if I posted my photos directly onto FaceBook I couldn’t share them with the world at large. I can show my Twitter status on FaceBook, but I can’t just make it use that for my FaceBook status (or at least not without a lot of work). I could use the site like a blog, but then only a tiny invited audience would get to see my ramblings (big loss, I know). The whole site needs login, so it’s not externally searchable.

All the FaceBook applications seem to either exist solely within the site itself, or to just be a window onto somewhere else. There’s no real interaction going on. There are no APIs to allow other applications to access FaceBook data – it’s all one-way traffic. There aren’t even any RSS feeds.

It seems like FaceBook are making a play to become the Microsoft Windows of the social networking world – the common interface to everyone’s applications. Maybe it’s because I’m a long-time Mac user, but that makes me really nervous.

Written by Kerry

July 27th, 2007 at 10:22 pm

Posted in Web 2.0

Updating FaceBook status from Twitter


I’ve recently jumped on the Facebook bandwagon. I can’t be bothered to update two statuses (I rarely get round to it with one), so I was looking for a way to update my FaceBook status from Twitter. I installed the Twitter application in FaceBook, but that just displays the Twitter status separately.

It seemed that the only way to do it was to write a script to regularly check Twitter, and update FaceBook when it found a new Twitter message. I found a partial solution in PHP, but decided to roll my own in Ruby anyway.

It took a few hours longer than I expected (the documentation for Net::HTTP could be better), but I got there in the end. I now have the script below installed on my DreamHost account, and set to fire every minute via cron. It’s not the prettiest code I’ve ever written, but it does the job. Feel free to borrow it if you think it’ll be useful.

Andrew ‘Boz’ Bosworth
11:29pm September 6th

I’m an engineer at facebook and I’m writing to ask if you would be willing to take down the link to your facebook/twitter status sync utility (located on your website Based on your comment on TechCrunch I suspect you anticipated this would be coming at some point. Even if your intended use of such a script is noble (as I’m sure it is), the simple script you have posted on your site is (and has always been) against our terms of service. Said more shortly, we just can’t let people automate aginst our site outside of the platform; it’s a slippery slope.

We’d obviously like to resolve this without disabling your account or getting the lawyers involved if possible, so please let me know as soon as you’ve taken the script down so that our legal department doesn’t get all fired up about this.

Andrew Bosworth
Facebook Engineer

My reply:


As you’ll probably expect, I’m not particularly impressed with Facebook’s current stance on openness in general, or on this issue in particular. I hope that at some point you add an API to allow remote updating of status, in the same way that you recently added an RSS feed to allow tracking of friends’ statuses.

For the record, I don’t believe that posting the script on an external site constitutes a violation of the terms of service, although I accept that using it would be. Also, when you say “we can’t just let people automate”, I assume you really mean “we won’t just let people automate”. This is a shame, as it goes against the grain of the Internet, and reinforces the impression that you’re trying to lock people into your site.

All that said, I don’t particularly want to be spending my time fending off writs and takedown notices, so the script no longer appears on my site (see


Technorati Tags: , , ,

Written by Kerry

July 14th, 2007 at 4:39 pm

Posted in Ruby,Web 2.0

Cool “Web 2.0” introductory videos from the Common Craft Show

leave a comment

There are some great short videos on explaining some Web 2.0 concepts for non-technical people. The lo-fi style is very clever, too.

So far they’ve done RSS, wikis and social networking (see below).

Read the rest of this entry »

Written by Kerry

July 6th, 2007 at 8:16 am

Posted in Web 2.0

Correct use of the flash in Rails


[Update 9 May 2012]

This seems to work for testing in Rails 3:

it "puts an error in the flash" do
  post :create
  flash[:error].should == "Sorry, that's wrong."

it "does not persist the flash" do
  post :create
  flash[:error].should be_nil

[Update 20 April 2010]

I recently had problems testing, and Google kept leading me back to this post. Unfortunately it doesn’t seem to work with the current version of Rails (I’m using 2.3.5 at the moment).

This post from Pluit Solutions gives an alternative approach which seems to work. I haven’t tried it with Rails 3 though.

I don’t know whether this has caught anyone else out, or whether we just didn’t read the documentation properly (it’s covered briefly on p153 of AWDwR), but I thought I’d mention it anyway.

Anyone who’s written a Rails app will know that the ‘flash’ is used to store error and status messages, usually on form submissions. Model validation failure messages automatically get copied into the flash, but you often want to do it manually too.

flash[:notice] = "User Details updated."
redirect_to edit_user_path(@user)

The gotcha comes when you want to display a message and render a page, as opposed to redirecting – for example when errors are preventing a form from being submitted. This is how not to do it:

flash[:error] = "Password doesn't match confirmation." # WRONG!
render :action => 'change_password'

The problem is that the flash is stored for the next request. Because we’re no longer doing a redirect, that means the message may appear wherever the user goes next, not just on the page that we just rendered. To avoid this, use, which is only used for the current request:[:error] = "Password doesn't match confirmation."
render :action => 'change_password'

The rule of thumb is to use flash if you’re redirecting, and if you’re rendering (either explicitly, or by dropping through to the default view for the action).

All very well, but whatever you put in is cleared out at the end of the request, so how do you test it? The answer (for RSpec, at least) lies in a comment on this RSpec feature request – basically just add the following to spec_helper.rb:

module ActionController
  module Flash
    class FlashHash 
      def initialize
        @hash = {}
        @now_hash = {}
      def [](key)
      def []=(key, obj)
        @hash[key] = obj
      def discard(k = nil)
      def now
      def update(hash)
      def sweep
        # do nothing

You can now do something like this:

describe "When a user tries to change his password with an invalid verification code" do

  it "should put an error message in the flash" do[:error].should == "Incorrect verification code or password."
  it "should not persist the flash" do
    flash[:error].should be_nil

Technorati Tags: , , ,

Written by Kerry

July 4th, 2007 at 2:37 pm

Posted in Rails

Putting Things Off


As I come to the end of a week off work, with a list of things that need doing around the house that’s little changed since the beginning of the week, it strikes me that it’s about time us procrastinators had our own system. With that in mind, I present the following (with apologies to David Allen).

The Putting Things Off System

The main principles of Putting Things Off can be summarised in four steps:


Every time you come across something you need to do, put it into a ‘bucket’ (an e-mail folder, a drawer in an old filing cabinet you never look in, or perhaps an actual bucket). Once you get all the things you need to remember out of your head, it’s easier to forget about them.

Once a bucket gets full, move it out of sight somewhere and start a new one. Don’t make the mistake of looking in the buckets – it’ll just be depressing.


When faced with a list of things that need doing, just pick a few at random and try to get rid of them using one of the following strategies:

Two-minute rule

If something looks like it would only take a couple of minutes, you can do it any time, so forget it for now. Don’t distract yourself by trying to do it straight away.


Can you think of someone else to blame for the task not getting done? If so, you’re in the clear. Don’t remind them though, otherwise they might remove the obstacle, and with it your excuse for inaction.


Deferring things is just a more positive way of saying procrastination, so this is a good plan if no other excuse presents itself.


Organise all your tasks into projects, and allocate a ‘next task’ for each. That way you can ignore all but one item in each project, leaving far fewer things to think of reasons to avoid.

Organising by context can also be a helpful source of excuses. For example, a context might be ‘things I can’t do at home’ or ‘things I can’t do if it’s raining’.


Review all your lists occasionally, to see whether you’ve ignored anything for so long that it’s gone away. One useful technique is the well-known ’43 folders’ – if you split stuff up across that many places, it’s far easier to forget about.


Finally, all this hard work will be to no avail if you still end up doing things. If all else fails, remember the words of the Grange Hill cast, and just say no.

Technorati Tags:

Written by Kerry

July 1st, 2007 at 5:51 pm

Posted in General nonsense

The simplest thing that could possibly work

leave a comment

But other times we’d be programming away, and we’d say, “Now, wait a second, what are we working on here?” We’d just get stuck. And if we were stuck more than a minute, I’d stop and say, “Kent, what’s the simplest thing that could possibly work?”
Ward Cunningham

Not a command: “Do the simplest thing that could possibly work!”, but a question: “What’s the simplest thing that could possibly work?”.

Once you think of something really simple that might work, think for a minute – is there an obvious reason why it definitely won’t? If not, try it, and then you’ll know. More importantly, if it didn’t, you’ll know exactly why not. Maybe it was functionally correct, but not fit for purpose – perhaps an algorithm was too slow, or an interface was too confusing or ugly to release to users. The point is, you’ve either got something you can build on, or you’ve got a concrete reason to abandon an idea, rather than a theoretical argument. If you’re lucky, it’ll turn out that the simplest thing did work, and the problem’s solved.

Too often people seem to twist this into some kind of XP Prime Directive, claiming that a particular solution is over-engineered because it wasn’t TSTTCPW. On the other side of the fence, big-picture architect types use it as a straw man to criticise agile methodologies, claiming that they ignore anything that isn’t part of TSTTCPW, leading to simplistic and unscalable solutions.

As Einstein said, “Everything should be made as simple as possible, but no simpler.”

Technorati Tags: , ,

Written by Kerry

July 1st, 2007 at 9:27 am

Posted in Agile