Exploration Through Example

Example-driven development, Agile testing, context-driven testing, Agile programming, Ruby, and other things of interest to Brian Marick
191.8 167.2 186.2 183.6 184.0 183.2 184.6

Thu, 20 Jul 2006

People who want to learn Ruby in Cleveland

Someone from the NOSQAA is being relentless about getting me to do something at their annual Quality Expo in Cleveland, Ohio, USA, in early November. (It happens that I have a client in Cleveland these days.)

That ties in with some thoughts about the long-overdue Scripting for Testers book. (Which is getting close, honest!) I'm not a fan of two- or three-day 60-people-in-a-room training courses. Even if there are lots of exercises, most of the course doesn't stick. It doesn't cause the kind of change that I want to cause.

So, when people call me and tell me they want me to train their testers in Ruby, I'm not planning on offering them such a course. Instead, I'm going to pattern my offering on the way I do consulting, which is to fly in for a week per month, sit down with people at computers and do work on their product, repeating the trips until they decide I'm no longer worth the money.

The Ruby variant would go like this: I won't train the testers in Ruby. I wrote a book that's supposed to allow them to self-train. So I want the company and testers to demonstrate that it won't all be a waste of time by working through parts 1 through 3 of the book on their own and starting to apply Ruby to their own projects. I'll come in, once or more, to help them with those projects, make observations, give impromptu mini-courses on topics I think they should know. That will be more expensive and time-consuming than a stand-up course, but it will have a much higher chance of working.

But I can do more, tying Ruby into my normal consulting. Suppose I'm flying to a city once a month anyway. What I'd like to do is organize something akin to a flash mob: a flash user group of testers (and others) who want to learn scripting. They'd learn it on their own, in concert or individually. When I'm in town, we'd have dinners devoted to the topic. At some point, we'd cap it off with a one-day mini-conference on Ruby and testing. I'm envisioning that the morning would be devoted to enticing beginners. Again, I'd downplay the lecture. What I'd want is the members of the existing flash user group to pair up with newbies and show them the Wonders of Ruby. In the afternoon, we'd have advanced topics. Perhaps something like RubyConf would work: have people present how they've used Ruby in their job. That way people would get ideas, hook up with people doing similar things.

Then, having gotten things going, I would ride off into the sunset.

To see if that works, I'd like to do a dry run in Cleveland. The question is whether there's interest. If you're near Cleveland and interested, drop me a line. Forward this URL to people in Cleveland. Let's see if we can get a critical mass going. If so, I'll tell Ms. Persistent-Far-Beyond-the-Call-of-Duty-They're-Lucky-to-Have-Her that she's won me over.

## Posted at 09:03 in category /ruby [permalink] [top]

Sun, 25 Jun 2006

RubyConf proposals

David A. Black reminds me to remind you that RubyConf proposals are due June 30. Here's the proposal link: http://proposals.rubygarden.org/.

## Posted at 10:24 in category /ruby [permalink] [top]

Sun, 22 Jan 2006

The right way to put Unicode on the pasteboard

The previous solution to my copy-Unicode problem turns out not to work for non-Unicode characters, at least not for the sort of screwy characters testers like to paste into apps. So I had to solve it right. I put the solution here in hopes that it'll be found in a web search someday and save someone some time.

require 'osx/cocoa'


#Example: unicopy %w{ 03b4 03d4 03a6 }
def unicopy(hex_string_array)
  copy_with_encoding(utf8(hex_string_array), UTF8_ENCODING)

# Utilities

def utf8(hex_string_array)
  number_array = hex_string_array.collect do | hex_name |

def copy_with_encoding(string, encoding)
  data = OSX::NSData.dataWithRubyString(string)
  ns_string = OSX::NSString.alloc.initWithData(data, :encoding, encoding)
  pb = OSX::NSPasteboard.generalPasteboard
  pb.declareTypes(["NSStringPboardType"], :owner, nil)
  pb.setString(ns_string, :forType, "NSStringPboardType")

For the Windows version and for copying non-Unicode, look here: http://www.exampler.com/testing-com/review-copies/test-strings-0.1.zip. That's an alpha version of a collection of utility methods oriented toward helping testers mess with text fields. They're inspired by James Bach and Danny Faught's perlclip. They work on both the Mac and Windows. The source will eventually live on the Scripting for Testers site.

## Posted at 21:52 in category /ruby [permalink] [top]

Tue, 17 Jan 2006

Hack for unicode to the pasteboard

See, just explaining the problem and sleeping on it makes the solution wave to attract your attention:

One way to put unicode on the Mac OS X pasteboard is to use FUJIMOTO Hisakuni's rubyaeosa to execute Applescript.

require 'osx/aeosa'

   set the clipboard to \xc7data utf8CEA3CEA6\xc8


(The hex characters are Mac-Roman "chevrons" that vaguely look like ‹‹ and ››. Applescript doesn't use 7-bit ASCII. The glop after "utf8" is sigma and phi in the Greek alphabet.)

I could dig further into rubyaeosa to find a Ruby message send equivalent to "set the clipboard", but I maybe think that's a bad idea. This is an example for Scripting for Testers, and I think that the message of getting the job done with bailing wire and twine and moving on is a good one.

Now on to Windows...

## Posted at 08:56 in category /ruby [permalink] [top]

Mon, 16 Jan 2006

Unicode to the pasteboard

I am blissfully ignorant of Unicode.

Nevertheless, I want to write a Ruby script that puts Unicode characters (the Greek alphabet, say) onto the Mac OS X pasteboard. It has to be pure Ruby (no writing in C). 7-bit ASCII I can do, and 8-bit Mac-Roman, both using pbcopy. However, I can't see a way to do Unicode.

Please let me know if I'm wrong.

I don't care about the encoding the Ruby code works with. UTF-8, UTF-16, Punycode, whatever.

P.S. Interesting how much more understandable the Wikipedia pages on Unicode are than the official site is.

P.P.S. Seeming bug in Textedit on 10.4.3: if I create a file full of Greek characters and save it as UTF-16, I can open it and see the same characters. If I save it as UTF-8, when I reopen it, it looks like it's full of Mac-Roman characters.

## Posted at 18:55 in category /ruby [permalink] [top]

Mon, 14 Nov 2005

Attractive Ruby tests that use multi-line strings

Suppose you're testing some method whose input is a multi-line string. You could write something like this:

  def test_tags_can_be_deeply_nested
    table = "<table>
                             Way nested
    slices = TagSlices.new(table, "table")
    # blah blah blah

That's fine - unless whitespace in the middle of the string is significant. The above method has no whitespace on the string's first line, but a whole lot on the others. What if I needed it all to be flush left? This is ugly:

  def test_tags_can_be_deeply_nested
    table =
                 Way nested
    slices = TagSlices.new(table, "table")
    # blah blah blah

I could argue that the ugliness makes it too hard to see the structure of the test and too hard to skim a file quickly and see what the tests are. That argument may even be true, but the real reason I don't like it is that it's ugly.

So I write such tests like this:

  def test_tags_can_be_deeply_nested
    table = "<table>
            . <tr><td>
            .   <table>
            .    <tr>
            .     <td>
            .       <table>
            .         <tr>
            .           <td>
            .               Way nested
            .           </td>
            .         </tr>
            .       </table>
            .     </td>
            .    </tr>
            .   </table>
            . </td></tr>
    slices = TagSlices.new(table, "table")
    # blah blah blah

unindent removes the whitespace at the beginnings of lines, together with the discrete margin made of dots. Its code looks like this:

class String
  def unindent
    gsub(/^\s*\./m, '')

I've fiddled around with unindent to a ridiculous degree, changing its name, how it works, how the margin is indicated. I think I've settled on this one.

## Posted at 17:00 in category /ruby [permalink] [top]

Thu, 13 Oct 2005

A Watir win

At PNSQC, Michael Kelly gave a talk. Among other things, it covered converting functional test scripts into performance test scripts. He gave examples using several tools, one of them Watir.

As he described how little of the test script had to change to make it a performance test script, I realized that there was a way to make it require no changes. I didn't quite finish a demo during his talk, but I did shortly after. Here's an example:

Load (a fake version of) Watir, get an object representing IE, and ask it to go to a URL.

irb(main):001:0> require 'watir'
=> true
irb(main):002:0> ie = IE.new
=> #<IE:0x329144>
irb(main):003:0> ie.goto('url')
=> "here's a bunch of HTML"

(I faked out Watir because I didn't have net access and, anyway, this machine is a Mac.) What you can't see in the above is that goto delays a random number of seconds before returning.

Now I want to run the same "test", timing all gotos.

irb(main):004:0> require 'perf'
=> true
irb(main):005:0> IE.time(:goto)
=> nil
irb(main):006:0> ie.goto('url')
=> "here's a bunch of HTML"

It took just over a second.

Here's the code. Mike will be seeing about getting something like it into the Watir distribution.

class IE
  def self.time(method)
    method = method.to_s
    original_method = '__orig__' + method
    new_def = "alias_method :#{original_method}, :#{method}
               def #{method}(*args, &block)
                  start = Time.now
                  retval = #{original_method}(*args, &block)
                  puts Time.now - start

Take that, WinRunner!

## Posted at 15:08 in category /ruby [permalink] [top]

Wed, 21 Sep 2005

Ruby makes the big time

My son is going to a birthday party this weekend. He wanted to get the birthday boy (Jody) two plush toy giant microbes. He chose Ebola and flesh-eating bacteria. (Yes, this was after I made several attempts to get him to choose something less gruesome, like the common cold or ulcer, because I didn't want his mother to think "what kind of bizarre child does my Jody hang around with?" But Paul insisted that Jody really likes that kind of thing. (What kind of bizarre child does my Paul hang around with?)

In any case, he prevailed, and I purchased the two toys at ThinkGeek. Along the way, I took their 46.4 second feedback survey. It asks what your favorite language is. I scanned down to the Rs and was appalled to find that Ruby wasn't listed, though Rebol and Rexx were and Python was just above them. But I later noticed that the list is not entirely alphabetical. Certain languages have been promoted to the front of the list: C, C++, Objective C, Perl, Java, ..., and Ruby. This is the big time, folks.

P.S. If you're from ThinkGeek: sorry about the rant in your Suggestions / Comments / Thoughts / Rants text area. That was before I noticed Ruby at the top.

## Posted at 09:25 in category /ruby [permalink] [top]

Tue, 11 Jan 2005

Another tester succumbs

From Elisabeth Hendrickson, testing consultant and my occasional partner in training:

I'd been resisting Ruby for such a long time, thinking that I already knew enough scripting languages. I figured I'd be better off spending my time learning Java and C#. After seeing what WATIR could do and how neat Ruby is, I became a convert. I dug in and learned the basics of Ruby over the weekend (though there is still much I need to learn).

## Posted at 20:42 in category /ruby [permalink] [top]

Thu, 13 May 2004

Exploratory testing with Ruby

I've written an article that shows novice programmer/testers how to use Ruby for exploratory testing of Google's web services interface. I hope it convinces some tester somewhere that programming is easy and fun.

## Posted at 16:32 in category /ruby [permalink] [top]

About Brian Marick
I consult mainly on Agile software development, with a special focus on how testing fits in.

Contact me here: marick@exampler.com.




Agile Testing Directions
Tests and examples
Technology-facing programmer support
Business-facing team support
Business-facing product critiques
Technology-facing product critiques
Testers on agile projects

Permalink to this list


Working your way out of the automated GUI testing tarpit
  1. Three ways of writing the same test
  2. A test should deduce its setup path
  3. Convert the suite one failure at a time
  4. You should be able to get to any page in one step
  5. Extract fast tests about single pages
  6. Link checking without clicking on links
  7. Workflow tests remain GUI tests
Permalink to this list


Design-Driven Test-Driven Design
Creating a test
Making it (barely) run
Views and presenters appear
Hooking up the real GUI


Popular Articles
A roadmap for testing on an agile project: When consulting on testing in Agile projects, I like to call this plan "what I'm biased toward."

Tacit knowledge: Experts often have no theory of their work. They simply perform skillfully.

Process and personality: Every article on methodology implicitly begins "Let's talk about me."


Related Weblogs

Wayne Allen
James Bach
Laurent Bossavit
William Caputo
Mike Clark
Rachel Davies
Esther Derby
Michael Feathers
Developer Testing
Chad Fowler
Martin Fowler
Alan Francis
Elisabeth Hendrickson
Grig Gheorghiu
Andy Hunt
Ben Hyde
Ron Jeffries
Jonathan Kohl
Dave Liebreich
Jeff Patton
Bret Pettichord
Hiring Johanna Rothman
Managing Johanna Rothman
Kevin Rutherford
Christian Sepulveda
James Shore
Jeff Sutherland
Pragmatic Dave Thomas
Glenn Vanderburg
Greg Vaughn
Eugene Wallingford
Jim Weirich


Where to Find Me

Software Practice Advancement


All of 2006
All of 2005
All of 2004
All of 2003



Agile Alliance Logo