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