Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
gherkin-ruby is a Gherkin parser in pure Ruby using Parslet.
Ruby

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.rvmrc
.travis.yml
Gemfile
Rakefile
Readme.md
gherkin-ruby.gemspec

Readme.md

gherkin-ruby Build Status Dependency Status

Gherkin-ruby is a pure Ruby implementation of a Gherkin parser.

Tested with MRI 1.9.2, 1.9.3, ruby-head and Rubinius head.

Why this one over the official, fast, Ragel-based Gherkin parser?

  • Less than 200 LOC.
  • No Java/.NET crap.
  • Fast enough for our purposes (using it for the Spinach project)

Install

$ gem install gherkin-ruby

Or in your Gemfile:

# Gemfile

gem 'gherkin-ruby'

Usage

You can easily implement your own visitors to traverse the Abstract Syntax Tree. The following example just prints the step names to standard output:

class MyVisitor
  def visit(ast)
    ast.accept(self)
  end

  def visit_Feature(feature)
    # Do something nasty with the feature
    # Set whatever state you want:
    #   @current_feature = feature
    # etc etc
    # And keep visiting its children:

    feature.each { |scenario| scenario.accept(self) }
  end

  def visit_Scenario(scenario)
    # Do something nasty with the scenario
    # Set whatever state you want:
    #   @current_scenario = scenario
    # etc etc
    # And keep visiting its children:

    scenario.each { |step| step.accept(self) }
  end

  def visit_Background(background)
    # Do something nasty with the background
    # And keep visiting its children:

    background.each { |step| step.accept(self) }
  end

  def visit_Tag(tag)
    # Do something nasty with the tag
  end

  def visit_Step(step)
    # Finally, print the step name.
    puts "STEP: #{step.name}"
  end
end

ast = Gherkin.parse(File.read('some.feature'))
visitor = MyVisitor.new
visitor.visit(ast)

Todo

  • Some optimization
Something went wrong with that request. Please try again.