Created
May 16, 2016 14:36
-
-
Save eterps/894d11d37bda183954afced74c39e54b to your computer and use it in GitHub Desktop.
Converts a Gherkin file to JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'json' | |
require 'gherkin/parser' | |
filename = ARGV[0] | |
src = open(filename).read | |
parser = Gherkin::Parser.new | |
gherkin_document = parser.parse(src) | |
scenarios = gherkin_document[:feature][:children].select{|n| n[:type] == :Scenario} | |
line = gherkin_document[:feature][:location][:line] | |
out = { | |
name: gherkin_document[:feature][:name], | |
path: "#{filename}:#{line}", | |
scenarios: scenarios.map do |scenario| | |
line = scenario[:location][:line] | |
{ | |
name: scenario[:name], | |
path: "#{filename}:#{line}", | |
steps: scenario[:steps].map{|n| n[:keyword] + n[:text]} | |
} | |
end | |
} | |
puts JSON.pretty_unparse(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment