Skip to content

Instantly share code, notes, and snippets.

@commuterjoy
Created October 23, 2011 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commuterjoy/1307626 to your computer and use it in GitHub Desktop.
Save commuterjoy/1307626 to your computer and use it in GitHub Desktop.
Converting Gherkin to JSON in Ruby
# This took me an hour or so to figure out as the documentation is a bit
# sparse, but the gherkin gem ships with a json formatter
require 'rubygems'
require 'gherkin'
require 'gherkin/formatter/json_formatter'
require 'gherkin/parser/parser'
require 'json'
#---
feature = IO.read('foo.feature')
io = StringIO.new
formatter = Gherkin::Formatter::JSONFormatter.new(io)
parser = Gherkin::Parser::Parser.new(formatter, false, 'root')
parser.parse(feature, __FILE__, 0)
puts JSON.parse(io.string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment