Gáspár Nagy on software

coach, trainer and bdd addict, creator of SpecFlow; owner of Spec Solutions

Automatic Table Formatting in SpecFlow

by Gáspár on April 5, 2011

In the new SpecFlow v1.6 release, besides other Visual Studio 2010 integration improvements there is one more that I did not mention in my previous post: the automatic table formatting.

I have spent a lot of time by aligning the table columns in the Gherkin files. This new feature tries to address this problem: whenever you type a pipe (|) character in a table that has at least two rows, it realigns the table columns. Here are the rules for the aligning:

  • the column widths are calculated based on the cell texts (header and body) without starting/ending whitespaces
  • the cell values are aligned to the left with a single padding space
  • there is at least one padding space on the right
  • the indentation whitespaces of the header row are repeated for the subsequent rows
  • comment lines between table rows are handled

The formatting is applied only to the table (parts) before the typed pipe character, simply because of technical reasons: it was easier to preserve the current cursor position this way. Though this sounds a bit weird, this should be still natural if you type in the table row-by-row. If you want to reformat an existing table, just simply re-type the last pipe character.

<\/param><\/embed><\/object><\/div>“;” alt=”” />
A short video showing this feature

If the automatic formatting is not something you like, you can either press “Undo” after you typed in the pipe, or you can disable this feature from Tools / Options / SpecFlow.

3 thoughts on “Automatic Table Formatting in SpecFlow