Testing with Perl: awesome

Sometimes when I get close to the end of the day and it isn’t feasible for me to start on something new I expand on my current project’s test suite. Recently I worked on one of the (seemingly) more complex ones. Basically it tests one of our autocompleters to ensure that it will search for the name and also the public facing id of a certain field. The id part was easy.

The name part was significantly more complex, but not too bad really:

my @data = $schema->resultset('Customer')->
      query => 'ame'
cmp_deeply @data, all(
         name => re(qr/.*ame.*/i)
), "Name matches query";

So basically what that does is ensure that all of the items in @data have a method that match the regex listed. It doesn’t care how many items are returned or any of the other details. Elegance!

Posted Thu, May 7, 2009

Receive Blog Posts in Your Email