How to do block comments in Gherkin?

Solution 1:

It is not supported by Gherkin, so you have to prefix all lines with #.

If you use the SpecFlow Visual Studio extension (v1.9.2) you can simply select the lines and toggle them into comments and back. The default shortcuts are Ctrl+K,C to comment and Ctrl+K,U to uncomment.

You can also "workaround" this problem in Visual Studio using the multi-line editing feature. (See http://weblogs.asp.net/scottgu/archive/2010/04/26/box-selection-and-multi-line-editing-with-vs-2010.aspx). You just have to select the beginning of the lines with holding ALT and using the mouse. Using this feature you can type in all the selected lines at the same time. You can also remove all of them similarly, selecting all the # characters for deletion.

Solution 2:

Yes, there is. It's called PyStrings type comments. See example at http://docs.behat.org/guides/1.gherkin.html#pystrings.

It will work if you use it just after Feature or Scenario and some other elements.

Feature: my feature
  """ some block comment
      still block comment
  """ end of block comment
Scenario: my feature
  """ some block comment
      still block comment
  """ end of block comment

One the other hand it will not work if you want to comment out some steps.

I think you can configure your IDE to comment out a line on standard key combination. For example IntelliJ recognizes *.feature files and allows to comment out line out of the box. The same possible to do with Notepad++ or even VS.

Solution 3:

In Eclipse, for commenting single/multiple lines of Gherkin feature file content, we can also do the following.

Add new file association
Windows > Preferences > General > Editors> File Associations > File types: > Add...
and add a new file type as *.feature

Associate an editor for new file type
Associated Editors > > Add...
add Properties File Editor (Default).

Now reopen the file if it's open and it will open in Properties File Editor instead of Text editor.

Doing this allows me select any number of lines and comment-out using the common commenting shortcut Ctrl+Shift+C