Cucumber , the BDD tool, is something that is really brilliant. I wrote Ruby code for my work too and I tried to used this tool with watir. Again, Brilliant.

And turns out there are cucumber implementations in Perl too:

  • http://search.cpan.org/dist/cucumber/
  • http://search.cpan.org/dist/Test-Cucumber/
  • http://github.com/kesor/p5-cucumber/tree/master

But they don't seem to work seamlessly with TAP-family of test tools. So I crafted Test::Cukes. It allows you to write your module test by defining scenarios first, then map those scenarios into test code:

use Test::More;
use Test::Cukes;

feature(<<TEXT);
Feature: writing behavior tests
  In order to make me happy
  As a test maniac
  I want to write behavior tests

  Scenario: Hello World
    Given the test program is running
    When it reaches this step
    Then it should pass
TEXT

Given qr/the test program is running/, sub {
    pass("running");
}

When qr/it reaches this step/, sub {
    pass("reaches");
}

Then qr/it should pass/, sub {
    pass("passes");
}

plan tests => 3;
runtests;

The scenario text is also output with Test::More::note when you run the test.

I hope this can help making my test files more maintainable. When my code base becomes larger I tended to split them into very small files (so I don't have to count the number of OKs like I'm learning math as a kid). However, maybe they should be written as modules and driven by a higher level logic like the code above.