assert_raises_kind_of with Module error tagging
this sunny sunday afternoon i was putting together some utility code(stupid me!) to do some remote blogging from the shell or the cosy inside of my vim editing session. This for some later time, but while i was going on with my test-driven/test first development i hit the problem of missing a test to check for the base class of my errors. I wanted to:
assert_raise(StandardError) { @blog.find_post(:postid => 123456789) }
to generally check for any kind of trouble bubbling up but it was not working as expected. Instead i got nasty Failure reports:
1) Failure:
test_find_post(XMLRPCTest) [mylib.rb:83]:
<StandardError> exception expected but was
Class: <XMLRPC::FaultException>
Message: <"Sorry, no such post.">
I suspected XMLRPCTest::FaultException to maybe not beeing derived from StandardError, but that was not the case. A look in the ruby documentation and the ruby-talk thread confirmed:
assert_raise(*args) {|| ...} is checking for the EXCACT exception type only!
How was it for you?
On the ruby-talk mailing list there was a little discussion about this topic and i pretty much agree with all the +1 sayers on the list. Edwin Fine propsed adding his own assert_raise_s method the Assertions class. You easily get into muddy waters with opening standard ruby classes for some duck-typing but reverting to:
assert_raise(XMLRPC::FaultException) { @blog.find_post(:postid => 123456789) }
was not an option. This would expose way to much implementation detail to this very high level coding of the very first tests so early in the project. So I was using the source, as yoda said and found another solution for me.
Modules as base class arguments to assert_raises
After i read Edwin’s post i checked the source for def
assert_raise and learned that this method is actually checking for some kind of exception base class. The argument to assert_raise is an array of exception types. assert_raise does partition this types into Class and Module.
The assertion_raise checks for Class types is exact, but the Module is not(can’t be). They are checked with an is_a? condition – there can’t be no object instance of module type or course.
My original test therefor simply fails because StandardError is not a Module but a class. The XMLRPC::FaultException implementation is not mine but it is bubbling through my lib which i’m testing and this is precisly the condition i want to write tests for.
“Module tagged” exceptions and assert_raises_kind_of
First i wrote an empty tagging module for lib to tag all Errors and exceptions coming from my lib:
module MyLib
module Error; end
end
Now i can tag all exception from some deeper laying code with my Error module:
begin
...
rescue => e # errors bubbling from the underworld
# tag it
class << e; include MyLib::Error; end
# throw it
raise e
end
Voila, and now i can write:
assert_raise(BlogMist::Error) { @blog.find_post(:postid => 123456789) }
and finally got what i wanted but you’re milage may vary. Basically this gives me a way to create some kind of folksonomy of errors coming from my library. Don’t know yet where this might lead me, but hey, ruby is the best for protoyping and playing around!
Don’t be lazy!
Testing for error base classes instead of pricise error handling is not to make you lazy! As discussed on the forum thread it is to start with tests early on and being able to refine error condition testing over time.
Technorati tag: ruby, ducktyping, assert_raise, test-first,
Erlang makes it easy to parallelize our programs.
In Erlang, there is no mutable state, -> there is no shared memory, -> and there are no locks. This makes it easy to parallelize our programs.
Page 32, Pragmatic Erlang, Software for a concurrent World
starting to love it.
Technorati Tags: erlang, concurrent, threads, pragmaticprogrammer
sharper images for foto-foo

form the “competition drives innovation” department i would like to tell you about the foto-foo (of my company) update for sharper images, but see for yourself!
nobody blogged about us(sigh), but with cameroid and phozi two other sites similar to us got mentioned on techcrunch and elsewhere. And as competition drives…, you know, we are glad to have them around. To keep us motivated. So we got sharper images for today, lets see whats next? Ideas?
Technorati Tags: foto-foo, photobooth, cameroid, phozi, onlinewebcam, webcam, widget, idmedia
Beef up your RSS2 template for consumption with the Google Feed API Slide Show Control
There can be no doubt about it, RSS Feeds became the connecting backplane for the internet. Like Yahoo Pipes a while ago, the new Google Feed API is building its functionallity on top off standartized RSS feeds. For the feeds API, just providing a standardized RSS feed is enough to offer you a free ride. And a jolly good ride it is. The Slide Show Control is rich in features. Most major photo banks are supported and the actual controls allows for fine grained control of timings and sizes. The funny thing is, the API pretty much covers most of what we discussed at work on the friday before the weekend the API was released.
For the public timeline of our all-online-in-browser-photobooth-application foto-foo at /i-d media we wanted to add RSS feeds from which to build slide show like applications displaying a constant stream of fresh images. I decided to give it try and found this RSS2 rxml template on dzone.com which i filled with my data.
Various things happend, but no image was to be seen and the browser stalled a couple of times. First thing i found out was, “standard” Feed actually means it uses the Media RSS extension. This means the feed header has include the Media RSS namespace:
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:dc="http://purl.org/dc/elements/1.1/"> which in rxml looks like:xml.rss "version" => "2.0", \
"xmlns:dc" => "http://purl.org/dc/elements/1.1/", \
"xmlns:media" => "http://search.yahoo.com/mrss/" doNext thing to do is adding a <media:group> to all the feed items: <media:group>
<media:title>"#{img.title}"</media:title>
<media:content type="#{img.type}" medium="image" url="#{img.url}"/>
<media:credit role="#{img.credit.role">#{img.credit.txt}</media:credit>
<media:description type="plain">"#{img.desc}"</media:description>
<media:keywords>"#{img.keywords}"</media:keywords>
<media:thumbnail
width="#{img.thumbnail.width" height="#{img.thumbnail.height"
url="#{img.thumbnail.url}"/>
</media:group> your media group Bonus: feed reader compliance
handling images in RSS feeds is part of the vaguely borderline of rich media feeds where things like the Media RSS extension are actually made for. For Atom it seems media handling is defined a little better but the Feed API depends on RSS2. All this variations are hard to grok for some feedreaders but I wanted to have my foto-foo RSS stream also in my Reader, but the
<description><a href='#{img.link}'><img src='#{img.url}'/></a></description>
and voila, your Slide Show complient rss image feed works equally well in your normal feed reader.i know this is all rough and dirty, but it works for me, might help you a bit, and i dont like to drown in spec reading for to long today. Find my RSS2 rxml code snippet on dzone and mess it up in any way you like.
have fun.
Technorati Tags: rss, mrss, ruby, rxml, rails, foto-foo, google-feed-api
rug-b -> ruby user group berlin has new home
as you all might warm up already for railsconf europe in berlin later this year i would like to let you know that the berlin user group got its own wiki now. After Florian Gersdorf did restart the meetings earlier this year we are happy to host the rug-b meeting every first thursday of the month at our place in /i-d media. And now, thanks to Benjamin Krause, we got our own place at http://www.rug-b.com/ where we set up the instiki wiki for a better overview on the berlin activities. Have a look over there for agenda, locations, timeings, whatsoever.
For all of our conference guest in berlin in september the rug-b started brainstorming about some special events and/or try to arrange for some benefits with berlin infrastructure. So come to Berlin, hope to see you soon!
I’m in no way linked to O’Reilly or the conference but in any case i’m quite willing to help making the berlin rails conference an even better one than the last. So when you have question or ideas for some socializing events around the rug-b or berlin just drop me a note.
UPDATE: wer des englischen nicht maechtig ist, dem soll versichert sein das “we are happy to host the rug-b meeting” nicht bedeutet, dass ich oder mein arbeitgeber der Veranstalter sind, sondern nur der Gastgeber. Scheinbar hat das der Kommentator nicht ganz mitbekommen. Ansprechpartner sind oben also genannt, aber wer will kann selbstverstaendlich auch mich ansprechen. Oder lieber anonym kommentieren, ganz wie es beliebt.
cheers.
Technorati Tags: railsconf, ruby, usergroup, berlin, idmedia, rug-b
Fortran for Playstations…?
actually not quite, but i could not skip these. IBM released a Fortran compiler for the Cell processor, thank you. Cell is the CPU which superpowers the PS3 for those amongst you how didn’t knew already. Now i jump and dig up my old medical volumen renderer code and might port it the the Playstation3! But as an old fellow of mine always said: “you can write bad fortran in any language”, and i prefer ruby nowerdays.
Technorati Tags: cell, ps3, fortran, ruby, ibm
DHH snapshot with foto-foo

what’s there more left to say? As steffen already posted on our company/product blog he managed to shoot the man himself! David(of ruby on rails fame) in front of our foto-foo webcam snapshot solution. This is best practice par excellence, right there, on location, from there to internet with no inbetween. That is foto-foo: no files, no upload, no hazzle, and, Thanks! David! You are the man, have a good time over there at the rails conf in portland and hope to see you all back in berlin in september!
cheers
ruby user group berlin: JRuby, YARV/1.9, omdb.de and more
We had our 2nd ruby users group berlin meeting yesterday with two speakers and the demo of the yet to be released omdb.org project.
First was Tim Lossen giving a good round-up of the JRuby developments. Not of much interest to me because i have’t touched Java in a while. There was a common understanding that JRuby is a good thing and will pave Rubys way into the enterprise world, and with Sun now as official backing partner, JRuby is heading for a 1.0 release this summer for Javaworld confererence. You can already run JRuby based Rails applications inside you IBM Websphere Application server, Yeah! But can you run a Rails application with JRuby from inside a Java applet on your client browser? Hm, interesting idea, we couldn’t answer that yesterday.
Next was the talk by Murphy about the state of the ruby 1.9 release. Murphy mainly used Mauricio Fernandez eigenclass for reference and gave a really great overview around the three main themes of this topic: Roadmap, New and changed features and performance. Everybody loves the hand drawn roadmap image(which i can’t find now) and while a Ruby2.0 release being something from a far utopian future, we might see a 1.9 release later this year. I’m actually not following the 1.9 developments but became inspired to check again. Enumerators for examples reminded me to my STL/C++ years, just now without the template pains :-) Interessting were his comments on performance. Tim already showed some charts which related the JRuby to some other implementations and Murphy made some own benchmarks which were pretty much in line with Tims data. The general information is that 1.9(==YARV) is a couple of times faster, ranging from 3 to 10 times faster. BUT! and that is a big but, Murphy did report that on the real life applications he tested, the speed-up was close to insignificant for various applications. This is because the the performance tuning in 1.9 seems to be focussing on benchmark relevant stuff. And real life application are hardly build from benchmark functionallity. This sounds like, been there, seen that before. History(benchmark tweaking) is repeating itself. For me it doesn’t matter. When others can do 4000 requests/second, ruby/rails is definitly fast enough for me.
Finally Benjamin Krause showcased his upcoming OMDB project(tech blog, development version, live). OMDB is a IMDb in wikipedia style with a creative commons licence. 16501 People(see comment) 16000 movies are already in the database and once it will open up, everybody can extend it. Thats a cool idea conceptually and what he showed technically was nothing less than the equivalent to an “Full House” in poker. For example the subsecond async response times for fetching actors from a huge database which were made possible by his ferret magic. impressive.
And this also led to the agenda for the next meeting where Benjamin will give a talk about ferret on Rails. Everybody wanted to see more of it. Also we will have a talk by Adam about AmzonWebServices: S3 and Rails on EC2 . I’m looking forward to it. And about the open mic section, i’m pretty sure we are releasing our foto-foo into the wild.
And for you to have some fun, we plan to record the talks next time and put them up as podcasts to fit with your online consumption habits. Murphy and Tim also promised to upload their talks for online viewing (to the wiki i guess).
looks like the ruby users group berlin is consolidating.
Technorati Tags: ruby, usergroup, YARV, jruby, omdb, imdb, idmedia, berlin,
shameless self promotion: Diz/Kiz video mashup released
after having Diz/Kiz online for some weeks now, for the very first time we let it outside. There never was a Beta, and now it is officially out of the gates. My connection? I work for the company which build it: productdevelpment @ /i-d media(full flash!).
Diz/Kiz ist a ruby-on-rails webapp where you can diz or kiz videos pulled in from other sites. With just 2 mouseclicks(the second click is only for confirmation :-) and our bookmarklet you can publish videos yourself. Diz/Kiz was supposed to give you some fun minutes with a simple “am I hot or not” mechanik.
The spanish speaking genbeta blog has something to say about us:
DizKiz, subiendo y votando vídeos
Diz/kiz es una herramienta online que permite a los usuarios subir los vídeos, por ahora soportando los sistemas de Google Vídeos, Youtube y t-community, añadiéndo simplemente los enlaces de las páginas de los vídeos que desean subir.
and web2null from Germany:
DizKiz: Video-Voting
DizKiz ist ein kleines Mashup von I-D Media, auf dem Videos von YouTube, GoogleVideo etc. vorgestellt und mit “Kiz” (gut) oder “Diz” (schlecht) bewertet werden können. Das ganze ist auch als Widget auf der eigenen Homepage nutzbar.
It is nice seeing your work beeing picked up by people around the globe. There was no Beta and Diz/Kiz was a proof-of-concept for us. Now we keep on going :-) Usabilitywise we need to fix some things and we will add functionallity. Don’t worry, Diz/Kiz will never become a full featured video portal but remains a simple one-step-stop for your video fun. But more widgets would be ok, wouldn’t it?
And for you beeing a ruby coder maybe, I promise some API to embed Diz/Kiz widgets on your own site. Diz/Kiz was designed from the groud up to embed video data from external storage providers and this is how it was build. Right now we are working on opening up this interface to the web.
next stop: foto-foo! This time we do a Beta, don’t forget to sign up!
Technorati Tags: dizkiz, video, mashup, idmedia, youtube
bubble bursting version numbers
With all due respect,
New versioning, 0.12.2 —> 2.2.0:
is the most ridiculous version number jump i have seen i a while. Yahoo just released a new version of their Yahoo! UI Library and pull this little marketing trick.
This is even more extreme than in the good old new economy times when marketing geniuses where pushing their fail-ups towards their IPOs.
Don’t get me wrong, YUI is a fine piece of work and the yuiblog a delighting source of inspiration. But no marketing blah-blah whatsoever will make me understand the reasoning behind going from below 1.0 to 2.2 in a single step. Get real, start at 1 please.
cheers
Technorati Tags: yui, yahoo, javascript, gui, library
Diz/kiz es una herramienta online que permite a los usuarios subir los vídeos, por ahora soportando los sistemas de Google Vídeos, Youtube y t-community, añadiéndo simplemente los enlaces de las páginas de los vídeos que desean subir.