Twisting my brain around Ruby while standing on the shoulders of giants

I’ve long been impressed with the Watir project – a ruby library that programmatically drives a web browser. With it, you can drive IE (and now FIrefox and Safari as well) through web sites, testing for content and verifying interactions. Previous test harnesses had some significant failings when it came to fiddling with the various javascript components, mostly because they were emulating a browser and just didn’t have javascript built in. I really love twill and mechanize for example, but they just don’t get the same javascript enabled coverage that you can arrange with a running browser.

When some of the QA folks here said “We’re going to use this!” I thought, “Yeah, awesome – good choice!”. A little later in the discussion it became clear that a day-long workshop would really help everyone come up to speed. “I can do that!” I thought … out loud … so now I’m teaching a day-long internal workshop on ruby and the watir library to folks here at the office.

The really good news is that I have the shoulders of giants to stand on – specifically the incredibly detailed and hard work that the Watir contributors have done in their documentation and the inspiration for the class setup and associated cheat sheets from Brett Pettichord. Since I’m not a big ruby language guy (more of a python guy, actually) I also immediately picked up a copy of Everyday Scripting with Ruby, from the Pragmatic Programmer press, which I wholeheartedly recommend.

As a side note – Pragmatic has become the “new OReilly” for me – the technical books are of good quality and invariably useful.

Aside from general syntax, the biggest thing I’m having a hard time wrapping my head around is the block mechanisms and periodic lack of parantheses. From the examples I’ve seen, parantheses are used intermittently, and I haven’t a clue when they’re needed or not. For my own work, I’ve been including them – but reading code without them is somewhat odd to me. Getting used to iterators using a block mechanism and the habit of many ruby folks of doing nifty one-liners is taking a while too. I invariably have to tease apart the syntax slowly to get a clue of what it’s doing – kind of like looking at a particularly hairy regular expression. I always rather found lambda methods in python a bit indecipherable myself, so I expect this is part and parcel.

As a final note to anyone interested in Watir, my one huge complaint with the project has completely disappeared. When I first say Watir, it really only supported “driving IE” – and I was having a somewhat irrational desire to shoot anything that required me to use IE at the time. The background of my mental state at that time is a tad hard to explain, but that particular issue is no longer even relevant. At of August 15th of this year Firewatir is a lovey supported variation of the Watir framework, meaning you can drive IE or FIrefox with the same library style setup. There’s also a variation for Safari that I haven’t looked into – covering all of the browsers that I care about or are forced to care about. I never had much luck with OpenQA’s Selenium, although I really tried… I never got terribly consistent results with it. This solves that technical issue entirely for me.

Published by heckj

Developer, author, and life-long student. Writes online at https://rhonabwy.com/.

3 thoughts on “Twisting my brain around Ruby while standing on the shoulders of giants

  1. Hey Joe… if you can, drop by the seattle.rb meeting. We meet every Tuesday from 7-9pm @ the new vivace @ the top of broadway. Great espresso, lots of ppl who can help.

    Like

  2. You’ll get used to the parens (or lack of). My personal philosophy is that they only go where they’re needed. If the parser recognizes the construct you’re using without parens, they probably don’t belong there. Get a copy of The Ruby Programming Language (the new book from Matz) – it’s got good, detailed coverage of this.

    Blocks (closures), though, are the heart of Ruby. Not only will you get used to them, you will curse loudly at any language that doesn’t have them. They’re a great big honking hammer in your Ruby toolbox, and you’re going to use them all the time.

    Like

Comments are closed.

%d bloggers like this: