Test Automation with Ruby: Don't drink the kool-aid

I was stuck at home this weekend with house painters pondering how best to spend the day sitting at home, so I decided to actually play around with the Ruby scripting language a bit. I will admit my bias in my previous post about the Ruby scripting language was based on business justifications and personal preferences towards the C family of languages. But, because Ruby is still being pimped by some experts in the industry for test automation, I figured I should understand more about the mechanics of language other than it's lack luster appeal by many professionals in the software industry.

 

I didn't delve very deeply into Ruby. A few chapters of Hal Fulton's book The Ruby Way and some additional research on the web confirmed my suspicion that Ruby for all purpose software test automation is simply not a good investment in your time given the other alternatives.

 

International Support Sucks!

 

If you are stuck working on small projects in English only then this probably won't bother you too much. But, if you realize the majority of the world does not communicate in English then Ruby's lack of international support simply sucks. Unless there is some hidden secret in the Ruby society the fact is Ruby can't do Unicode. Yes, you can store UTF-8 encoded data in 8-bit encoded strings, but many Ruby String methods assume single byte encoding. I have to admit this completely blows my mind. UTF-8 is a popular encoding form of Unicode; however, it is only one of several Unicode transformation formats. So, forget about UTF-16, and definitely forget about testing Unicode surrogate pairs or conformance to the GB18030–2000 Chinese encoding standard. So, what does this mean for testers? String testing is basically limited to a very small subset of characters.

 

Multiple ways to initialize arrays (and just about anything else)

 

Hal Fulton lists the following 3 ways to initialize the array class method.

            a = Array.[](1,2,3,4)

            b = Array[1,2,3,4]

            c = [1,2,3,4]

I don't know why this would be a 'cool' thing to do, but I do know that it increases confusion, and potentially adds to the cost overhead of white box testing and code maintenance.

 

I guess it's pretty cool that arrays in Ruby contain objects rather than data types, and an array in Ruby can contain integers, strings, etc. I am not quite sure why this is a positive because I can't think of a situation where I would want to iterate through an array with disparate data types.

 

Cryptic codes

 

If Hungarian notation wasn't bad enough, just stir in some Ruby identifiers into the cryptic pool of sludge. Let's see the # sign is a comment if it is the first character in a new line or after a statement (which of course doesn't end with a semi-colon or other signifier), otherwise it is an embedded variable. And what is the deal with variable scope declarations? The @ sign is used to declare instance variables, using @@ signs declares a class variable, and of course the $ sign declares a variable that is global in scope. Hmmm...I am thinking the access modifiers 'public' and 'private' in C# make a lot more sense, but of course I have to type all those letters instead of just pressing the shift key followed by one or two characters.

 

Useless keywords

 

For all you Ruby experts, can someone please explain the purpose of the unless keyword? It seems to me to be another bit of useless confusion. Let's see if I have this right in Ruby:

 

            if x < 5 then

            statement

  end

and

            unless x < 5 then

            statement

            end

 

are identical! What's the point?

 

Syntax?

 

And what's the deal with 'downcase' and 'upcase' instead of 'lowercase' or 'uppercase?' Is downcase really intuitive to anyone other than Ruby zealots?

 

I could probably go on, but frankly I am convinced that Ruby is not the way.

 

So, that's a day in my life that I will never get back. But, all was not lost because in-between chapters of the Ruby book I got to watch the paint dry on my house.

Comments

  • Anonymous
    August 29, 2006
    Surely "unless" is translated as "If Not"? In which case, "if x<5" is NOT the same as "unless x<5". i.e. "unless x<5" means "when x is NOT less than 5"?

    I agree that the wording is strange, but surely this is just an alternative single-word approach? All languages differ, it's just a case of getting used to a different set of words?

    Regarding the "downcase" and "upcase" - Excel has had "UCase", and "Upper", so I guess "downcase" could be regarded as one logical opposite. Other languages have "UPCASE" - Delphi and php?

    (PS - I'm a Test Manager, not a coder, and have no knowledge of Ruby)

  • Anonymous
    August 29, 2006
    Hi Elijah,

    WRT to the unless keyword in Ruby, looking at a list of keywords I would also assume different behaviors. But, that is simply not the case.

    I agree that each language uses different words. (I also never really got the DIM thing in VB for example.)

    My key point is that having alternative keywords that do the same thing simply obfuscates the code.

    I just thought the upcase/downcase thing a bit strange. The real deal breaker for me is the way Ruby deals with strings. Much of the data we deal with today is Unicode and there are multiple transformation formats of Unicode(of which Ruby partially supports only UTF-8).

    Ruby may have some benefit in the web development community for limited applications. But, as a useful language for testers, Ruby simply can't do what I need (especially since the web is designed to support the Unicode.)

  • Anonymous
    August 29, 2006
    Totally agree with Elijah in what was said regarding the 'unless' and UCase scenarios if it makes it easier, view unless as IF NOT. In addition, if I understand you correctly, you cannot see the benefit of the mixed array types "an array in Ruby can contain integers, strings, etc. I am not quite sure why this is a positive because I can't think of a situation where I would want to iterate through an array with disparate data types."
    Surely a form entry where you wish to be able to collect mixed data types (ABC,123...etc) makes this function invaluable. I don't see how you cannot see the benefit of this?!?

    Again, I know nothing of ruby so I may be speaking out of turn, it's just that most of the things you mention seem either standard in coding languages across the board, or a good idea.

  • Anonymous
    August 30, 2006
    Hi Lewis and Elijah,

    You guys are right and I stand corrected. Thanks for driving that point. Sometimes I can be a bit thick-headed. (I'll blame it on the latex paint fumes :-).) Hal Fulton's example which is specifically:

    if x < 5 then
     statement1
    else
     statement2
    end

    unless x < 5 then
     statement2
    else
     statement1
    end

    Basically, this is the same as doing

    if (condition)
       statement 1;
    else
       statement 2;


    if (!condition)
       statement 2;
    else
       statement 1;

    I know...that darned little exclaimation point sometimes gets overlooked and is not understood unless you know the cryptic codes used consistently among languages such as C/C++, Java, C#, etc.

    WRT to the arrays of disparate data types I understand your example to collect information from a form, but then what efficient task are you going to do with it? You can't sort it, you can't loop through it efficiently, etc. So, I guess I should have clarified and stated that from a test automation perspective I don't see the benefit.

    But, the things I point out are not so standard in coding languages across the board with the exception of perhaps the cryptic codes.

    Java, C#, C/C++ all support Unicode and the various transformation formats for encoding strings of Unicode characters. Most languages do not offer multiple ways to delcare an array object (or other declarations), and the only languages that have the "unless" keyword are Ruby, LISP, and BOO.

    Again from a test automation standpoint I stand by my statement that Ruby is not a good choice. WATIR may provide some great support for web testing, but what about testing Windows applications? I guess I will have to get busy on the benefits of C# post so folks can make their own decisions.

  • Anonymous
    August 30, 2006
    The comment has been removed

  • Anonymous
    August 31, 2006
    Your points are well stated Michael, and I agree that all languages have their quirks, idiosyncracies, and some stuff that just makes us say "huh?".

    And I haven't looked at WATIR. And testers who limit their testing to web interfaces may find WATIR sufficient to fit their needs.

    It is interesting that no one has yet to address the issue of the lack of Unicode character support other than the limited UTF-8 support. The Unicode Standard supports 3 encodings, and there are several more defined. I guess this is ok as long as you only deal with one language and that language is English.

    I also stand by my assertion as long as it includes the entire assertion which states "for all purpose software test automation Ruby is simply not a good investment of your time given the other alternatives." By 'all purpose test automation' I am implying testing legacy Win32 applications, managed code applications, and weblications and services.

    Learning alternative languages from a dev perspective has some merit and sometimes makes new ideas click. But, for non-coding testers considering learning a language for test automation to improve their marketability and/or future business needs I simply wouldn't suggest Ruby. (Insert blatent plug for C# here.)

    (Mental note to self: Avoid the use of the 'you' pronoun in writing.)

  • Anonymous
    October 31, 2006
    The comment has been removed

  • Anonymous
    October 31, 2006
    The comment has been removed

  • Anonymous
    May 31, 2009
    PingBack from http://woodtvstand.info/story.php?id=11531

  • Anonymous
    June 02, 2009
    PingBack from http://woodtvstand.info/story.php?id=52719