rubycucumberhookscenarios

How to get the feature name in Cucumber hooks.rb


I need a variable that contains the name of the feature: since it's a feature, do it; since it is another, do that.

I tried these ways, but no success:

Examples:

1)

After do |scenario|
    puts scenario.feature.name
end

2)

After do |scenario|
    puts scenario.scenario_outline.feature.name
end

p.s.: Translated by Google


Solution

  • Finally I found it!

    Before do |s|
      feature(s.location) # => #<struct Cucumber::Core::Test::Location::Precise
    end
    
    def feature(location)
            string = File.read(location.file)
            document = ::Gherkin::Parser.new.parse(string)
            document[:feature]
    end
    

    The solution is in the clink below:

    https://github.com/cucumber/cucumber-ruby/issues/1432