Forum Discussion

DanielFrampton's avatar
DanielFrampton
New Contributor
3 years ago
Solved

All comments in feature file printed to console

Hello Cucumber community!

 

I'm upgrading my organization's Ruby environment used for automated testing, and making a big leap forward in our Cucumber gem version from 1.3.20 (!!!) to 6.0.

 

In the process of doing so, with all other variables remaining the same, I noticed that between Cucumber 3.2.0 and 4.0.0 the comments in our feature files went from only being included in the console output if they immediately preceded one of the scenarios being run to always being printed out regardless of proximity to those scenarios.

 

Before (Cucumber 1.3.20 to 3.2.0):

 

> bundle exec cucumber features/my_feature.feature:6
@tag_1 @tag_2
Feature: A feature description

  # A comment immediately preceding the scenario on line 6
  @tag_3 @tag_4
  Scenario: The name of the scenario on line 6.   # features/my_feature.feature:6
Some intentional console output      
    Given I do a thing          # features/step_definitions/my_feature_steps.rb:3
    When I do a thing           # features/step_definitions/my_feature_steps.rb:157
    Then I should see a thing   # features/step_definitions/my_featue_steps.rb:20

1 scenario (1 passed)
3 steps (3 passed)

 

 

After (Cucumber 4.0 to 6.1.0):

 

> bundle exec cucumber features/my_feature.feature:6
@tag_1 @tag_2
Feature: A feature description

  # The first comment in the file
  # A comment preceding the scenario before this
  # A comment immediately preceding the scenario on line 6
  @tag_3 @tag_4
  Scenario: The name of the scenario on line 6.   # features/my_feature.feature:6
Some intentional console output      
    Given I do a thing          # features/step_definitions/my_feature_steps.rb:3
    When I do a thing           # features/step_definitions/my_feature_steps.rb:157
    Then I should see a thing   # features/step_definitions/my_featue_steps.rb:20

# A comment following this scenario but not immediately preceding a scenario
# Another comment preceding a subsequent scenario
# A comment between steps in a subsequent scenario
# Etc., all the comments following line 6 to the end of the feature file

1 scenario (1 passed)
3 steps (3 passed)

 

 

The only references to comments in feature files in the Cucumber docs, primarily in the section Gherkin Reference, simply say that the pound sign preceded by any number of spaces is a supported syntax for comments, suggesting that they are still supported. I cannot, however, find any open or closed issues regarding this, nor any references to changes in the behavior of console output of comments in the change-log or major version upgrade announcements.

 

I did find one comment on an issue here which stated that "I think new versions of cucumber does not process comment at all by design. If you want to add documentation to you features and scenarios, description should be helpful." But that was in reference to report generation, not console output.

 

Is this normal/expected behavior? Is there a way to configure Cucumber to not print those comments not immediately preceding scenarios being run? Is it a bug that somehow has persisted since 4.0 that I should make an issue for?

 

Thanks in advance for any help!

  • The change in cucumber@4.0 has been introduced in the following commit: https://github.com/cucumber/cucumber-ruby/commit/22c4f13dd0f8b3b0eac593d881b814328a3e49e2

     

    It has not been documented, but it looks like it has been intentional, so it seems to be expected behavior. And no option to disable it.

     

    In your case, if those comments after the last scenario are an issue, you may consider monkey patching the "Pretty" formatter. For example, if your support code is in `features/support`, you could add a `formatter` folder with `pretty.rb` with the following content:

     

     

     

    # features/support/formatter/pretty.rb
    # frozen_string_literal: true
    
    require 'cucumber/formatter/pretty'
    
    module Cucumber
      module Formatter
        class Pretty
          def on_test_run_finished(_event)
            print_summary
          end
        end
      end
    end

     

     

     

2 Replies

  • The change in cucumber@4.0 has been introduced in the following commit: https://github.com/cucumber/cucumber-ruby/commit/22c4f13dd0f8b3b0eac593d881b814328a3e49e2

     

    It has not been documented, but it looks like it has been intentional, so it seems to be expected behavior. And no option to disable it.

     

    In your case, if those comments after the last scenario are an issue, you may consider monkey patching the "Pretty" formatter. For example, if your support code is in `features/support`, you could add a `formatter` folder with `pretty.rb` with the following content:

     

     

     

    # features/support/formatter/pretty.rb
    # frozen_string_literal: true
    
    require 'cucumber/formatter/pretty'
    
    module Cucumber
      module Formatter
        class Pretty
          def on_test_run_finished(_event)
            print_summary
          end
        end
      end
    end