Singlecell logo

This is Singlecell, the Angry amoeba Tumblelog. We use this tumblelog to write about the things that interest us, and the software we create.

04 Jul

Testing for desirable errors in Ruby

Sometimes, you want your code to fail. You want to make sure that in the event of a failure, an exception is generated - the equivalent of a controlled explosion. Something you can design contingencies around. Until now I’ve been a little frustrated with testing these eventualities, so I decided to hack up a quick custom assertion for your Test::Unit suites (although it should translate pretty effortlessly to RSpec or any other test framework):

# In test_helper.rb:
def assert_error_raised(errorklass=StandardError, &block)
     raised = false
     begin
       block.call 
     rescue errorklass 
       raised = true
     end
     # You will see this message if an error was not raised.
     # If an error was raised which was not of the type you specified, then the test trace
     # will be allowed to display the error as normal and the test will fail with an E.
     assert raised, "Expected error #{errorklass.to_s} to be raised but error never encountered."
end

# In your application code, let's say some_model.rb:
def do_something_with(array)
       unless array.is_a?(Array)
              raise ArgumentError, "Argument of type #{array.class.to_s} given to SomeModel#do_something when argument must be of type Array"
       end
       continue_doing_something
end

# In your test suite:
def test_error_generated_with_bad_argument_to_do_something_with
       @some_model = SomeModel.new
       # This test will pass
       assert_error_raised(ArgumentError) do
              @some_model.do_something_with "i'm not an array"
       end
       # This test will fail and dump the error via your test console's usual channel
       assert_error_raised(RuntimeError) do
              @some_model.do_something_with "neither am i"
       end
end
03 Jul

Chirrup 0.81 released

Hi there, sorry I haven’t written in a while. It’s this damned work business. Some actual content is promised soon.

Anyhow - A rather nasty text-escaping bug popped up in Chirrup, so I’ve issued a patch in version 0.81 which is available for download now.

The problem: Badly-formatted tweets containing certain special characters caused Chirrup’s JSON to fail parsing and the Chirrup UI to not display.

The fix: Improved sanitisation routine for tweet data being sent over JSON.

Happy Tweeting.

30 May
Upgrading to Rails 2.1 - A Horribly efficient and wonderfully-detailed guide.
24 May

How to force Git to ignore files

Just documenting this one for later, really. If you’re setting up a git repository and you need to ignore certain types of file - logs, or python bytecode (not that I’m dealing with those two problems at this exact moment or anything), the procedure is quite simple:

# Get to the hidden .git directory within your project.
cd /path/to/your/project
cd .git/info
# in .git/info is a file named "exclude". Open it in whatever you like. Here we'll open it with Textmate.
mate exclude
The file’s contents are, by default, commented out. To add your own ignore rules, just add each rule on a new line. Here’s a simple example from a Python project which prevents bytecode and Textmate project files from being committed:

*.pyc
*.tmproj
In a Rails project, you’d likely want a set of rules like the following completely untested fragment:

log
*.log
*.pid
tmp
23 May
The science of keyboard design. Fascinating!
20 May

Chirrup launched for public use

Well, that’s another silly little side-project in the can. If you’d like to have Twitter comments on your blog, wiki, website, or basically anything with a URL, head on over to http://chirrup.angryamoeba.co.uk and download Chirrup to get started!

Thanks to the Videojuicer dev team for helping with testing - Ted Han, John Carlin, Alex Nichol and Adam Livesley. And thanks to Adam for turning Chirrup into a wordpress plugin - this functionality is included in the main download package .

Thanks for bearing with us over the testing period, and have fun with Chirrup!

14 May
Commerce reaches its logical conclusion with The Something Store. One something for $10.
13 May

Chirrup - Twitter comments for your blog!

UPDATE: Chirrup is now available to the public. Visit http://chirrup.angryamoeba.co.uk to get your copy.

You might’ve noticed some new features here at Singlecell - we’ve been working on a library called Chirrup, which allows you to include comments from Twitter in your pages.

The idea behind Chirrup is to provide a more natural relationship between dialogue happening on individual pages and dialogue happening in public on applications such as Twitter. People are discussing content in comment sections, and then duplicating the discussion on Twitter - so why not marry the two up?

When you post a comment to a page via Chirrup, your comment is sent as an @reply to the blog’s owner, and contains both the URL and your comment. This means that your comments are completely legible to the rest of Twitter, and contain no unnecessary data.

Chirrup’s server-side component then slurps up the blog owner’s @replies and sorts through them for Chirrup responses. It supports compression and decompression of tinyurl’s, so comments sent with all major Twitter clients can be recognised by Chirrup’s parser.

Chirrup will enjoy a short testing period on this page while I snarf down huge piles of my own dog food, and will then be released under a Creative Commons license.

In the meantime, if you find a bug in Chirrup’s behaviour, I’d be obliged if you’d post it to the Chirrup bugtracker on Tails.

09 May
Transparent Post-Its are utterly inspired. Transparent Post-Its are utterly inspired.
oEmbed standard is new, relevant to our interests

Dan Glegg is an independent software developer living and working on the South coast of England.

He spends 80.5% of his time making software with Ruby, Actionscript and Objective-C, 15% of his time playing video games and 4.5% in a practical coma.