Code Monkey home page Code Monkey logo

gherkin-ruby's Introduction

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

gherkin-ruby's People

Contributors

josepjaume avatar divins avatar jonathantron avatar luislavena avatar ntalbott avatar

Stargazers

iain avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.