Mads Buus Westmark’s tech blog
RSS icon Home icon
  • PDF generation in cucumber

    Posted on September 14th, 2009 mads No comments

    Many people prefer nice-looking, printable spec documents.

    Developers usually hate spec documents. Not the documents themselves, or  writing specs, but we hate the future agony a written document represents. Documents need to be updated many times, by different people, and most of them ends up as static, historical dinosaurs documenting not the features of our system, but our premature understanding of our system that happened to turn out quite differently.

    The nice cucumber framework comes to the rescue, changing rigid document specs into runnable code without losing business readability, and even adding a needed tightening of a usual sloppy spec syntax.

    The problem is….

    Many people prefer nice-looking, printable documents.

    So after trying to convince business people to accept the cucumber features, each in its easy-to-read raw text file, they still seem to need those documents.

    So following up on an old cucumber feature request, I wrote a PDF formatter using the ‘prawn’ library.

    In my opinion such a PDF is for presentation purposes only (which is why I think we should never need a doc/odt/rtf/pages version), as any editable form would undermine the whole idea of executable specs.

    The formatter entered cucumber mainline yesterday, and is part cucumber since 0.3.101 (15/9 2009).

    You need a recent  prawn gem installed for this to work:

    gem install prawn

    Example of usage:

    cucumber --format pdf --dry-run --out my-file.pdf   features

    This will generate a nice PDF of the features and scenarios, avoiding page breaks in scenarios.

    You can place your own logo in features/support/logo.png and the formatter will pick it up and display it on the front page, along with the generation time and the command line used.

    You can even run the actual features using this formatter, and the PDF will be colorcoded according to run status.

    Heres a screenshot:

    cucumber PDF formatter rendering a sample feature

    As soon as the cucumber is released, we will  a page on the cucumber wiki with some more examples and docs.

    Enjoy.