84

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?

dbruning
  • 4,587
  • 5
  • 31
  • 33
  • 1
    I haven't tried it, but if Artem's solution is correct then the accepted solution should be changed to that one. – KobeJohn Jun 05 '12 at 13:46
  • Lots of editors can multi-line prefix with single lines using a keyboard shortcut. In Atom it's `CMD + /` ;) – cregox Sep 15 '15 at 01:43
  • This is not supported by Gherkin. The reason for this is because you are already able to introduce description blocks to elaborate as needed for the keywords: Feature, Scenario Outline, Scenario and Examples. A multiline comment for these would be an anti pattern. For the remainder keywords, you have the single line comment as need be. Introducing a multiline comment for them should be rather rare and perhaps be indicative of a lack of clarity. – Kevin Johnson Dec 29 '19 at 17:28

13 Answers13

61

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.

Tz_
  • 2,919
  • 16
  • 13
  • 6
    You can do the same thing in RubyMine by selecting lines and pressing Ctrl+/, and uncomment them the same way. Fabulously useful. :) – Doug Noel Apr 18 '12 at 21:11
  • I use the alt trick all the time. Very handy for sql stamements also when i need to add ' and ', for where-in clauses. +1 – Caleb Postlethwait Aug 01 '14 at 21:48
24

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.

Artem Oboturov
  • 4,246
  • 2
  • 25
  • 46
  • Coming from Python, it is really weird to see triple quotes used that way. Nice solution if it works though! – KobeJohn Jun 05 '12 at 13:46
  • 5
    There is no need to use triple quotes in these places, as any text there will be handled as comments (i.e. ignored) by Cucumber anyway. The triple quotes are used for multiline texts given/when/then inside steps. – csgero Aug 01 '13 at 07:12
7

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

Dušan Maďar
  • 7,399
  • 4
  • 30
  • 51
Afshar
  • 222
  • 3
  • 9
5

For commenting :

Single Line --> #

Multiple Line --> """

CChittem
  • 59
  • 1
  • 1
5

Single line comment : #

Mutli line comment : Starts with """ Ends with """

p91java
  • 49
  • 1
  • 2
3

Use CTRL + /

It works great. Multiple line comment

Anand Dave
  • 31
  • 1
2

Use Command key + '?' key to comment multiple lines for cucumber scripts in MAC.

venkat
  • 21
  • 2
2

There's no block commenting in Gherkin, however you can comment multiple lines at once by selecting that block and hitting ctrl + /

1

You could achieve it by selecting all the lines that you want to comment and then pressing "Ctrl + plus/equals key + /" keys in eclipse.

1

I don't think it's supported, actually. I have been doing Cucumber related work for about 2 years now and I never seen it.

You'll have to do lot of #-lines ;).

I would start reading the great wiki on github (https://github.com/cucumber/cucumber/wiki/Gherkin)

Richard Neish
  • 7,053
  • 4
  • 32
  • 65
Marcus Hammarberg
  • 4,602
  • 1
  • 28
  • 36
0

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

0

Well, I have so far used # to comment the test steps. If you use this, you should individually comment out each and every line, scenarios and examples which ever applicable. Though this is not recommended, still, I dont see anything similar supported in gherkin yet.

Emjey
  • 1,802
  • 1
  • 12
  • 30
0

Select all the lines you want to comment and press cmd+shift+c.

See..
  • 23
  • 4