Gherkin-ruby is a pure Ruby implementation of a Gherkin parser.
Tested with MRI 1.9.3, 2.0.0, head, Rubinius 2.0.0-rc1 and Rubinius head.
A new rewrite of the Gherkin parser used by Cucumber is planned (for version 3.0) gherkin-ruby will not add any more features until then, and will eventually be deprecated in favor of Gherkin 3.0.
- Less than 200 LOC.
- No Java/.NET crap.
- Fast enough for our purposes (using it for the Spinach project)
- Because we believe it's a BDD anti-pattern. Tables show the need for more unit tests.
$ gem install gherkin-ruby
Or in your Gemfile:
# Gemfilegem'gherkin-ruby'You can easily implement your own visitors to traverse the Abstract Syntax Tree. The following example just prints the step names to standard output:
classMyVisitordefvisit(ast)ast.accept(self)enddefvisit_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)}enddefvisit_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)}enddefvisit_Background(background)# Do something nasty with the background# And keep visiting its children:background.each{ |step| step.accept(self)}enddefvisit_Tag(tag)# Do something nasty with the tagenddefvisit_Step(step)# Finally, print the step name.puts"STEP: #{step.name}"endendast=Gherkin.parse(File.read('some.feature'))visitor=MyVisitor.newvisitor.visit(ast)- Some optimization
MIT (Expat) License. Copyright 2011-2013 Codegram Technologies

