Giter Club home page Giter Club 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.3, 2.0.0, head, Rubinius 2.0.0-rc1 and Rubinius head.

WARNING: Will be deprecated after Gherkin 3.0

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.

FAQ

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)

Why don't you support tables?

  • Because we believe it's a BDD anti-pattern. Tables show the need for more unit tests.

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

FAQ

License

MIT (Expat) License. Copyright 2011-2013 Codegram Technologies

gherkin-ruby's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gherkin-ruby's Issues

Support PyStrings

Multi-line strings work great in the native gherkin but gherkin-ruby doesn't seem to be a big fan.

/Users/paul/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/racc/parser.rb:351:in `on_error':  (Racc::ParseError)
parse error on value "\"\"\"" (TEXT)
    from (eval):3:in `_racc_do_parse_c'
    from (eval):3:in `do_parse'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p194/gems/gherkin-ruby-0.2.1/lib/gherkin/parser/lexer.rb:31:in `scan_str'
    from gherkin.y:107:in `parse'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p194/gems/gherkin-ruby-0.2.1/lib/gherkin.rb:8:in `parse'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p194/gems/spinach-0.5.2/lib/spinach/parser.rb:39:in `parse'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p194/gems/spinach-0.5.2/lib/spinach/runner.rb:66:in `block in run'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p194/gems/spinach-0.5.2/lib/spinach/runner.rb:63:in `each'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p194/gems/spinach-0.5.2/lib/spinach/runner.rb:63:in `run'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p194/gems/spinach-0.5.2/lib/spinach/cli.rb:23:in `run'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p194/gems/spinach-0.5.2/bin/spinach:16:in `<top (required)>'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p194/bin/spinach:19:in `load'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p194/bin/spinach:19:in `<main>'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
    from /Users/paul/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'```

Chokes on blank lines that have whitespace

The following throws a parse error:

Feature: feature

Scenario: a
  Given something

Scenario: b
  Given something

Due to the two spaces on the blank line between Scenarios.

'And' in feature description make exception

The text

Feature: Star topic
  As a user
  And I want to star/unstar owned + joined + public topics

Make unreadable exception

/home/msa/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/racc/parser.rb:351:in `on_error':  (Racc::ParseError)
parse error on value "And" (AND)
    from (eval):3:in `_racc_do_parse_c'
    from (eval):3:in `do_parse'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/gherkin-ruby-0.2.1/lib/gherkin/parser/lexer.rb:31:in `scan_str'
    from gherkin.y:107:in `parse'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/gherkin-ruby-0.2.1/lib/gherkin.rb:8:in `parse'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/spinach-0.8.0/lib/spinach/parser.rb:39:in `parse'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/spinach-0.8.0/lib/spinach/runner.rb:75:in `block in run'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/spinach-0.8.0/lib/spinach/runner.rb:72:in `each'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/spinach-0.8.0/lib/spinach/runner.rb:72:in `run'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/spinach-0.8.0/lib/spinach/cli.rb:27:in `run'

Chokes on comments

As far as I can tell, the parser will choke whenever it encounters a comment. While there is a comment declaration, comments are never added as an acceptable part of Features/Scenarios.

Support tables

I'm a fan of tables, and wanted to check to see if this is a feature you're planning to support. I was going to see about implementing it, but a friend pointed me to codegram/spinach#62, so I figured I should ask to see if it's left out intentionally.

Just to be clear, here's an example. Let's say I'm writing a search feature for a time tracker:

Given I have the time sheet entries:
  | 5 minutes  | hiding kids    |
  | 10 minutes | hiding wife    |
  | 10 minutes | hiding husband |
  | 20 minutes | finding rapist |
When I search for "hiding"
Then I should see the search results:
  | hiding kids    | 5 minutes  |
  | hiding wife    | 10 minutes |
  | hiding husband | 10 minutes |
And I should not see "finding rapist"

Is there a reason you wouldn't want to support this syntax?

Ruby ships with racc, why depend on it as gem?

Hello,

I recently noticed that for installing gherkin-ruby, racc gem dependency needs to be built, which defeats the purpose of having a pure ruby version.

The thing is that racc is already part of Ruby:

$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin10.8.0]

$ gem list racc

*** LOCAL GEMS ***

$ ruby --disable-gems -rracc/parser.rb -e "puts 'works'"
works

Perhaps the racc dependency can be move to development one instead?

Thank you! ❤️

Support Tables or Document Not Supporting Tables

Hi. I spent a couple of hours considering switching to Spinach until I learned that you're not supporting the Gherkin table syntax. I find tables immensely valuable for specifying the nitty-gritty details of a data-intensive test case that would waste a lot of space (and have horrible readability) in narrative format.

Please either consider adding tables OR state clearly in your documentation that they are purposely Not Supported.

Thank you. (This project looked promising)

Rename 'gherkin.rb' to 'gherkin-ruby.rb'

The gherkin-ruby gem is colliding with the gherkin gem because they both use gherkin.rb as their primary file to be required.

(I'm trying to migrate from Cucumber to Spinach piecemeal and this is keeping me from doing that.)

I'm happy to make this change (here and in Spinach) if someone gives the thumbs-up.

'Button' in scenario make exception

The scenario

  Scenario: Star topic
    Given Button

Make a unreadable exception

/home/msa/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/racc/parser.rb:351:in `on_error':  (Racc::ParseError)
parse error on value "But" (BUT)
    from (eval):3:in `_racc_do_parse_c'
    from (eval):3:in `do_parse'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/gherkin-ruby-0.2.1/lib/gherkin/parser/lexer.rb:31:in `scan_str'
    from gherkin.y:107:in `parse'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/gherkin-ruby-0.2.1/lib/gherkin.rb:8:in `parse'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/spinach-0.8.0/lib/spinach/parser.rb:39:in `parse'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/spinach-0.8.0/lib/spinach/runner.rb:75:in `block in run'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/spinach-0.8.0/lib/spinach/runner.rb:72:in `each'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/spinach-0.8.0/lib/spinach/runner.rb:72:in `run'
    from /home/msa/.rvm/gems/ruby-1.9.3-p374/gems/spinach-0.8.0/lib/spinach/cli.rb:27:in `run'

Prerequisite knowledge for adding support for Docstrings

I noticed this library doesn't yet support docstrings. Now, if I were to go and try to implement this feature, what would I need to know to do that?

I noticed there's a .y file and a .rex file. It looks like I would have to understand yacc. What about the .rex file? Does anyone have a link they can post where I can learn more about the syntax in that file? Is this the correct repo for learning more about rex: https://github.com/tenderlove/racc?

I'm going to refer to issue #20 since @kalupa also wanted support for this feature.

Support Tables

I would strongly encourage the separation of functionality in the repo from the philosophical beliefs about writing tests in Gherkin. Primarily because for users who already have suites of Gherkin files, this repo becomes useless or another piece of work to extend to accommodate the gap. Basically, I think that omitting that major feature of Gherkin is more limiting to this project than the act of supporting an anti-pattern.

I would also like to suggest that tables are not always an anti-pattern. One of the main intentions of Cucumber is to provide a more human readable format. So, if the table is testing things like corner cases for inputs to a function, than the test is already going beyond what a non-technical user would comprehend.

However, tables are a great way to list what fields should be in a dropdown box or in a nav bar. They're also a great way to say what fields on a view are visible based on the user's permission. I do not really see how every table equates to the need for better unit testing.

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.