Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do block comments in Gherkin?

In gherkin syntax (used by Cucumber and SpecFlow, I can comment out a line by prefixing it with '#'

Is there any way to block-comment multiple lines?

like image 460
dbruning Avatar asked Aug 18 '11 20:08

dbruning


People also ask

How do I block a comment in a feature file?

Feature file only supports comments with a # sign. We put # at the beginning of our Comment. You want to do a single line or multiple line comments; you need to put # before all lines. The parser will ignore every line which starts with #.

How do you comment on the Gherkin code?

Most lines in a Gherkin document start with one of the keywords. Comments are only permitted at the start of a new line, anywhere in the feature file. They begin with zero or more spaces, followed by a hash sign ( # ) and some text. Block comments are currently not supported by Gherkin.

How do you comment multiple lines in BDD?

Comments can be placed any where in the bdd file. Comment can be single line or multiline. Single line comment starts with # or ! . Multi-line comments start with """ and end with """ .


2 Answers

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.

like image 148
Tz_ Avatar answered Sep 24 '22 20:09

Tz_


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.

like image 26
Artem Oboturov Avatar answered Sep 25 '22 20:09

Artem Oboturov